use of com.google.android.gms.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(mFillAlphaBar.getProgress(), new float[] { mFillHueBar.getProgress(), 1, 1 });
int strokeColorArgb = Color.HSVToColor(mStrokeAlphaBar.getProgress(), new float[] { mStrokeHueBar.getProgress(), 1, 1 });
// Create a rectangle with two rectangular holes.
mMutablePolygon = 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(mStrokeWidthBar.getProgress()).clickable(mClickabilityCheckbox.isChecked()));
mFillHueBar.setOnSeekBarChangeListener(this);
mFillAlphaBar.setOnSeekBarChangeListener(this);
mStrokeWidthBar.setOnSeekBarChangeListener(this);
mStrokeHueBar.setOnSeekBarChangeListener(this);
mStrokeAlphaBar.setOnSeekBarChangeListener(this);
mStrokeJointTypeSpinner.setOnItemSelectedListener(this);
mStrokePatternSpinner.setOnItemSelectedListener(this);
mMutablePolygon.setStrokeJointType(getSelectedJointType(mStrokeJointTypeSpinner.getSelectedItemPosition()));
mMutablePolygon.setStrokePattern(getSelectedPattern(mStrokePatternSpinner.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.gms.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.gms.maps.model.PolygonOptions in project android-maps-utils by googlemaps.
the class Renderer method addKmlPlacemarkToMap.
/**
* 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;
}
use of com.google.android.gms.maps.model.PolygonOptions in project android-maps-utils by googlemaps.
the class GeoJsonPolygonStyle method toPolygonOptions.
/**
* 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;
}
use of com.google.android.gms.maps.model.PolygonOptions in project android-maps-utils by googlemaps.
the class KmlStyle method createPolygonOptions.
/**
* 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) {
float originalWidth = 0.0f;
PolygonOptions polygonOptions = new PolygonOptions();
if (isFill) {
polygonOptions.fillColor(originalPolygonOption.getFillColor());
}
if (isOutline) {
polygonOptions.strokeColor(originalPolygonOption.getStrokeColor());
originalWidth = originalPolygonOption.getStrokeWidth();
}
polygonOptions.strokeWidth(originalWidth);
polygonOptions.clickable(originalPolygonOption.isClickable());
return polygonOptions;
}
Aggregations