---
title: "MaplibreClusterLayer"
description: "Point clustering layer that automatically renders clustered circles, count labels, and individual points from a GeoJSON cluster source. Clicking a cluster expands it."
canonical_url: "https://maplibre.mhaibaraai.cn/en/docs/layers/cluster"
---
# MaplibreClusterLayer

> Point clustering layer that automatically renders clustered circles, count labels, and individual points from a GeoJSON cluster source. Clicking a cluster expands it.

## Introduction

`MaplibreClusterLayer` automatically clusters large point datasets. Internally it uses a cluster-enabled GeoJSON source to render three layers: cluster circles, count labels, and unclustered points. Clicking a cluster zooms to the expand level by default (`autoExpand`), and emits `clusterClick` / `pointClick` events.

## Usage

Pass in point data and clusters are handled automatically. Click a cluster to expand it:

```vue [ClusterLayerExample.vue]
<script setup lang="ts">
import type { FeatureCollection } from 'geojson'

const data: FeatureCollection = {
  type: 'FeatureCollection',
  features: Array.from({ length: 150 }, (_, i) => ({
    type: 'Feature',
    properties: {},
    geometry: {
      type: 'Point',
      coordinates: [116.0 + ((i * 37) % 100) / 125, 39.7 + ((i * 53) % 100) / 167]
    }
  }))
}
</script>

<template>
  <div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
    <MaplibreMap :options="{ style: 'https://tiles.openfreemap.org/styles/positron', center: [116.4, 39.9], zoom: 9 }">
      <!-- 自动聚合：点击聚合圆放大展开，散点单独渲染 -->
      <MaplibreClusterLayer :data="data" />
    </MaplibreMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MaplibreClusterLayer component
 */
interface MaplibreClusterLayerProps {
  /**
   * 点要素数据（GeoJSON 或其 URL）
   */
  data: string | GeoJSON.Point | GeoJSON.MultiPoint | GeoJSON.LineString | GeoJSON.MultiLineString | GeoJSON.Polygon | GeoJSON.MultiPolygon | GeoJSON.GeometryCollection<GeoJSON.Geometry> | GeoJSON.Feature<GeoJSON.Geometry, GeoJSON.GeoJsonProperties> | GeoJSON.FeatureCollection<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>;
  /**
   * source 与图层 id 前缀；省略时自动生成，变更需配合 `:key` 重建
   */
  sourceId?: string | undefined;
  /**
   * 聚合半径（像素）
   * @default 50
   */
  clusterRadius?: number | undefined;
  /**
   * 超过该缩放级别不再聚合
   * @default 14
   */
  clusterMaxZoom?: number | undefined;
  /**
   * 覆盖聚合圆 paint
   */
  clusterPaint?: PropBag | undefined;
  /**
   * 覆盖计数文字 layout
   */
  countLayout?: PropBag | undefined;
  /**
   * 覆盖计数文字 paint
   */
  countPaint?: PropBag | undefined;
  /**
   * 覆盖散点 paint
   */
  pointPaint?: PropBag | undefined;
  /**
   * 点击聚合圆自动放大到展开级别
   * @default true
   */
  autoExpand?: boolean | undefined;
  /**
   * 插入到该图层之前
   */
  beforeId?: string | undefined;
}
```

### Emits

```ts
/**
 * Emitted events for the MaplibreClusterLayer component
 */
interface MaplibreClusterLayerEmits {
  clusterClick: (payload: [payload: { clusterId: number; coordinates: [number, number]; expansionZoom: number; }]) => void;
  pointClick: (payload: [feature: MapGeoJSONFeature]) => void;
}
```

## Changelog

See commit history for [src/runtime/components/layers/ClusterLayer.vue](https://github.com/mhaibaraai/movk-maplibre/commits/main/src/runtime/components/layers/ClusterLayer.vue).


## Sitemap

See the full [sitemap](https://maplibre.mhaibaraai.cn/sitemap.md) for all pages.
