use of com.google.maps.android.collections.MarkerManager 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;
});
}
use of com.google.maps.android.collections.MarkerManager in project ti.map by tidev.
the class TiUIMapView method onMapReady.
@Override
public void onMapReady(GoogleMap gMap) {
map = gMap;
if (proxy == null) {
return;
}
Activity activity = proxy.getActivity();
if (activity == null) {
return;
}
mMarkerManager = new MarkerManager(map);
mMarkerManager.newCollection(DEFAULT_COLLECTION_ID);
mMarkerManager.getCollection(DEFAULT_COLLECTION_ID).setOnMarkerClickListener(this);
collection = mMarkerManager.newCollection();
mClusterManager = new ClusterManager<TiMarker>(activity, map, mMarkerManager);
clusterRender = new TiClusterRenderer(activity, map, mClusterManager);
mClusterManager.setRenderer(clusterRender);
processMapProperties(proxy.getProperties());
processPreloadRoutes();
processPreloadPolygons();
processPreloadCircles();
processPreloadPolylines();
processOverlaysList();
map.setOnMarkerClickListener(mMarkerManager);
map.setOnMapClickListener(this);
if (!this.liteMode) {
map.setOnCameraIdleListener(this);
map.setOnCameraMoveStartedListener(this);
map.setOnCameraMoveListener(this);
}
collection.setOnMarkerDragListener(this);
map.setOnMapLongClickListener(this);
map.setOnMapLoadedCallback(this);
map.setOnMyLocationChangeListener(this);
collection.setInfoWindowAdapter(this);
collection.setOnInfoWindowClickListener(this);
collection.setOnMarkerClickListener(this);
mClusterManager.setOnClusterClickListener(this);
mClusterManager.setOnClusterItemClickListener(this);
MarkerManager.Collection markerCollection = mClusterManager.getMarkerCollection();
markerCollection.setInfoWindowAdapter(this);
markerCollection.setOnInfoWindowClickListener(this);
markerCollection.setOnMarkerDragListener(this);
((ViewProxy) proxy).clearPreloadObjects();
}
Aggregations