MapConductor Marker Clustering provides a marker clustering strategy for the MapConductor SDK. It automatically groups nearby markers into clusters as you zoom out, and expands them back into individual markers as you zoom in. It works with any map implementation (Google Maps, MapLibre, Mapbox, ArcGIS, HERE, etc.).
https://docs-android.mapconductor.com/setup/
Wrap your markers with MarkerClusterGroup inside any XxxMapView content block:
val markerStates: List<MarkerState> = remember { buildMarkerList() }
XxxMapView(...) {
MarkerClusterGroup<ActualMarker>(
state = remember { MarkerClusterGroupState() },
markers = markerStates,
)
}Replace
ActualMarkerwith the map-specific marker type of the implementation you are using (e.g.Markerfor Google Maps,Symbolfor MapLibre).
Use MarkerClusterGroupState to configure clustering behaviour:
val clusterState = remember {
MarkerClusterGroupState<ActualMarker>(
clusterRadiusPx = 50.0,
minClusterSize = 2,
onClusterClick = { cluster ->
// handle cluster tap
},
)
}
XxxMapView(...) {
MarkerClusterGroup(
state = clusterState,
markers = markerStates,
)
}Provide a lambda to clusterIconProvider to render a custom icon for each cluster:
val clusterState = remember {
MarkerClusterGroupState<ActualMarker>(
clusterIconProvider = { count ->
DefaultMarkerIcon(
fillColor = Color.Blue,
label = count.toString(),
labelTextColor = Color.White,
)
},
)
}Add extra overlays alongside the clustered markers using the content lambda:
XxxMapView(...) {
MarkerClusterGroup(
state = clusterState,
markers = markerStates,
) {
// additional composables rendered alongside the cluster group
Circle(circleState)
}
}| Property | Type | Default | Description |
|---|---|---|---|
clusterRadiusPx |
Double |
50.0 |
Pixel radius within which markers are clustered |
minClusterSize |
Int |
2 |
Minimum number of markers to form a cluster |
expandMargin |
Double |
— | Extra margin when expanding clusters |
clusterIconProvider |
(Int) -> MarkerIconInterface |
Default circle badge | Returns an icon for the given cluster size |
onClusterClick |
((MarkerCluster) -> Unit)? |
null |
Called when a cluster marker is tapped |
enableZoomAnimation |
Boolean |
false |
Animate markers on zoom change |
enablePanAnimation |
Boolean |
false |
Animate markers on pan |
zoomAnimationDurationMillis |
Long |
— | Duration of zoom animation |
cameraIdleDebounceMillis |
Long |
— | Debounce delay before re-clustering after camera stops |