com.google.android.gms.maps.model.Polygon Java Examples
The following examples show how to use
com.google.android.gms.maps.model.Polygon.
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 File: Renderer.java From android-maps-utils with Apache License 2.0 | 6 votes |
/** * 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 File: PolygonClickFuncTest.java From RxGoogleMaps with Apache License 2.0 | 5 votes |
@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 #3
Source File: PolyActivity.java From android-samples with Apache License 2.0 | 5 votes |
/** * 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 #4
Source File: PolyActivity.java From android-samples with Apache License 2.0 | 5 votes |
/** * 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 #5
Source File: PolygonManager.java From android-maps-utils with Apache License 2.0 | 5 votes |
@Override public void onPolygonClick(Polygon polygon) { Collection collection = mAllObjects.get(polygon); if (collection != null && collection.mPolygonClickListener != null) { collection.mPolygonClickListener.onPolygonClick(polygon); } }
Example #6
Source File: StaticGeometryCollection.java From mage-android with Apache License 2.0 | 5 votes |
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 #7
Source File: Renderer.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * 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 #8
Source File: Renderer.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * 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 File: Renderer.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * 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 #10
Source File: StaticGeometryCollection.java From mage-android with Apache License 2.0 | 5 votes |
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 #11
Source File: Renderer.java From android-maps-utils with Apache License 2.0 | 4 votes |
/** * 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 #12
Source File: PolyActivity.java From android-samples with Apache License 2.0 | 4 votes |
/** * 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 #13
Source File: TagsDemoActivity.java From android-samples with Apache License 2.0 | 4 votes |
@Override public void onPolygonClick(Polygon polygon) { onClick((CustomTag) polygon.getTag()); }
Example #14
Source File: PolygonDemoActivity.java From android-samples with Apache License 2.0 | 4 votes |
@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 #15
Source File: AirMapPolygon.java From AirMapView with Apache License 2.0 | 4 votes |
public void setGooglePolygon(Polygon googlePolygon) { this.googlePolygon = googlePolygon; }
Example #16
Source File: Renderer.java From android-maps-utils with Apache License 2.0 | 4 votes |
/** * 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 #17
Source File: PolygonManager.java From android-maps-utils with Apache License 2.0 | 4 votes |
@Override protected void removeObjectFromMap(Polygon object) { object.remove(); }
Example #18
Source File: PolygonManager.java From android-maps-utils with Apache License 2.0 | 4 votes |
public Polygon addPolygon(PolygonOptions opts) { Polygon polygon = mMap.addPolygon(opts); super.add(polygon); return polygon; }
Example #19
Source File: PolygonManager.java From android-maps-utils with Apache License 2.0 | 4 votes |
public void showAll() { for (Polygon polygon : getPolygons()) { polygon.setVisible(true); } }
Example #20
Source File: PolygonManager.java From android-maps-utils with Apache License 2.0 | 4 votes |
public void hideAll() { for (Polygon polygon : getPolygons()) { polygon.setVisible(false); } }
Example #21
Source File: PolygonManager.java From android-maps-utils with Apache License 2.0 | 4 votes |
public boolean remove(Polygon polygon) { return super.remove(polygon); }
Example #22
Source File: PolygonManager.java From android-maps-utils with Apache License 2.0 | 4 votes |
public java.util.Collection<Polygon> getPolygons() { return getObjects(); }
Example #23
Source File: AirMapPolygon.java From AirMapView with Apache License 2.0 | 4 votes |
public Polygon getGooglePolygon() { return googlePolygon; }
Example #24
Source File: NativeGoogleMapFragment.java From AirMapView with Apache License 2.0 | 4 votes |
@Override public <T> void removePolygon(AirMapPolygon<T> polygon) { Polygon nativePolygon = polygon.getGooglePolygon(); if (nativePolygon != null) { nativePolygon.remove(); } }
Example #25
Source File: NativeGoogleMapFragment.java From AirMapView with Apache License 2.0 | 4 votes |
@Override public <T> void addPolygon(AirMapPolygon<T> polygon) { Polygon googlePolygon = googleMap.addPolygon(polygon.getPolygonOptions()); polygon.setGooglePolygon(googlePolygon); }
Example #26
Source File: ShapeActivity.java From Complete-Google-Map-API-Tutorial with Apache License 2.0 | 4 votes |
@Override public void onPolygonClick(Polygon polygon) { onClick((CustomTag) polygon.getTag()); }
Example #27
Source File: StaticGeometryCollection.java From mage-android with Apache License 2.0 | 4 votes |
public String getPopupHTML(Polygon polygon) { return featurePolygonDescriptions.get(polygon); }
Example #28
Source File: GoogleMapShape.java From geopackage-android-map with MIT License | 4 votes |
/** * 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 #29
Source File: MultiPolygon.java From geopackage-android-map with MIT License | 4 votes |
/** * Remove from the map */ public void remove() { for (Polygon polygon : polygons) { polygon.remove(); } }
Example #30
Source File: GoogleMapShape.java From geopackage-android-map with MIT License | 4 votes |
/** * 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: } }