Marker Clustering
El módulo android-marker-clustering proporciona agrupación automática de marcadores para MapConductor.
Agrupa los marcadores cercanos en clústeres al alejar el zoom, y los expande de vuelta en marcadores individuales al acercar el zoom.
Funciona con cualquier proveedor de mapas (Google Maps, MapLibre, Mapbox, ArcGIS, HERE, etc.).
Installation
Section titled “Installation”dependencies { implementation(platform("com.mapconductor:mapconductor-bom:1.1.3")) implementation("com.mapconductor:core") implementation("com.mapconductor:marker-clustering")
// Choose your map provider implementation("com.mapconductor:for-googlemaps")}Basic Usage
Section titled “Basic Usage”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 for your provider (e.g.Markerfor Google Maps,Symbolfor MapLibre).
Configuring Cluster Behavior
Section titled “Configuring Cluster Behavior”Usa MarkerClusterGroupState para configurar el comportamiento del clúster:
val clusterState = remember { MarkerClusterGroupState<ActualMarker>( clusterRadiusPx = 50.0, minClusterSize = 2, onClusterClick = { cluster -> // handle cluster tap }, )}
XxxMapView(...) { MarkerClusterGroup( state = clusterState, markers = markerStates, )}Custom Cluster Icon
Section titled “Custom Cluster Icon”Provide a clusterIconProvider lambda 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, ) }, )}Extra Content Inside a Cluster Group
Section titled “Extra Content Inside a Cluster Group”Agrega overlays adicionales junto a los marcadores agrupados usando el lambda content:
XxxMapView(...) { MarkerClusterGroup( state = clusterState, markers = markerStates, ) { // Additional composables rendered alongside the cluster group Circle(circleState) }}API Reference
Section titled “API Reference”MarkerClusterGroupState
Section titled “MarkerClusterGroupState”| 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 |