ClusterManager

Groups nearby markers into clusters that show their count. Clusters are computed again when the map stops at a new integer zoom level.

The manager is the map's camera idle and marker click listener:

val clusterManager = ClusterManager<Shop>(context, mapView)
mapView.setOnCameraIdleListener(clusterManager)
mapView.setOnMarkerClickListener(clusterManager)
clusterManager.addItems(shops)
clusterManager.cluster()

Tapping a cluster zooms in to show its items, unless an OnClusterClickListener returns true.

Parameters

context

Context for the screen density

map

The map to draw the markers on

Type Parameters

T

The type of the items

Constructors

Link copied to clipboard
constructor(context: Context, map: OpenMapView)

Types

Link copied to clipboard

Provides the icon of a cluster marker, e.g. to draw clusters in your own style.

Link copied to clipboard

Provides the icon of an item's marker, or null for the default marker.

Link copied to clipboard

Called when a cluster marker is tapped.

Link copied to clipboard

Called when the marker of a single item is tapped.

Properties

Link copied to clipboard

Draws the cluster markers, or null for circles with the count.

Link copied to clipboard

Draws the item markers, or null for the default marker.

Link copied to clipboard

How close items must be to share a cluster, in dp on the screen. Default is 100.

Link copied to clipboard

The smallest group drawn as a cluster; smaller groups show their items' markers. Default is 4.

Functions

Link copied to clipboard
fun addItem(item: T): Boolean

Adds an item. Call cluster to show it.

Link copied to clipboard

Adds items. Call cluster to show them.

Link copied to clipboard

Removes all items. Call cluster to update the map.

Link copied to clipboard
fun cluster()

Computes the clusters for the current zoom level and draws their markers.

Link copied to clipboard

Returns the items of the manager.

Link copied to clipboard
open override fun onCameraIdle()

Clusters again when the camera stops at another integer zoom level.

Link copied to clipboard
open override fun onMarkerClick(marker: Marker): Boolean

Handles taps on the manager's markers; returns false for other markers.

Link copied to clipboard
fun removeItem(item: T): Boolean

Removes an item. Call cluster to update the map.

Link copied to clipboard

Removes items. Call cluster to update the map.

Link copied to clipboard

Sets a listener called when a cluster is tapped.

Link copied to clipboard

Sets a listener called when the marker of a single item is tapped.