com.google.android.gms.maps.model.PolygonOptions Java Examples
The following examples show how to use
com.google.android.gms.maps.model.PolygonOptions.
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: ShapeActivity.java From Complete-Google-Map-API-Tutorial with Apache License 2.0 | 6 votes |
private void addPolygon() { googleMap.clear(); PolygonOptions polygonOptions = new PolygonOptions(); polygonOptions.add(new LatLng(0, 0)); polygonOptions.add(new LatLng(-3, 2.5)); polygonOptions.add(new LatLng(0, 5)); polygonOptions.add(new LatLng(3, 5)); polygonOptions.add(new LatLng(3, 0)); polygonOptions.add(new LatLng(0, 0)); polygonOptions.clickable(true); polygonOptions.fillColor(Color.BLUE); googleMap.addPolygon(polygonOptions).setTag(new CustomTag("polygon")); googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(0, 0))); }
Example #2
Source File: GoogleMapShapeConverter.java From geopackage-android-map with MIT License | 6 votes |
/** * Add a MultiPolygonOptions to the map as markers * * @param shapeMarkers google map shape markers * @param map google map * @param multiPolygon multi polygon options * @param polygonMarkerOptions polygon marker options * @param polygonMarkerHoleOptions polygon marker hole options * @param globalPolygonOptions global polygon options * @return multi polygon markers */ public MultiPolygonMarkers addMultiPolygonToMapAsMarkers( GoogleMapShapeMarkers shapeMarkers, GoogleMap map, MultiPolygonOptions multiPolygon, MarkerOptions polygonMarkerOptions, MarkerOptions polygonMarkerHoleOptions, PolygonOptions globalPolygonOptions) { MultiPolygonMarkers multiPolygonMarkers = new MultiPolygonMarkers(); for (PolygonOptions polygon : multiPolygon.getPolygonOptions()) { PolygonMarkers polygonMarker = addPolygonToMapAsMarkers( shapeMarkers, map, polygon, polygonMarkerOptions, polygonMarkerHoleOptions, globalPolygonOptions); shapeMarkers.add(polygonMarker); multiPolygonMarkers.add(polygonMarker); } return multiPolygonMarkers; }
Example #3
Source File: MapUtils.java From geopackage-android-map with MIT License | 6 votes |
/** * Is the point of the polygon * * @param point point * @param polygon polygon * @param geodesic geodesic check flag * @param tolerance distance tolerance * @return true if on the polygon */ public static boolean isPointOnPolygon(LatLng point, PolygonOptions polygon, boolean geodesic, double tolerance) { boolean onPolygon = PolyUtil.containsLocation(point, polygon.getPoints(), geodesic) || PolyUtil.isLocationOnEdge(point, polygon.getPoints(), geodesic, tolerance); if (onPolygon) { for (List<LatLng> hole : polygon.getHoles()) { if (PolyUtil.containsLocation(point, hole, geodesic)) { onPolygon = false; break; } } } return onPolygon; }
Example #4
Source File: GoogleMapShapeConverterUtils.java From geopackage-android-map with MIT License | 6 votes |
/** * Compare Polygon with Map Polygon * * @param converter * @param polygon * @param polygon2 */ private static void comparePolygonAndMapPolygon(GoogleMapShapeConverter converter, Polygon polygon, PolygonOptions polygon2) { List<LineString> rings = polygon.getRings(); List<LatLng> points = polygon2.getPoints(); List<List<LatLng>> holes = polygon2.getHoles(); TestCase.assertEquals(polygon.numRings(), 1 + holes.size()); LineString polygonRing = rings.get(0); compareLineStringAndLatLngs(converter, polygonRing, points); for (int i = 1; i < rings.size(); i++) { LineString ring = rings.get(i); List<LatLng> hole = holes.get(i - 1); compareLineStringAndLatLngs(converter, ring, hole); } }
Example #5
Source File: MyMapView.java From open-location-code with Apache License 2.0 | 6 votes |
@Override public void drawCodeArea(final OpenLocationCode code) { if (code.equals(mLastDisplayedCode)) { // Skip if we're already displaying this location. return; } mLastDisplayedCode = code; if (mMap != null) { CodeArea area = code.decode(); LatLng southWest = new LatLng(area.getSouthLatitude(), area.getWestLongitude()); LatLng northWest = new LatLng(area.getNorthLatitude(), area.getWestLongitude()); LatLng southEast = new LatLng(area.getSouthLatitude(), area.getEastLongitude()); LatLng northEast = new LatLng(area.getNorthLatitude(), area.getEastLongitude()); if (mCodePolygon != null) { mCodePolygon.remove(); } mCodePolygon = mMap.addPolygon( new PolygonOptions().add(southWest, northWest,northEast, southEast) .strokeColor(ContextCompat.getColor(this.getContext(), R.color.code_box_stroke)) .strokeWidth(CODE_AREA_STROKE_WIDTH) .fillColor(ContextCompat.getColor(this.getContext(), R.color.code_box_fill))); } }
Example #6
Source File: StyleUtils.java From geopackage-android-map with MIT License | 6 votes |
/** * Set the style into the polygon options * * @param polygonOptions polygon options * @param style style row * @param density display density: {@link android.util.DisplayMetrics#density} * @return true if style was set into the polygon options */ public static boolean setStyle(PolygonOptions polygonOptions, StyleRow style, float density) { if (style != null) { Color color = style.getColorOrDefault(); polygonOptions.strokeColor(color.getColorWithAlpha()); double width = style.getWidthOrDefault(); polygonOptions.strokeWidth((float) width * density); Color fillColor = style.getFillColor(); if (fillColor != null) { polygonOptions.fillColor(fillColor.getColorWithAlpha()); } } return style != null; }
Example #7
Source File: Renderer.java From android-maps-utils with Apache License 2.0 | 6 votes |
/** * Sets the inline polygon style by copying over the styles that have been set * * @param polygonOptions polygon options object to add inline styles to * @param inlineStyle inline styles to apply */ private void setInlinePolygonStyle(PolygonOptions polygonOptions, KmlStyle inlineStyle) { PolygonOptions inlinePolygonOptions = inlineStyle.getPolygonOptions(); if (inlineStyle.hasFill() && inlineStyle.isStyleSet("fillColor")) { polygonOptions.fillColor(inlinePolygonOptions.getFillColor()); } if (inlineStyle.hasOutline()) { if (inlineStyle.isStyleSet("outlineColor")) { polygonOptions.strokeColor(inlinePolygonOptions.getStrokeColor()); } if (inlineStyle.isStyleSet("width")) { polygonOptions.strokeWidth(inlinePolygonOptions.getStrokeWidth()); } } if (inlineStyle.isPolyRandomColorMode()) { polygonOptions.fillColor(KmlStyle.computeRandomColor(inlinePolygonOptions.getFillColor())); } }
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: StyleUtils.java From geopackage-android-map with MIT License | 5 votes |
/** * Create new polygon options populated with the style * * @param style style row * @param density display density: {@link android.util.DisplayMetrics#density} * @return polygon options populated with the style */ public static PolygonOptions createPolygonOptions(StyleRow style, float density) { PolygonOptions polygonOptions = new PolygonOptions(); setStyle(polygonOptions, style, density); return polygonOptions; }
Example #10
Source File: StyleUtils.java From geopackage-android-map with MIT License | 5 votes |
/** * Create new polygon options populated with the feature style * * @param featureStyle feature style * @param density display density: {@link android.util.DisplayMetrics#density} * @return polygon options populated with the feature style */ public static PolygonOptions createPolygonOptions(FeatureStyle featureStyle, float density) { PolygonOptions polygonOptions = new PolygonOptions(); setFeatureStyle(polygonOptions, featureStyle, density); return polygonOptions; }
Example #11
Source File: MapUtils.java From geopackage-android-map with MIT License | 5 votes |
/** * Is the point on the multi polygon * * @param point point * @param multiPolygon multi polygon * @param geodesic geodesic check flag * @param tolerance distance tolerance * @return true if on the multi polygon */ public static boolean isPointOnMultiPolygon(LatLng point, MultiPolygonOptions multiPolygon, boolean geodesic, double tolerance) { boolean near = false; for (PolygonOptions polygon : multiPolygon.getPolygonOptions()) { near = isPointOnPolygon(point, polygon, geodesic, tolerance); if (near) { break; } } return near; }
Example #12
Source File: GoogleMapShapeConverter.java From geopackage-android-map with MIT License | 5 votes |
/** * Convert a {@link MultiPolygon} to a {@link MultiPolygonOptions} * * @param multiPolygon multi polygon * @return multi polygon options */ public MultiPolygonOptions toPolygons(MultiPolygon multiPolygon) { MultiPolygonOptions polygons = new MultiPolygonOptions(); for (Polygon polygon : multiPolygon.getPolygons()) { PolygonOptions polygonOptions = toPolygon(polygon); polygons.add(polygonOptions); } return polygons; }
Example #13
Source File: GoogleMapShapeConverter.java From geopackage-android-map with MIT License | 5 votes |
/** * Convert a list of {@link PolygonOptions} to a {@link MultiPolygon} * * @param multiPolygonOptions multi polygon options * @param hasZ has z flag * @param hasM has m flag * @return multi polygon */ public MultiPolygon toMultiPolygonFromOptions( MultiPolygonOptions multiPolygonOptions, boolean hasZ, boolean hasM) { MultiPolygon multiPolygon = new MultiPolygon(hasZ, hasM); for (PolygonOptions mapPolygon : multiPolygonOptions .getPolygonOptions()) { Polygon polygon = toPolygon(mapPolygon); multiPolygon.addPolygon(polygon); } return multiPolygon; }
Example #14
Source File: GoogleMapShapeConverter.java From geopackage-android-map with MIT License | 5 votes |
/** * Convert a {@link PolyhedralSurface} to a {@link MultiPolygonOptions} * * @param polyhedralSurface polyhedral surface * @return multi polygon options */ public MultiPolygonOptions toPolygons(PolyhedralSurface polyhedralSurface) { MultiPolygonOptions polygons = new MultiPolygonOptions(); for (Polygon polygon : polyhedralSurface.getPolygons()) { PolygonOptions polygonOptions = toPolygon(polygon); polygons.add(polygonOptions); } return polygons; }
Example #15
Source File: GoogleMapShapeConverter.java From geopackage-android-map with MIT License | 5 votes |
/** * Convert a {@link MultiPolygonOptions} to a {@link PolyhedralSurface} * * @param multiPolygonOptions multi polygon options * @param hasZ has z flag * @param hasM has m flag * @return polyhedral surface */ public PolyhedralSurface toPolyhedralSurfaceWithOptions( MultiPolygonOptions multiPolygonOptions, boolean hasZ, boolean hasM) { PolyhedralSurface polyhedralSurface = new PolyhedralSurface(hasZ, hasM); for (PolygonOptions mapPolygon : multiPolygonOptions .getPolygonOptions()) { Polygon polygon = toPolygon(mapPolygon); polyhedralSurface.addPolygon(polygon); } return polyhedralSurface; }
Example #16
Source File: GoogleMapShapeConverter.java From geopackage-android-map with MIT License | 5 votes |
/** * Add a Polygon to the map as markers * * @param shapeMarkers google map shape markers * @param map google map * @param polygonOptions polygon options * @param polygonMarkerOptions polygon marker options * @param polygonMarkerHoleOptions polygon marker hole options * @param globalPolygonOptions global polygon options * @return polygon markers */ public PolygonMarkers addPolygonToMapAsMarkers( GoogleMapShapeMarkers shapeMarkers, GoogleMap map, PolygonOptions polygonOptions, MarkerOptions polygonMarkerOptions, MarkerOptions polygonMarkerHoleOptions, PolygonOptions globalPolygonOptions) { PolygonMarkers polygonMarkers = new PolygonMarkers(this); if (globalPolygonOptions != null) { polygonOptions.fillColor(globalPolygonOptions.getFillColor()); polygonOptions.strokeColor(globalPolygonOptions.getStrokeColor()); polygonOptions.geodesic(globalPolygonOptions.isGeodesic()); polygonOptions.visible(globalPolygonOptions.isVisible()); polygonOptions.zIndex(globalPolygonOptions.getZIndex()); polygonOptions.strokeWidth(globalPolygonOptions.getStrokeWidth()); } com.google.android.gms.maps.model.Polygon polygon = addPolygonToMap( map, polygonOptions); polygonMarkers.setPolygon(polygon); List<Marker> markers = addPointsToMapAsMarkers(map, polygon.getPoints(), polygonMarkerOptions, true); polygonMarkers.setMarkers(markers); for (List<LatLng> holes : polygon.getHoles()) { List<Marker> holeMarkers = addPointsToMapAsMarkers(map, holes, polygonMarkerHoleOptions, true); PolygonHoleMarkers polygonHoleMarkers = new PolygonHoleMarkers( polygonMarkers); polygonHoleMarkers.setMarkers(holeMarkers); shapeMarkers.add(polygonHoleMarkers); polygonMarkers.addHole(polygonHoleMarkers); } return polygonMarkers; }
Example #17
Source File: MainActivity.java From effective_android_sample with Apache License 2.0 | 5 votes |
/** * 戦場1つを描画する */ private void drawField(Field field) { // マーカー定義 MarkerOptions markerOptions = new MarkerOptions(); markerOptions.title(field.getName()); // 名前を設定 markerOptions.snippet(field.getMemo()); // 説明を設定 markerOptions.position(calcCenter(field.getVertexes())); // マーカーの座標を設定(区画の中心を自動算出) markerOptions.icon(BitmapDescriptorFactory.defaultMarker(field.getColorHue())); // 色を設定 // マップにマーカーを追加 mGoogleMap.addMarker(markerOptions); // 区画を描画 final LatLng[] vertexes = field.getVertexes(); if (vertexes != null && vertexes.length > 3) { // ポリゴン定義 PolygonOptions polygonOptions = new PolygonOptions(); // RGBそれぞれの色を作成 final int[] colorRgb = field.getColorRgb(); int colorRed = colorRgb[0]; int colorGreen = colorRgb[1]; int colorBlue = colorRgb[2]; // 区画の輪郭について設定 polygonOptions.strokeColor(Color.argb(0x255, colorRed, colorGreen, colorBlue)); polygonOptions.strokeWidth(5); // 区画の塗りつぶしについて設定 polygonOptions.fillColor(Color.argb(0x40, colorRed, colorGreen, colorBlue)); // 各頂点の座標を設定 polygonOptions.add(vertexes); // LatLngでもLatLng[]でもOK // マップにポリゴンを追加 mGoogleMap.addPolygon(polygonOptions); } }
Example #18
Source File: KmlStyle.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * Creates a new PolygonOption from given properties of an existing PolygonOption * * @param originalPolygonOption An existing PolygonOption instance * @param isFill Whether the fill for a polygon is set * @param isOutline Whether the outline for a polygon is set * @return A new PolygonOption */ private static PolygonOptions createPolygonOptions(PolygonOptions originalPolygonOption, boolean isFill, boolean isOutline) { PolygonOptions polygonOptions = new PolygonOptions(); if (isFill) { polygonOptions.fillColor(originalPolygonOption.getFillColor()); } if (isOutline) { polygonOptions.strokeColor(originalPolygonOption.getStrokeColor()); polygonOptions.strokeWidth(originalPolygonOption.getStrokeWidth()); } polygonOptions.clickable(originalPolygonOption.isClickable()); return polygonOptions; }
Example #19
Source File: GoogleMapShapeConverterUtils.java From geopackage-android-map with MIT License | 5 votes |
/** * Test the Polygon conversion * * @param converter * @param polygon */ private static void convertPolygon(GoogleMapShapeConverter converter, Polygon polygon) { PolygonOptions polygonOptions = converter.toPolygon(polygon); TestCase.assertNotNull(polygonOptions); comparePolygonAndMapPolygon(converter, polygon, polygonOptions); Polygon polygon2 = converter.toPolygon(polygonOptions); comparePolygons(polygon, polygon2); }
Example #20
Source File: KmlPlacemark.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * Gets a PolygonOption * * @return new PolygonOptions */ public PolygonOptions getPolygonOptions() { if (mInlineStyle == null) { return null; } return mInlineStyle.getPolygonOptions(); }
Example #21
Source File: GoogleMapShapeConverterUtils.java From geopackage-android-map with MIT License | 5 votes |
/** * Compare list of polygons with list of map polygons * * @param converter * @param polygons * @param mapPolygons */ private static void comparePolygonsAndMapPolygons(GoogleMapShapeConverter converter, List<Polygon> polygons, List<PolygonOptions> mapPolygons) { TestCase.assertEquals(polygons.size(), mapPolygons.size()); for (int i = 0; i < polygons.size(); i++) { comparePolygonAndMapPolygon(converter, polygons.get(i), mapPolygons.get(i)); } }
Example #22
Source File: MapObservationManager.java From mage-android with Apache License 2.0 | 5 votes |
/** * Set the polygon options * * @param style shape style * @param polygonOptions polygon options * @param visible visible flag */ private void setPolygonOptions(ObservationShapeStyle style, PolygonOptions polygonOptions, boolean visible) { polygonOptions.strokeWidth(style.getStrokeWidth()); polygonOptions.strokeColor(style.getStrokeColor()); polygonOptions.fillColor(style.getFillColor()); polygonOptions.visible(visible); polygonOptions.geodesic(MapShapeObservation.GEODESIC); }
Example #23
Source File: MapFragment.java From Android-GoogleMaps-Part1 with BSD 2-Clause "Simplified" License | 5 votes |
private void drawPolygon( LatLng startingLocation ) { LatLng point2 = new LatLng( startingLocation.latitude + .001, startingLocation.longitude ); LatLng point3 = new LatLng( startingLocation.latitude, startingLocation.longitude + .001 ); PolygonOptions options = new PolygonOptions(); options.add(startingLocation, point2, point3); options.fillColor( getResources().getColor( R.color.fill_color ) ); options.strokeColor( getResources().getColor( R.color.stroke_color ) ); options.strokeWidth( 10 ); getMap().addPolygon(options); }
Example #24
Source File: LiteDemoActivity.java From android-samples with Apache License 2.0 | 5 votes |
/** * Add a Polyline and a Polygon to the map. * The Polyline connects Melbourne, Adelaide and Perth. The Polygon is located in the Northern * Territory (Australia). */ private void addPolyObjects() { map.addPolyline((new PolylineOptions()) .add(MELBOURNE, ADELAIDE, PERTH) .color(Color.GREEN) .width(5f)); map.addPolygon(new PolygonOptions() .add(POLYGON) .fillColor(Color.CYAN) .strokeColor(Color.BLUE) .strokeWidth(5)); }
Example #25
Source File: GeoJsonPolygonStyle.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * Gets a new PolygonOptions object containing styles for the GeoJsonPolygon * * @return new PolygonOptions object */ public PolygonOptions toPolygonOptions() { PolygonOptions polygonOptions = new PolygonOptions(); polygonOptions.fillColor(mPolygonOptions.getFillColor()); polygonOptions.geodesic(mPolygonOptions.isGeodesic()); polygonOptions.strokeColor(mPolygonOptions.getStrokeColor()); polygonOptions.strokeJointType(mPolygonOptions.getStrokeJointType()); polygonOptions.strokePattern(mPolygonOptions.getStrokePattern()); polygonOptions.strokeWidth(mPolygonOptions.getStrokeWidth()); polygonOptions.visible(mPolygonOptions.isVisible()); polygonOptions.zIndex(mPolygonOptions.getZIndex()); polygonOptions.clickable(mPolygonOptions.isClickable()); return polygonOptions; }
Example #26
Source File: Style.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * Creates a new Style object */ public Style() { mMarkerOptions = new MarkerOptions(); mPolylineOptions = new PolylineOptions(); mPolylineOptions.clickable(true); mPolygonOptions = new PolygonOptions(); mPolygonOptions.clickable(true); }
Example #27
Source File: MapFragment.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
private void drawPolygon( LatLng startingLocation ) { LatLng point2 = new LatLng( startingLocation.latitude + .001, startingLocation.longitude ); LatLng point3 = new LatLng( startingLocation.latitude, startingLocation.longitude + .001 ); PolygonOptions options = new PolygonOptions(); options.add(startingLocation, point2, point3); options.fillColor( getResources().getColor( R.color.fill_color ) ); options.strokeColor( getResources().getColor( R.color.stroke_color ) ); options.strokeWidth( 10 ); getMap().addPolygon(options); }
Example #28
Source File: PolygonImpl.java From android_packages_apps_GmsCore with Apache License 2.0 | 4 votes |
public PolygonImpl(String id, PolygonOptions options, MarkupListener listener) { this.id = id; this.options = options; this.listener = listener; }
Example #29
Source File: GoogleMapImpl.java From android_packages_apps_GmsCore with Apache License 2.0 | 4 votes |
@Override public IPolygonDelegate addPolygon(PolygonOptions options) throws RemoteException { return backendMap.add(new PolygonImpl(getNextPolygonId(), options, this)); }
Example #30
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); } }); }