The Mapbox component is a high-level wrapper that combines MapboxMap and MapboxSupercluster components to provide a complete Mapbox GL JS integration with built-in clustering support. It handles the initialization of the map and manages the clustering of markers automatically.
<template>
<Mapbox
:features="features"
:initialize-with="mapOptions"
@loaded="onMapLoaded"
>
<!-- Custom marker template -->
<template #marker="{ id, feature }">
<MapboxMarker
:id="id"
:feature="feature"
class="custom-marker"
>
{{ feature.properties.name }}
</MapboxMarker>
</template>
<!-- Custom cluster marker template -->
<template #cluster="{ id, feature }">
<MapboxClusterMarker
:id="id"
:feature="feature"
class="custom-cluster"
>
{{ feature.properties.point_count }}
</MapboxClusterMarker>
</template>
</Mapbox>
</template>
<script setup lang="ts">
const features = ref([
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-74.5, 40]
},
properties: {
name: 'Location 1'
}
}
]);
const mapOptions = {
zoom: 12,
center: [-74.5, 40]
};
const onMapLoaded = (map) => {
console.log('Map loaded:', map);
};
</script>
| Prop | Default | Type |
|---|---|---|
clusterMarkerClass | stringCSS class to apply to individual markers | |
clusterClusterMarkerClass | stringCSS class to apply to cluster markers |
| Emit | Payload |
|---|---|
loaded | (map: Map) => voidEmitted when the map is fully loaded |
| Slot | Payload |
|---|---|
marker | { id: string, feature: Feature }Custom template for individual markers |
cluster | { id: string, feature: Feature }Custom template for cluster markers |
loader | {}Custom loading state template |
| Exposed | Type |
|---|---|
focusFeatures() | (features: MapboxFeatures) => voidFocus the map on specific features |