Skip to content

🧩 LMarkerClusterGroup

Provides Beautiful Animated Marker Clustering functionality for Leaflet, a JS library for interactive maps.

🧪 Demo

vue
<script setup lang="ts">
import { LMap, LMarker, LTileLayer } from '@maxel01/vue-leaflet'
import { LMarkerClusterGroup } from '@maxel01/vue-leaflet-plugins'
import { LatLng, Map } from 'leaflet'
import { ref } from 'vue'

const markers = ref<LatLng[]>([])

function getRandomLatLng(map: Map) {
    const bounds = map.getBounds()
    const latSpan = bounds.getNorth() - bounds.getSouth()
    const lngSpan = bounds.getEast() - bounds.getWest()
    return new LatLng(
        bounds.getSouth() + latSpan * Math.random(),
        bounds.getWest() + lngSpan * Math.random()
    )
}

function populate(map: Map) {
    markers.value = Array.from({ length: 100 }, () => getRandomLatLng(map))
}
</script>

<template>
    <LMap :zoom="4" :center="[47.41322, -1.219482]" @ready="populate">
        <LTileLayer
            url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
            layer-type="base"
            name="OpenStreetMap"
        />
        <LMarkerClusterGroup>
            <LMarker
                v-for="(point, index) in markers"
                :key="index"
                :lat-lng="[point.lat, point.lng]"
            />
        </LMarkerClusterGroup>
    </LMap>
</template>

⚙️ Props

This component does not have any specific props.

Inherited props

from LayerProps
Prop nameDescriptionTypeReactiveDefaultRequired
paneBy default, the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).stringinitOnly-false
attributionString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.stringtrue-false
name-stringtrue-false
layerType-LayerTypetrue-false
visible-booleantrue-false
from ComponentProps
Prop nameDescriptionTypeReactiveDefaultRequired
optionsLeaflet options to pass to the component constructor.TinitOnly-false

🎯 Slots

NameDescription
default?

🧭 Exposes

NameTypeDescription
readyRef<boolean>Indicates whether the component and its underlying Leaflet object are fully initialized.
leafletObjectRef<MarkerClusterGroup | undefined>The underlying Leaflet instance. Can be used to directly interact with the Leaflet API (e.g. calling methods or accessing internal state).