Java Code Examples for com.google.android.gms.maps.model.Polygon

The following examples show how to use com.google.android.gms.maps.model.Polygon. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: android-maps-utils   Author: googlemaps   File: Renderer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Given a Marker, Polyline, Polygon or an array of these and removes it from the map
 *
 * @param mapObject map object or array of map objects to remove from the map
 */
protected void removeFromMap(Object mapObject) {
    if (mapObject instanceof Marker) {
        mMarkers.remove((Marker) mapObject);
    } else if (mapObject instanceof Polyline) {
        mPolylines.remove((Polyline) mapObject);
    } else if (mapObject instanceof Polygon) {
        mPolygons.remove((Polygon) mapObject);
    } else if (mapObject instanceof GroundOverlay) {
        mGroundOverlays.remove((GroundOverlay) mapObject);
    } else if (mapObject instanceof ArrayList) {
        for (Object mapObjectElement : (ArrayList) mapObject) {
            removeFromMap(mapObjectElement);
        }
    }
}
 
Example #2
Source Project: mage-android   Author: ngageoint   File: StaticGeometryCollection.java    License: Apache License 2.0 5 votes vote down vote up
public Polygon addPolygon(String layerId, Polygon polygon, String popupHTML) {
	if (featurePolygons.get(layerId) == null) {
		featurePolygons.put(layerId, new ArrayList<Polygon>());
	}

	featurePolygons.get(layerId).add(polygon);
	featurePolygonDescriptions.put(polygon, popupHTML);
	return polygon;
}
 
Example #3
Source Project: mage-android   Author: ngageoint   File: StaticGeometryCollection.java    License: Apache License 2.0 5 votes vote down vote up
public Collection<Polygon> getPolygons() {
	Collection<Polygon> polygons = new ArrayList<Polygon>();
	for (Map.Entry<String, Collection<Polygon>> entry : featurePolygons.entrySet()) {
		for (Polygon p : entry.getValue()) {
			polygons.add(p);
		}
	}
	return polygons;
}
 
Example #4
Source Project: RxGoogleMaps   Author: minageorge5080   File: PolygonClickFuncTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEmmitPolygon() throws Exception {
    TestSubscriber<Polygon> testSubscriber = new TestSubscriber<>();
    new PolygonClickFunc().call(googleMap)
            .subscribe(testSubscriber);
    verify(googleMap).setOnPolygonClickListener(argumentCaptor.capture());
    argumentCaptor.getValue().onPolygonClick(null);
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    argumentCaptor.getValue().onPolygonClick(null);
    testSubscriber.assertValueCount(2);
}
 
Example #5
Source Project: android-samples   Author: googlemaps   File: PolyActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Listens for clicks on a polygon.
 * @param polygon The polygon object that the user has clicked.
 */
@Override
public void onPolygonClick(Polygon polygon) {
    // Flip the values of the red, green, and blue components of the polygon's color.
    int color = polygon.getStrokeColor() ^ 0x00ffffff;
    polygon.setStrokeColor(color);
    color = polygon.getFillColor() ^ 0x00ffffff;
    polygon.setFillColor(color);

    Toast.makeText(this, "Area type " + polygon.getTag().toString(), Toast.LENGTH_SHORT).show();
}
 
Example #6
Source Project: android-samples   Author: googlemaps   File: PolyActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Styles the polygon, based on type.
 * @param polygon The polygon object that needs styling.
 */
private void stylePolygon(Polygon polygon) {
    String type = "";
    // Get the data object stored with the polygon.
    if (polygon.getTag() != null) {
        type = polygon.getTag().toString();
    }

    List<PatternItem> pattern = null;
    int strokeColor = COLOR_BLACK_ARGB;
    int fillColor = COLOR_WHITE_ARGB;

    switch (type) {
        // If no type is given, allow the API to use the default.
        case "alpha":
            // Apply a stroke pattern to render a dashed line, and define colors.
            pattern = PATTERN_POLYGON_ALPHA;
            strokeColor = COLOR_GREEN_ARGB;
            fillColor = COLOR_PURPLE_ARGB;
            break;
        case "beta":
            // Apply a stroke pattern to render a line of dots and dashes, and define colors.
            pattern = PATTERN_POLYGON_BETA;
            strokeColor = COLOR_ORANGE_ARGB;
            fillColor = COLOR_BLUE_ARGB;
            break;
    }

    polygon.setStrokePattern(pattern);
    polygon.setStrokeWidth(POLYGON_STROKE_WIDTH_PX);
    polygon.setStrokeColor(strokeColor);
    polygon.setFillColor(fillColor);
}
 
Example #7
Source Project: android-maps-utils   Author: googlemaps   File: Renderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Removes all given Features from the map and clears all stored features.
 *
 * @param features features to remove
 */
private void removeFeatures(Collection features) {
    // Remove map object from the map
    for (Object mapObject : features) {
        if (mapObject instanceof Collection) {
            removeFeatures((Collection) mapObject);
        } else if (mapObject instanceof Marker) {
            mMarkers.remove((Marker) mapObject);
        } else if (mapObject instanceof Polyline) {
            mPolylines.remove((Polyline) mapObject);
        } else if (mapObject instanceof Polygon) {
            mPolygons.remove((Polygon) mapObject);
        }
    }
}
 
Example #8
Source Project: android-maps-utils   Author: googlemaps   File: Renderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a DataPolygon to the map as a Polygon
 *
 * @param polygonOptions
 * @param polygon        contains coordinates for the Polygon
 * @return Polygon object created from given DataPolygon
 */
private Polygon addPolygonToMap(PolygonOptions polygonOptions, DataPolygon polygon) {
    // First array of coordinates are the outline
    polygonOptions.addAll(polygon.getOuterBoundaryCoordinates());
    // Following arrays are holes
    List<List<LatLng>> innerBoundaries = polygon.getInnerBoundaryCoordinates();
    for (List<LatLng> innerBoundary : innerBoundaries) {
        polygonOptions.addHole(innerBoundary);
    }
    Polygon addedPolygon = mPolygons.addPolygon(polygonOptions);
    addedPolygon.setClickable(polygonOptions.isClickable());
    return addedPolygon;
}
 
Example #9
Source Project: android-maps-utils   Author: googlemaps   File: Renderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds all GeoJsonPolygon in the GeoJsonMultiPolygon to the map as multiple Polygons
 *
 * @param polygonStyle contains relevant styling properties for the Polygons
 * @param multiPolygon contains an array of GeoJsonPolygons
 * @return array of Polygons that have been added to the map
 */
private ArrayList<Polygon> addMultiPolygonToMap(GeoJsonPolygonStyle polygonStyle,
                                                GeoJsonMultiPolygon multiPolygon) {
    ArrayList<Polygon> polygons = new ArrayList<>();
    for (GeoJsonPolygon geoJsonPolygon : multiPolygon.getPolygons()) {
        polygons.add(addPolygonToMap(polygonStyle.toPolygonOptions(), geoJsonPolygon));
    }
    return polygons;
}
 
Example #10
Source Project: android-maps-utils   Author: googlemaps   File: PolygonManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onPolygonClick(Polygon polygon) {
    Collection collection = mAllObjects.get(polygon);
    if (collection != null && collection.mPolygonClickListener != null) {
        collection.mPolygonClickListener.onPolygonClick(polygon);
    }
}
 
Example #11
Source Project: Complete-Google-Map-API-Tutorial   Author: mohammadima3oud   File: ShapeActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onPolygonClick(Polygon polygon)
{
	onClick((CustomTag) polygon.getTag());
}
 
Example #12
Source Project: geopackage-android-map   Author: ngageoint   File: GoogleMapShape.java    License: MIT License 4 votes vote down vote up
/**
 * Removes all objects added to the map
 */
public void remove() {

    switch (shapeType) {

        case MARKER:
            ((Marker) shape).remove();
            break;
        case POLYGON:
            ((Polygon) shape).remove();
            break;
        case POLYLINE:
            ((Polyline) shape).remove();
            break;
        case MULTI_MARKER:
            ((MultiMarker) shape).remove();
            break;
        case MULTI_POLYLINE:
            ((MultiPolyline) shape).remove();
            break;
        case MULTI_POLYGON:
            ((MultiPolygon) shape).remove();
            break;
        case POLYLINE_MARKERS:
            ((PolylineMarkers) shape).remove();
            break;
        case POLYGON_MARKERS:
            ((PolygonMarkers) shape).remove();
            break;
        case MULTI_POLYLINE_MARKERS:
            ((MultiPolylineMarkers) shape).remove();
            break;
        case MULTI_POLYGON_MARKERS:
            ((MultiPolygonMarkers) shape).remove();
            break;
        case COLLECTION:
            @SuppressWarnings("unchecked")
            List<GoogleMapShape> shapeList = (List<GoogleMapShape>) shape;
            for (GoogleMapShape shapeListItem : shapeList) {
                shapeListItem.remove();
            }
            break;
        default:
    }

}
 
Example #13
Source Project: geopackage-android-map   Author: ngageoint   File: GoogleMapShape.java    License: MIT License 4 votes vote down vote up
/**
 * Updates visibility of all objects
 *
 * @param visible visible flag
 * @since 1.3.2
 */
public void setVisible(boolean visible) {

    switch (shapeType) {

        case MARKER_OPTIONS:
            ((MarkerOptions) shape).visible(visible);
            break;
        case POLYLINE_OPTIONS:
            ((PolylineOptions) shape).visible(visible);
            break;
        case POLYGON_OPTIONS:
            ((PolygonOptions) shape).visible(visible);
            break;
        case MULTI_POLYLINE_OPTIONS:
            ((MultiPolylineOptions) shape).visible(visible);
            break;
        case MULTI_POLYGON_OPTIONS:
            ((MultiPolygonOptions) shape).visible(visible);
            break;
        case MARKER:
            ((Marker) shape).setVisible(visible);
            break;
        case POLYGON:
            ((Polygon) shape).setVisible(visible);
            break;
        case POLYLINE:
            ((Polyline) shape).setVisible(visible);
            break;
        case MULTI_MARKER:
            ((MultiMarker) shape).setVisible(visible);
            break;
        case MULTI_POLYLINE:
            ((MultiPolyline) shape).setVisible(visible);
            break;
        case MULTI_POLYGON:
            ((MultiPolygon) shape).setVisible(visible);
            break;
        case POLYLINE_MARKERS:
            ((PolylineMarkers) shape).setVisible(visible);
            break;
        case POLYGON_MARKERS:
            ((PolygonMarkers) shape).setVisible(visible);
            break;
        case MULTI_POLYLINE_MARKERS:
            ((MultiPolylineMarkers) shape).setVisible(visible);
            break;
        case MULTI_POLYGON_MARKERS:
            ((MultiPolygonMarkers) shape).setVisible(visible);
            break;
        case COLLECTION:
            @SuppressWarnings("unchecked")
            List<GoogleMapShape> shapeList = (List<GoogleMapShape>) shape;
            for (GoogleMapShape shapeListItem : shapeList) {
                shapeListItem.setVisible(visible);
            }
            break;
        default:
    }

}
 
Example #14
Source Project: geopackage-android-map   Author: ngageoint   File: GoogleMapShape.java    License: MIT License 4 votes vote down vote up
/**
 * Set the z index
 *
 * @param zIndex z index
 * @since 2.0.1
 */
public void setZIndex(float zIndex) {

    switch (shapeType) {

        case MARKER_OPTIONS:
            ((MarkerOptions) shape).zIndex(zIndex);
            break;
        case POLYLINE_OPTIONS:
            ((PolylineOptions) shape).zIndex(zIndex);
            break;
        case POLYGON_OPTIONS:
            ((PolygonOptions) shape).zIndex(zIndex);
            break;
        case MULTI_POLYLINE_OPTIONS:
            ((MultiPolylineOptions) shape).zIndex(zIndex);
            break;
        case MULTI_POLYGON_OPTIONS:
            ((MultiPolygonOptions) shape).zIndex(zIndex);
            break;
        case MARKER:
            ((Marker) shape).setZIndex(zIndex);
            break;
        case POLYGON:
            ((Polygon) shape).setZIndex(zIndex);
            break;
        case POLYLINE:
            ((Polyline) shape).setZIndex(zIndex);
            break;
        case MULTI_MARKER:
            ((MultiMarker) shape).setZIndex(zIndex);
            break;
        case MULTI_POLYLINE:
            ((MultiPolyline) shape).setZIndex(zIndex);
            break;
        case MULTI_POLYGON:
            ((MultiPolygon) shape).setZIndex(zIndex);
            break;
        case POLYLINE_MARKERS:
            ((PolylineMarkers) shape).setZIndex(zIndex);
            break;
        case POLYGON_MARKERS:
            ((PolygonMarkers) shape).setZIndex(zIndex);
            break;
        case MULTI_POLYLINE_MARKERS:
            ((MultiPolylineMarkers) shape).setZIndex(zIndex);
            break;
        case MULTI_POLYGON_MARKERS:
            ((MultiPolygonMarkers) shape).setZIndex(zIndex);
            break;
        case COLLECTION:
            @SuppressWarnings("unchecked")
            List<GoogleMapShape> shapeList = (List<GoogleMapShape>) shape;
            for (GoogleMapShape shapeListItem : shapeList) {
                shapeListItem.setZIndex(zIndex);
            }
            break;
        default:
    }

}
 
Example #15
Source Project: geopackage-android-map   Author: ngageoint   File: GoogleMapShape.java    License: MIT License 4 votes vote down vote up
/**
 * Expand the bounding box to include the shape
 *
 * @param boundingBox bounding box
 */
public void expandBoundingBox(BoundingBox boundingBox) {

    switch (shapeType) {

        case LAT_LNG:
            expandBoundingBox(boundingBox, (LatLng) shape);
            break;
        case MARKER_OPTIONS:
            expandBoundingBox(boundingBox,
                    ((MarkerOptions) shape).getPosition());
            break;
        case POLYLINE_OPTIONS:
            expandBoundingBox(boundingBox,
                    ((PolylineOptions) shape).getPoints());
            break;
        case POLYGON_OPTIONS:
            expandBoundingBox(boundingBox, ((PolygonOptions) shape).getPoints());
            break;
        case MULTI_LAT_LNG:
            expandBoundingBox(boundingBox, ((MultiLatLng) shape).getLatLngs());
            break;
        case MULTI_POLYLINE_OPTIONS:
            MultiPolylineOptions multiPolylineOptions = (MultiPolylineOptions) shape;
            for (PolylineOptions polylineOptions : multiPolylineOptions
                    .getPolylineOptions()) {
                expandBoundingBox(boundingBox, polylineOptions.getPoints());
            }
            break;
        case MULTI_POLYGON_OPTIONS:
            MultiPolygonOptions multiPolygonOptions = (MultiPolygonOptions) shape;
            for (PolygonOptions polygonOptions : multiPolygonOptions
                    .getPolygonOptions()) {
                expandBoundingBox(boundingBox, polygonOptions.getPoints());
            }
            break;
        case MARKER:
            expandBoundingBox(boundingBox, ((Marker) shape).getPosition());
            break;
        case POLYLINE:
            expandBoundingBox(boundingBox, ((Polyline) shape).getPoints());
            break;
        case POLYGON:
            expandBoundingBox(boundingBox, ((Polygon) shape).getPoints());
            break;
        case MULTI_MARKER:
            expandBoundingBoxMarkers(boundingBox,
                    ((MultiMarker) shape).getMarkers());
            break;
        case MULTI_POLYLINE:
            MultiPolyline multiPolyline = (MultiPolyline) shape;
            for (Polyline polyline : multiPolyline.getPolylines()) {
                expandBoundingBox(boundingBox, polyline.getPoints());
            }
            break;
        case MULTI_POLYGON:
            MultiPolygon multiPolygon = (MultiPolygon) shape;
            for (Polygon polygon : multiPolygon.getPolygons()) {
                expandBoundingBox(boundingBox, polygon.getPoints());
            }
            break;
        case POLYLINE_MARKERS:
            expandBoundingBoxMarkers(boundingBox,
                    ((PolylineMarkers) shape).getMarkers());
            break;
        case POLYGON_MARKERS:
            expandBoundingBoxMarkers(boundingBox,
                    ((PolygonMarkers) shape).getMarkers());
            break;
        case MULTI_POLYLINE_MARKERS:
            MultiPolylineMarkers multiPolylineMarkers = (MultiPolylineMarkers) shape;
            for (PolylineMarkers polylineMarkers : multiPolylineMarkers
                    .getPolylineMarkers()) {
                expandBoundingBoxMarkers(boundingBox,
                        polylineMarkers.getMarkers());
            }
            break;
        case MULTI_POLYGON_MARKERS:
            MultiPolygonMarkers multiPolygonMarkers = (MultiPolygonMarkers) shape;
            for (PolygonMarkers polygonMarkers : multiPolygonMarkers
                    .getPolygonMarkers()) {
                expandBoundingBoxMarkers(boundingBox,
                        polygonMarkers.getMarkers());
            }
            break;
        case COLLECTION:
            @SuppressWarnings("unchecked")
            List<GoogleMapShape> shapeList = (List<GoogleMapShape>) shape;
            for (GoogleMapShape shapeListItem : shapeList) {
                shapeListItem.expandBoundingBox(boundingBox);
            }
            break;
    }

}
 
Example #16
Source Project: geopackage-android-map   Author: ngageoint   File: MultiPolygon.java    License: MIT License 4 votes vote down vote up
/**
 * Remove from the map
 */
public void remove() {
    for (Polygon polygon : polygons) {
        polygon.remove();
    }
}
 
Example #17
Source Project: mage-android   Author: ngageoint   File: StaticGeometryCollection.java    License: Apache License 2.0 4 votes vote down vote up
public String getPopupHTML(Polygon polygon) {
	return featurePolygonDescriptions.get(polygon);
}
 
Example #18
Source Project: AirMapView   Author: airbnb   File: NativeGoogleMapFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Override public <T> void addPolygon(AirMapPolygon<T> polygon) {
  Polygon googlePolygon = googleMap.addPolygon(polygon.getPolygonOptions());
  polygon.setGooglePolygon(googlePolygon);
}
 
Example #19
Source Project: AirMapView   Author: airbnb   File: NativeGoogleMapFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Override public <T> void removePolygon(AirMapPolygon<T> polygon) {
  Polygon nativePolygon = polygon.getGooglePolygon();
  if (nativePolygon != null) {
    nativePolygon.remove();
  }
}
 
Example #20
Source Project: AirMapView   Author: airbnb   File: AirMapPolygon.java    License: Apache License 2.0 4 votes vote down vote up
public Polygon getGooglePolygon() {
  return googlePolygon;
}
 
Example #21
Source Project: AirMapView   Author: airbnb   File: AirMapPolygon.java    License: Apache License 2.0 4 votes vote down vote up
public void setGooglePolygon(Polygon googlePolygon) {
  this.googlePolygon = googlePolygon;
}
 
Example #22
Source Project: android-samples   Author: googlemaps   File: PolyActivity.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Manipulates the map when it's available.
 * The API invokes this callback when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera.
 * In this tutorial, we add polylines and polygons to represent routes and areas on the map.
 */
// [END EXCLUDE]
@Override
public void onMapReady(GoogleMap googleMap) {

    // Add polylines to the map.
    // Polylines are useful to show a route or some other connection between points.
    // [START maps_poly_activity_add_polyline_set_tag]
    // [START maps_poly_activity_add_polyline]
    Polyline polyline1 = googleMap.addPolyline(new PolylineOptions()
            .clickable(true)
            .add(
                    new LatLng(-35.016, 143.321),
                    new LatLng(-34.747, 145.592),
                    new LatLng(-34.364, 147.891),
                    new LatLng(-33.501, 150.217),
                    new LatLng(-32.306, 149.248),
                    new LatLng(-32.491, 147.309)));
    // [END maps_poly_activity_add_polyline]
    // [START_EXCLUDE silent]
    // Store a data object with the polyline, used here to indicate an arbitrary type.
    polyline1.setTag("A");
    // [END maps_poly_activity_add_polyline_set_tag]
    // Style the polyline.
    stylePolyline(polyline1);

    Polyline polyline2 = googleMap.addPolyline(new PolylineOptions()
            .clickable(true)
            .add(
                    new LatLng(-29.501, 119.700),
                    new LatLng(-27.456, 119.672),
                    new LatLng(-25.971, 124.187),
                    new LatLng(-28.081, 126.555),
                    new LatLng(-28.848, 124.229),
                    new LatLng(-28.215, 123.938)));
    polyline2.setTag("B");
    stylePolyline(polyline2);

    // [START maps_poly_activity_add_polygon]
    // Add polygons to indicate areas on the map.
    Polygon polygon1 = googleMap.addPolygon(new PolygonOptions()
            .clickable(true)
            .add(
                    new LatLng(-27.457, 153.040),
                    new LatLng(-33.852, 151.211),
                    new LatLng(-37.813, 144.962),
                    new LatLng(-34.928, 138.599)));
    // Store a data object with the polygon, used here to indicate an arbitrary type.
    polygon1.setTag("alpha");
    // [END maps_poly_activity_add_polygon]
    // Style the polygon.
    stylePolygon(polygon1);

    Polygon polygon2 = googleMap.addPolygon(new PolygonOptions()
            .clickable(true)
            .add(
                    new LatLng(-31.673, 128.892),
                    new LatLng(-31.952, 115.857),
                    new LatLng(-17.785, 122.258),
                    new LatLng(-12.4258, 130.7932)));
    polygon2.setTag("beta");
    stylePolygon(polygon2);
    // [END_EXCLUDE]

    // Position the map's camera near Alice Springs in the center of Australia,
    // and set the zoom factor so most of Australia shows on the screen.
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-23.684, 133.903), 4));

    // Set listeners for click events.
    googleMap.setOnPolylineClickListener(this);
    googleMap.setOnPolygonClickListener(this);
}
 
Example #23
Source Project: android-samples   Author: googlemaps   File: TagsDemoActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onPolygonClick(Polygon polygon) {
    onClick((CustomTag) polygon.getTag());
}
 
Example #24
Source Project: android-samples   Author: googlemaps   File: PolygonDemoActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
    // Override the default content description on the view, for accessibility mode.
    map.setContentDescription(getString(R.string.polygon_demo_description));

    int fillColorArgb = Color.HSVToColor(
            fillAlphaBar.getProgress(), new float[]{fillHueBar.getProgress(), 1, 1});
    int strokeColorArgb = Color.HSVToColor(
            strokeAlphaBar.getProgress(), new float[]{strokeHueBar.getProgress(), 1, 1});

    // Create a rectangle with two rectangular holes.
    mutablePolygon = map.addPolygon(new PolygonOptions()
            .addAll(createRectangle(CENTER, 5, 5))
            .addHole(createRectangle(new LatLng(-22, 128), 1, 1))
            .addHole(createRectangle(new LatLng(-18, 133), 0.5, 1.5))
            .fillColor(fillColorArgb)
            .strokeColor(strokeColorArgb)
            .strokeWidth(strokeWidthBar.getProgress())
            .clickable(clickabilityCheckbox.isChecked()));

    fillHueBar.setOnSeekBarChangeListener(this);
    fillAlphaBar.setOnSeekBarChangeListener(this);

    strokeWidthBar.setOnSeekBarChangeListener(this);
    strokeHueBar.setOnSeekBarChangeListener(this);
    strokeAlphaBar.setOnSeekBarChangeListener(this);

    strokeJointTypeSpinner.setOnItemSelectedListener(this);
    strokePatternSpinner.setOnItemSelectedListener(this);

    mutablePolygon.setStrokeJointType(getSelectedJointType(strokeJointTypeSpinner.getSelectedItemPosition()));
    mutablePolygon.setStrokePattern(getSelectedPattern(strokePatternSpinner.getSelectedItemPosition()));

    // Move the map so that it is centered on the mutable polygon.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(CENTER, 4));

    // Add a listener for polygon clicks that changes the clicked polygon's stroke color.
    map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
        @Override
        public void onPolygonClick(Polygon polygon) {
            // Flip the red, green and blue components of the polygon's stroke color.
            polygon.setStrokeColor(polygon.getStrokeColor() ^ 0x00ffffff);
        }
    });
}
 
Example #25
Source Project: android-maps-utils   Author: googlemaps   File: Renderer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Adds a single geometry object to the map with its specified style (used for KML)
 *
 * @param geometry defines the type of object to add to the map
 * @param style    defines styling properties to add to the object when added to the map
 * @return the object that was added to the map, this is a Marker, Polyline, Polygon or an array
 * of either objects
 */
protected Object addKmlPlacemarkToMap(KmlPlacemark placemark, Geometry geometry, KmlStyle style,
                                      KmlStyle inlineStyle, boolean isVisible) {
    String geometryType = geometry.getGeometryType();
    boolean hasDrawOrder = placemark.hasProperty("drawOrder");
    float drawOrder = 0;

    if (hasDrawOrder) {
        try {
            drawOrder = Float.parseFloat(placemark.getProperty("drawOrder"));
        } catch (NumberFormatException e) {
            hasDrawOrder = false;
        }
    }
    switch (geometryType) {
        case "Point":
            MarkerOptions markerOptions = style.getMarkerOptions();
            if (inlineStyle != null) {
                setInlinePointStyle(markerOptions, inlineStyle, style);
            } else if (style.getIconUrl() != null) {
                // Use shared style
                addMarkerIcons(style.getIconUrl(), style.getIconScale(), markerOptions);
            }
            Marker marker = addPointToMap(markerOptions, (KmlPoint) geometry);
            marker.setVisible(isVisible);
            setMarkerInfoWindow(style, marker, placemark);
            if (hasDrawOrder) {
                marker.setZIndex(drawOrder);
            }
            return marker;
        case "LineString":
            PolylineOptions polylineOptions = style.getPolylineOptions();
            if (inlineStyle != null) {
                setInlineLineStringStyle(polylineOptions, inlineStyle);
            } else if (style.isLineRandomColorMode()) {
                polylineOptions.color(KmlStyle.computeRandomColor(polylineOptions.getColor()));
            }
            Polyline polyline = addLineStringToMap(polylineOptions, (LineString) geometry);
            polyline.setVisible(isVisible);
            if (hasDrawOrder) {
                polyline.setZIndex(drawOrder);
            }
            return polyline;
        case "Polygon":
            PolygonOptions polygonOptions = style.getPolygonOptions();
            if (inlineStyle != null) {
                setInlinePolygonStyle(polygonOptions, inlineStyle);
            } else if (style.isPolyRandomColorMode()) {
                polygonOptions.fillColor(KmlStyle.computeRandomColor(polygonOptions.getFillColor()));
            }
            Polygon polygon = addPolygonToMap(polygonOptions, (DataPolygon) geometry);
            polygon.setVisible(isVisible);
            if (hasDrawOrder) {
                polygon.setZIndex(drawOrder);
            }
            return polygon;
        case "MultiGeometry":
            return addMultiGeometryToMap(placemark, (KmlMultiGeometry) geometry, style, inlineStyle,
                    isVisible);
    }
    return null;
}
 
Example #26
Source Project: android-maps-utils   Author: googlemaps   File: Renderer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Sets a single click listener for each of the map object collections, that will be called
 * with the corresponding Feature object when an object on the map (Polygon, Marker, Polyline)
 * from one of this Renderer's collections is clicked.
 *
 * If getFeature() returns null this means that either the object is inside a KMLContainer,
 * or the object is a MultiPolygon, MultiLineString or MultiPoint and must
 * be handled differently.
 *
 * @param listener Listener providing the onFeatureClick method to call.
 */
void setOnFeatureClickListener(final Layer.OnFeatureClickListener listener) {

    mPolygons.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
        @Override
        public void onPolygonClick(Polygon polygon) {
            if (getFeature(polygon) != null) {
                listener.onFeatureClick(getFeature(polygon));
            } else if (getContainerFeature(polygon) != null) {
                listener.onFeatureClick(getContainerFeature(polygon));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(polygon)));
            }
        }
    });

    mMarkers.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            if (getFeature(marker) != null) {
                listener.onFeatureClick(getFeature(marker));
            }  else if (getContainerFeature(marker) != null) {
                listener.onFeatureClick(getContainerFeature(marker));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(marker)));
            }
            return false;
        }
    });

    mPolylines.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
        @Override
        public void onPolylineClick(Polyline polyline) {
            if (getFeature(polyline) != null) {
                listener.onFeatureClick(getFeature(polyline));
            } else if (getContainerFeature(polyline) != null) {
                listener.onFeatureClick(getContainerFeature(polyline));
            }  else {
                listener.onFeatureClick(getFeature(multiObjectHandler(polyline)));
            }
        }
    });
}
 
Example #27
Source Project: android-maps-utils   Author: googlemaps   File: PolygonManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void removeObjectFromMap(Polygon object) {
    object.remove();
}
 
Example #28
Source Project: android-maps-utils   Author: googlemaps   File: PolygonManager.java    License: Apache License 2.0 4 votes vote down vote up
public Polygon addPolygon(PolygonOptions opts) {
    Polygon polygon = mMap.addPolygon(opts);
    super.add(polygon);
    return polygon;
}
 
Example #29
Source Project: android-maps-utils   Author: googlemaps   File: PolygonManager.java    License: Apache License 2.0 4 votes vote down vote up
public void showAll() {
    for (Polygon polygon : getPolygons()) {
        polygon.setVisible(true);
    }
}
 
Example #30
Source Project: android-maps-utils   Author: googlemaps   File: PolygonManager.java    License: Apache License 2.0 4 votes vote down vote up
public void hideAll() {
    for (Polygon polygon : getPolygons()) {
        polygon.setVisible(false);
    }
}