Class ClusterManager<T extends ClusterItem>

  • 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
    • 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

      • setAlgorithm

        public void setAlgorithm​(Algorithm<T> algorithm)
      • setAnimation

        public void setAnimation​(boolean animate)
      • getAlgorithm

        public Algorithm<T> getAlgorithm()
      • clearItems

        public void clearItems()
        Removes all items from the cluster manager. After calling this method you must invoke cluster() 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 invoke cluster() 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 invoke cluster() 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 invoke cluster() 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 invoke cluster() 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 invoke cluster() 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 interface com.google.android.gms.maps.GoogleMap.OnCameraIdleListener
      • onMarkerClick

        public boolean onMarkerClick​(@NonNull
                                     com.google.android.gms.maps.model.Marker marker)
        Specified by:
        onMarkerClick in interface com.google.android.gms.maps.GoogleMap.OnMarkerClickListener
      • onInfoWindowClick

        public void onInfoWindowClick​(@NonNull
                                      com.google.android.gms.maps.model.Marker marker)
        Specified by:
        onInfoWindowClick in interface com.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.