mapboxExpandCluster() is a utility that enhances the default Mapbox cluster expansion behavior. While the default behavior only zooms enough to break up a cluster, this function zooms in as far as possible while ensuring all markers within the cluster remain visible in the viewport.
Behavior for small maps (width < 640px):
This is the fallback behavior, since it most likely returns the same result as the default zoom.
getClusterExpansionZoom() method of the Supercluster instance. (See Supercluster API)flyTo() method of the Map instance.Behavior for larger maps:
This is the intended behavior.
getLeaves() method of the Supercluster instance. (See Supercluster API)<template>
<button @click="mapboxExpandCluster(map, supercluster, clusterFeature)">
Expand Cluster
</button>
</template>
declare function mapboxExpandCluster(
map: Map | null,
supercluster: Supercluster,
feature: Feature<Point, { cluster_id: number }>,
options: EasingOptions = { padding: 100 },
): void;