use of com.google.android.libraries.maps.model.PolygonOptions in project android-samples by googlemaps.
the class LiteDemoActivity method addPolyObjects.
/**
* 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));
}
use of com.google.android.libraries.maps.model.PolygonOptions in project android-samples by googlemaps.
the class PolygonDemoActivity method onMapReady.
@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);
}
});
}
use of com.google.android.libraries.maps.model.PolygonOptions in project android-samples by googlemaps.
the class TagsDemoActivity method addObjectsToMap.
private void addObjectsToMap() {
// A circle centered on Adelaide.
mAdelaideCircle = mMap.addCircle(new CircleOptions().center(ADELAIDE).radius(500000).fillColor(Color.argb(150, 66, 173, 244)).strokeColor(Color.rgb(66, 173, 244)).clickable(true));
mAdelaideCircle.setTag(new CustomTag("Adelaide circle"));
// A ground overlay at Sydney.
mSydneyGroundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.harbour_bridge)).position(SYDNEY, 700000).clickable(true));
mSydneyGroundOverlay.setTag(new CustomTag("Sydney ground overlay"));
// A marker at Hobart.
mHobartMarker = mMap.addMarker(new MarkerOptions().position(HOBART));
mHobartMarker.setTag(new CustomTag("Hobart marker"));
// A polygon centered at Darwin.
mDarwinPolygon = mMap.addPolygon(new PolygonOptions().add(new LatLng(DARWIN.latitude + 3, DARWIN.longitude - 3), new LatLng(DARWIN.latitude + 3, DARWIN.longitude + 3), new LatLng(DARWIN.latitude - 3, DARWIN.longitude + 3), new LatLng(DARWIN.latitude - 3, DARWIN.longitude - 3)).fillColor(Color.argb(150, 34, 173, 24)).strokeColor(Color.rgb(34, 173, 24)).clickable(true));
mDarwinPolygon.setTag(new CustomTag("Darwin polygon"));
// A polyline from Perth to Brisbane.
mPolyline = mMap.addPolyline(new PolylineOptions().add(PERTH, BRISBANE).color(Color.rgb(103, 24, 173)).width(30).clickable(true));
mPolyline.setTag(new CustomTag("Perth to Brisbane polyline"));
}
use of com.google.android.libraries.maps.model.PolygonOptions in project android-maps-utils by googlemaps.
the class PolySimplifyDemoActivity method startDemo.
@Override
protected void startDemo(boolean isRestore) {
GoogleMap map = getMap();
// Original line
List<LatLng> line = PolyUtil.decode(LINE);
map.addPolyline(new PolylineOptions().addAll(line).color(Color.BLACK));
if (!isRestore) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15));
}
List<LatLng> simplifiedLine;
/*
* Simplified lines - increasing the tolerance will result in fewer points in the simplified
* line
*/
// meters
double tolerance = 5;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.RED - ALPHA_ADJUSTMENT));
// meters
tolerance = 20;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.GREEN - ALPHA_ADJUSTMENT));
// meters
tolerance = 50;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.MAGENTA - ALPHA_ADJUSTMENT));
// meters
tolerance = 500;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.YELLOW - ALPHA_ADJUSTMENT));
// meters
tolerance = 1000;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.BLUE - ALPHA_ADJUSTMENT));
// Triangle polygon - the polygon should be closed
ArrayList<LatLng> triangle = new ArrayList<>();
// Should match last point
triangle.add(new LatLng(28.06025, -82.41030));
triangle.add(new LatLng(28.06129, -82.40945));
triangle.add(new LatLng(28.06206, -82.40917));
triangle.add(new LatLng(28.06125, -82.40850));
triangle.add(new LatLng(28.06035, -82.40834));
triangle.add(new LatLng(28.06038, -82.40924));
// Should match first point
triangle.add(new LatLng(28.06025, -82.41030));
map.addPolygon(new PolygonOptions().addAll(triangle).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
// Simplified triangle polygon
// meters
tolerance = 88;
List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance);
map.addPolygon(new PolygonOptions().addAll(simplifiedTriangle).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
// Oval polygon - the polygon should be closed
List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
map.addPolygon(new PolygonOptions().addAll(oval).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
// Simplified oval polygon
// meters
tolerance = 10;
List simplifiedOval = PolyUtil.simplify(oval, tolerance);
map.addPolygon(new PolygonOptions().addAll(simplifiedOval).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
}
use of com.google.android.libraries.maps.model.PolygonOptions in project google-maps by capacitor-community.
the class CapacitorGoogleMaps method addPolygon.
@PluginMethod()
public void addPolygon(final PluginCall call) {
final JSArray points = call.getArray("points", new JSArray());
getBridge().executeOnMainThread(new Runnable() {
@Override
public void run() {
PolygonOptions polygonOptions = new PolygonOptions();
for (int i = 0; i < points.length(); i++) {
try {
JSONObject point = points.getJSONObject(i);
LatLng latLng = new LatLng(point.getDouble("latitude"), point.getDouble("longitude"));
polygonOptions.add(latLng);
} catch (JSONException e) {
e.printStackTrace();
}
}
googleMap.addPolygon(polygonOptions);
call.resolve();
}
});
}
Aggregations