mapboxFindExpansionZoomForFeature() is a utility function that helps determine the exact zoom level at which a specific feature will become visible as an individual point rather than being part of a cluster. This is particularly useful when you want to smoothly zoom to a specific feature that might be contained within a cluster.
Behavior for unclustered features:
The function works by recursively traversing the cluster hierarchy:
<script setup lang="ts">
import { mapboxFindExpansionZoomForFeature } from '@nobears-front-end/nuxt-mapbox';
import type { Feature, Point } from "geojson";
import Supercluster from "supercluster";
const supercluster = new Supercluster({ ... });
const features = [
{ type: 'Feature', id: 'cluster1', properties: { cluster: true } },
{ type: 'Feature', id: 'point1', properties: { cluster: false } }
];
const zoom = mapboxFindExpansionZoomForFeature(supercluster, features, 'point1', 10);
</script>
declare function mapboxFindExpansionZoomForFeature(
index: Supercluster,
features: Array<Feature<Point, { cluster?: boolean }>>,
id: string | number | undefined,
currentZoom: number,
): number;