use of com.google.maps.android.collections.PolygonManager in project android-maps-utils by googlemaps.
the class MultiLayerDemoActivity method startDemo.
@Override
protected void startDemo(boolean isRestore) {
if (!isRestore) {
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.403186, -0.126446), 10));
}
// Shared object managers - used to support multiple layer types on the map simultaneously
MarkerManager markerManager = new MarkerManager(getMap());
GroundOverlayManager groundOverlayManager = new GroundOverlayManager(getMap());
PolygonManager polygonManager = new PolygonManager(getMap());
PolylineManager polylineManager = new PolylineManager(getMap());
// Add clustering
ClusterManager<MyItem> clusterManager = new ClusterManager<>(this, getMap(), markerManager);
getMap().setOnCameraIdleListener(clusterManager);
addClusterItems(clusterManager);
// Add GeoJSON from resource
try {
// GeoJSON polyline
GeoJsonLayer geoJsonLineLayer = new GeoJsonLayer(getMap(), R.raw.south_london_line_geojson, this, markerManager, polygonManager, polylineManager, groundOverlayManager);
// Make the line red
GeoJsonLineStringStyle geoJsonLineStringStyle = new GeoJsonLineStringStyle();
geoJsonLineStringStyle.setColor(Color.RED);
for (GeoJsonFeature f : geoJsonLineLayer.getFeatures()) {
f.setLineStringStyle(geoJsonLineStringStyle);
}
geoJsonLineLayer.addLayerToMap();
geoJsonLineLayer.setOnFeatureClickListener((GeoJsonLayer.GeoJsonOnFeatureClickListener) feature -> Toast.makeText(MultiLayerDemoActivity.this, "GeoJSON polyline clicked: " + feature.getProperty("title"), Toast.LENGTH_SHORT).show());
// GeoJSON polygon
GeoJsonLayer geoJsonPolygonLayer = new GeoJsonLayer(getMap(), R.raw.south_london_square_geojson, this, markerManager, polygonManager, polylineManager, groundOverlayManager);
// Fill it with red
GeoJsonPolygonStyle geoJsonPolygonStyle = new GeoJsonPolygonStyle();
geoJsonPolygonStyle.setFillColor(Color.RED);
for (GeoJsonFeature f : geoJsonPolygonLayer.getFeatures()) {
f.setPolygonStyle(geoJsonPolygonStyle);
}
geoJsonPolygonLayer.addLayerToMap();
geoJsonPolygonLayer.setOnFeatureClickListener((GeoJsonLayer.GeoJsonOnFeatureClickListener) feature -> Toast.makeText(MultiLayerDemoActivity.this, "GeoJSON polygon clicked: " + feature.getProperty("title"), Toast.LENGTH_SHORT).show());
} catch (IOException e) {
Log.e(TAG, "GeoJSON file could not be read");
} catch (JSONException e) {
Log.e(TAG, "GeoJSON file could not be converted to a JSONObject");
}
// Add KMLs from resources
try {
// KML Polyline
KmlLayer kmlPolylineLayer = new KmlLayer(getMap(), R.raw.south_london_line_kml, this, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
kmlPolylineLayer.addLayerToMap();
kmlPolylineLayer.setOnFeatureClickListener(feature -> Toast.makeText(MultiLayerDemoActivity.this, "KML polyline clicked: " + feature.getProperty("name"), Toast.LENGTH_SHORT).show());
// KML Polygon
KmlLayer kmlPolygonLayer = new KmlLayer(getMap(), R.raw.south_london_square_kml, this, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
kmlPolygonLayer.addLayerToMap();
kmlPolygonLayer.setOnFeatureClickListener(feature -> Toast.makeText(MultiLayerDemoActivity.this, "KML polygon clicked: " + feature.getProperty("name"), Toast.LENGTH_SHORT).show());
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Unclustered marker - instead of adding to the map directly, use the MarkerManager
MarkerManager.Collection markerCollection = markerManager.newCollection();
markerCollection.addMarker(new MarkerOptions().position(new LatLng(51.150000, -0.150032)).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)).title("Unclustered marker"));
markerCollection.setOnMarkerClickListener(marker -> {
Toast.makeText(MultiLayerDemoActivity.this, "Marker clicked: " + marker.getTitle(), Toast.LENGTH_SHORT).show();
return false;
});
}
Aggregations