Class ClusterManager<T extends ClusterItem>
- java.lang.Object
-
- com.google.maps.android.clustering.ClusterManager<T>
-
- All Implemented Interfaces:
com.google.android.gms.maps.GoogleMap.OnCameraIdleListener
,com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener
,com.google.android.gms.maps.GoogleMap.OnMarkerClickListener
public class ClusterManager<T extends ClusterItem> extends java.lang.Object implements com.google.android.gms.maps.GoogleMap.OnCameraIdleListener, com.google.android.gms.maps.GoogleMap.OnMarkerClickListener, com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener
Groups many items on a map based on zoom level.ClusterManager should be added to the map as an:
GoogleMap.OnCameraIdleListener
GoogleMap.OnMarkerClickListener
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ClusterManager.OnClusterClickListener<T extends ClusterItem>
Called when a Cluster is clicked.static interface
ClusterManager.OnClusterInfoWindowClickListener<T extends ClusterItem>
Called when a Cluster's Info Window is clicked.static interface
ClusterManager.OnClusterInfoWindowLongClickListener<T extends ClusterItem>
Called when a Cluster's Info Window is long clicked.static interface
ClusterManager.OnClusterItemClickListener<T extends ClusterItem>
Called when an individual ClusterItem is clicked.static interface
ClusterManager.OnClusterItemInfoWindowClickListener<T extends ClusterItem>
Called when an individual ClusterItem's Info Window is clicked.static interface
ClusterManager.OnClusterItemInfoWindowLongClickListener<T extends ClusterItem>
Called when an individual ClusterItem's Info Window is long clicked.
-
Constructor Summary
Constructors Constructor Description ClusterManager(android.content.Context context, com.google.android.gms.maps.GoogleMap map)
ClusterManager(android.content.Context context, com.google.android.gms.maps.GoogleMap map, MarkerManager markerManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addItem(T myItem)
Adds an item to a cluster.boolean
addItems(java.util.Collection<T> items)
Adds items to clusters.void
clearItems()
Removes all items from the cluster manager.void
cluster()
Force a re-cluster on the map.Algorithm<T>
getAlgorithm()
MarkerManager.Collection
getClusterMarkerCollection()
MarkerManager.Collection
getMarkerCollection()
MarkerManager
getMarkerManager()
ClusterRenderer<T>
getRenderer()
void
onCameraIdle()
Might re-cluster.void
onInfoWindowClick(com.google.android.gms.maps.model.Marker marker)
boolean
onMarkerClick(com.google.android.gms.maps.model.Marker marker)
boolean
removeItem(T item)
Removes an item from clusters.boolean
removeItems(java.util.Collection<T> items)
Removes items from clusters.void
setAlgorithm(Algorithm<T> algorithm)
void
setAlgorithm(ScreenBasedAlgorithm<T> algorithm)
void
setAnimation(boolean animate)
void
setOnClusterClickListener(ClusterManager.OnClusterClickListener<T> listener)
Sets a callback that's invoked when a Cluster is tapped.void
setOnClusterInfoWindowClickListener(ClusterManager.OnClusterInfoWindowClickListener<T> listener)
Sets a callback that's invoked when a Cluster info window is tapped.void
setOnClusterInfoWindowLongClickListener(ClusterManager.OnClusterInfoWindowLongClickListener<T> listener)
Sets a callback that's invoked when a Cluster info window is long-pressed.void
setOnClusterItemClickListener(ClusterManager.OnClusterItemClickListener<T> listener)
Sets a callback that's invoked when an individual ClusterItem is tapped.void
setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItemInfoWindowClickListener<T> listener)
Sets a callback that's invoked when an individual ClusterItem's Info Window is tapped.void
setOnClusterItemInfoWindowLongClickListener(ClusterManager.OnClusterItemInfoWindowLongClickListener<T> listener)
Sets a callback that's invoked when an individual ClusterItem's Info Window is long-pressed.void
setRenderer(ClusterRenderer<T> renderer)
boolean
updateItem(T item)
Updates an item in clusters.
-
-
-
Constructor Detail
-
ClusterManager
public ClusterManager(android.content.Context context, com.google.android.gms.maps.GoogleMap map)
-
ClusterManager
public ClusterManager(android.content.Context context, com.google.android.gms.maps.GoogleMap map, MarkerManager markerManager)
-
-
Method Detail
-
getMarkerCollection
public MarkerManager.Collection getMarkerCollection()
-
getClusterMarkerCollection
public MarkerManager.Collection getClusterMarkerCollection()
-
getMarkerManager
public MarkerManager getMarkerManager()
-
setRenderer
public void setRenderer(ClusterRenderer<T> renderer)
-
setAlgorithm
public void setAlgorithm(ScreenBasedAlgorithm<T> algorithm)
-
setAnimation
public void setAnimation(boolean animate)
-
getRenderer
public ClusterRenderer<T> getRenderer()
-
clearItems
public void clearItems()
Removes all items from the cluster manager. After calling this method you must invokecluster()
for the map to be cleared.
-
addItems
public boolean addItems(java.util.Collection<T> items)
Adds items to clusters. After calling this method you must invokecluster()
for the state of the clusters to be updated on the map.- Parameters:
items
- items to add to clusters- Returns:
- true if the cluster manager contents changed as a result of the call
-
addItem
public boolean addItem(T myItem)
Adds an item to a cluster. After calling this method you must invokecluster()
for the state of the clusters to be updated on the map.- Parameters:
myItem
- item to add to clusters- Returns:
- true if the cluster manager contents changed as a result of the call
-
removeItems
public boolean removeItems(java.util.Collection<T> items)
Removes items from clusters. After calling this method you must invokecluster()
for the state of the clusters to be updated on the map.- Parameters:
items
- items to remove from clusters- Returns:
- true if the cluster manager contents changed as a result of the call
-
removeItem
public boolean removeItem(T item)
Removes an item from clusters. After calling this method you must invokecluster()
for the state of the clusters to be updated on the map.- Parameters:
item
- item to remove from clusters- Returns:
- true if the item was removed from the cluster manager as a result of this call
-
updateItem
public boolean updateItem(T item)
Updates an item in clusters. After calling this method you must invokecluster()
for the state of the clusters to be updated on the map.- Parameters:
item
- item to update in clusters- Returns:
- true if the item was updated in the cluster manager, false if the item is not contained within the cluster manager and the cluster manager contents are unchanged
-
cluster
public void cluster()
Force a re-cluster on the map. You should call this after adding, removing, updating, or clearing item(s).
-
onCameraIdle
public void onCameraIdle()
Might re-cluster.- Specified by:
onCameraIdle
in interfacecom.google.android.gms.maps.GoogleMap.OnCameraIdleListener
-
onMarkerClick
public boolean onMarkerClick(@NonNull com.google.android.gms.maps.model.Marker marker)
- Specified by:
onMarkerClick
in interfacecom.google.android.gms.maps.GoogleMap.OnMarkerClickListener
-
onInfoWindowClick
public void onInfoWindowClick(@NonNull com.google.android.gms.maps.model.Marker marker)
- Specified by:
onInfoWindowClick
in interfacecom.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener
-
setOnClusterClickListener
public void setOnClusterClickListener(ClusterManager.OnClusterClickListener<T> listener)
Sets a callback that's invoked when a Cluster is tapped. Note: For this listener to function, the ClusterManager must be added as a click listener to the map.
-
setOnClusterInfoWindowClickListener
public void setOnClusterInfoWindowClickListener(ClusterManager.OnClusterInfoWindowClickListener<T> listener)
Sets a callback that's invoked when a Cluster info window is tapped. Note: For this listener to function, the ClusterManager must be added as a info window click listener to the map.
-
setOnClusterInfoWindowLongClickListener
public void setOnClusterInfoWindowLongClickListener(ClusterManager.OnClusterInfoWindowLongClickListener<T> listener)
Sets a callback that's invoked when a Cluster info window is long-pressed. Note: For this listener to function, the ClusterManager must be added as a info window click listener to the map.
-
setOnClusterItemClickListener
public void setOnClusterItemClickListener(ClusterManager.OnClusterItemClickListener<T> listener)
Sets a callback that's invoked when an individual ClusterItem is tapped. Note: For this listener to function, the ClusterManager must be added as a click listener to the map.
-
setOnClusterItemInfoWindowClickListener
public void setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItemInfoWindowClickListener<T> listener)
Sets a callback that's invoked when an individual ClusterItem's Info Window is tapped. Note: For this listener to function, the ClusterManager must be added as a info window click listener to the map.
-
setOnClusterItemInfoWindowLongClickListener
public void setOnClusterItemInfoWindowLongClickListener(ClusterManager.OnClusterItemInfoWindowLongClickListener<T> listener)
Sets a callback that's invoked when an individual ClusterItem's Info Window is long-pressed. Note: For this listener to function, the ClusterManager must be added as a info window click listener to the map.
-
-