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.
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>
type MapboxClusterMarkerProps = {
/**
* Unique identifier for the cluster marker
*/
id: string;
/**
* Mapbox cluster marker options
* @see {@link mapboxgl.MarkerOptions|MarkerOptions}
*/
options?: MarkerOptions;
/**
* GeoJSON feature containing cluster marker coordinates
* @see {@link ClusterFeature|ClusterFeature}
*/
feature: ClusterFeature<any>;
/**
* Easing options for the cluster marker
*
* _Composed type of {@link mapboxgl.CameraOptions|CameraOptions} and {@link mapboxgl.AnimationOptions|AnimationOptions}._
* @see {@link mapboxgl.EasingOptions|EasingOptions}
*/
easingOptions?: EasingOptions;
/**
* The element or component this component should render as.
*
* Will prioritize components over elements when the name for both is the same.
* @defaultValue "button"
* @see {@link AsTag|AsTag}
* @see {@link Component|Component}
* @example
* ```vue
* <template>
* <MapboxMarker as="span" />
* </template>
* ```
*/
as?: MapboxMarkerProps["as"];
} & Pick<MapboxMarkerProps, "asChild">;
type MapboxClusterMarkerContext = {
/**
* The cluster Marker instance
* @see {@link mapboxgl.Marker|Marker}
* @see {@link https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker|Mapbox GL Docs - Marker}
*/
clusterMarker: Ref<Marker | null | undefined>;
};
| Prop | Default | Type |
|---|---|---|
id* | stringUnique identifier for the cluster marker | |
options | { anchor: 'top-left' } | MarkerOptionsMapbox cluster marker options |
feature* | ClusterFeature<any>GeoJSON feature containing cluster marker coordinates | |
easingOptions | EasingOptionsEasing options for the cluster marker | |
as | button | stringThe element or component this component should render as |
| Event | Payload |
|---|---|
click | () => expandCluster()Expanded the cluster to reveal individual points |
| Slot | Payload |
|---|---|
default | Content to render inside the cluster marker |
cluster-marker-count | Content to render inside the cluster marker count |
| Attribute | Value | Type |
|---|---|---|
data-type | mapbox-cluster-marker | string |
| Exposed | Type |
|---|---|
clusterMarker | Marker |
clusterMarkerElement | ComponentPublicInstanceThe cluster marker element instance |
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
| Context | Type |
|---|---|
clusterMarker | Ref<Marker | null>The cluster marker instance |
<script setup lang="ts">
const { clusterMarker } = injectMapboxClusterMarkerContext();
</script>
<template>
<div>{{ clusterMarker }}</div>
</template>