MapboxClusterMarker is a component that renders a marker representing a cluster of points on a Mapbox map. It provides functionality to expand clusters when clicked, revealing the individual points within the cluster.
Key features:
The component is typically used within a MapboxSupercluster component to render cluster markers.
<template>
<MapboxMap>
<MapboxSupercluster :features="points">
<template #cluster="{ id, feature }">
<MapboxClusterMarker
:id="id"
:feature="feature"
:options="{ anchor: 'center' }"
>
<span class="cluster-count">
{{ feature.properties.point_count }}
</span>
</MapboxClusterMarker>
</template>
</MapboxSupercluster>
</MapboxMap>
</template>
| Prop | Default | Type |
|---|---|---|
id* | stringUnique identifier for the cluster marker | |
options | MarkerOptionsMapbox marker options for customizing appearance | |
feature* | Feature<Point, any>GeoJSON feature representing the cluster | |
easingOptions | EasingOptionsOptions for controlling the animation when expanding clusters |
| Exposed | Type |
|---|---|
expandCluster() | (options?: EasingOptions) => voidExpands the cluster to reveal individual points (also the default click event) |
The component provides a context that can be injected by child components:
export type MapboxClusterMarkerContext = {
clusterMarker: Ref<Marker | null>;
};
export const [injectMapboxClusterMarkerContext, provideMapboxClusterMarkerContext]
= createContext<MapboxClusterMarkerContext>("MapboxClusterMarker");
<template>
<MapboxMap>
<MapboxSupercluster :features="points">
<template #cluster="{ id, feature }">
<MapboxClusterMarker
:id="id"
:feature="feature"
:options="{
anchor: 'center',
color: '#ff0000'
}"
@click="handleClusterClick"
>
<div class="custom-cluster">
<span class="count">{{ feature.properties.point_count }}</span>
<span class="label">Points</span>
</div>
</MapboxClusterMarker>
</template>
</MapboxSupercluster>
</MapboxMap>
</template>
<script setup lang="ts">
function handleClusterClick() {
// Handle cluster click event
}
</script>
<style>
.custom-cluster {
background: white;
border-radius: 50%;
padding: 8px;
text-align: center;
}
.count {
font-weight: bold;
font-size: 16px;
}
.label {
font-size: 12px;
color: #666;
}
</style>