use of com.google.android.gms.maps.model.Polygon in project android-maps-utils by googlemaps.
the class Renderer method addPolygonToMap.
/**
* 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
*/
protected 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 = mMap.addPolygon(polygonOptions);
addedPolygon.setClickable(true);
return addedPolygon;
}
use of com.google.android.gms.maps.model.Polygon in project android-maps-utils by googlemaps.
the class Layer method setOnFeatureClickListener.
/**
* Sets a single click listener for the entire GoogleMap object, that will be called
* with the corresponding Feature object when an object on the map (Polygon,
* Marker, Polyline) 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.
*/
public void setOnFeatureClickListener(final OnFeatureClickListener listener) {
GoogleMap map = getMap();
map.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)));
}
}
});
map.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;
}
});
map.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)));
}
}
});
}
use of com.google.android.gms.maps.model.Polygon 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.getIconUrl());
} else if (style.getIconUrl() != null) {
// Use shared style
addMarkerIcons(style.getIconUrl(), 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.Polygon in project AirMapView by airbnb.
the class NativeGoogleMapFragment method addPolygon.
@Override
public <T> void addPolygon(AirMapPolygon<T> polygon) {
Polygon googlePolygon = googleMap.addPolygon(polygon.getPolygonOptions());
polygon.setGooglePolygon(googlePolygon);
}
Aggregations