33Enhance MapLibre GL JS with fully interactive HTML-based clusters and markers.
44
55** Features:**
6- - 🧱 Renders native MapLibre GL JS clusters as HTML elements
7- - 🌀 Smart unfolded clusters (circle, hexagrid, grid) based on zoom level and item count
8- - 📌 Pin marker display on feature click
9- - 🔍 Interact with overlapping markers without needing to zoom in
10- - 🚫 Avoids the need to uncluster or zoom for interaction
6+ - 🧱 Renders MapLibre GL JS clusters as HTML elements.
7+ - 📌 Displays a pinned marker when a feature is clicked.
8+ - 🚫 Unfolded small clusters to avoid requiring zoom or manual ungrouping.
9+
10+ ** 3 Cluster States:**
11+ - Cluster Marker: A single marker representing a cluster, eg. displaying the number of features.
12+ - Unfolded Cluster: Displays individual features grouped from a small cluster or when at the highest zoom level.
13+ - Unclustered Features
14+
15+ ** Customization Callbacks:**
16+ - Custom function to render cluster.
17+ - Custom function to render individual markers.
18+ - Custom function to render unfolded cluster.
19+
1120---
1221## Demo
1322
@@ -19,7 +28,7 @@ Enhance MapLibre GL JS with fully interactive HTML-based clusters and markers.
1928Install @teritorio/maplibre-gl-teritorio-cluster with yarn
2029
2130``` bash
22- yarn add @teritorio/maplibre-gl-teritorio-cluster
31+ yarn add @teritorio/maplibre-gl-teritorio-cluster
2332```
2433
2534Or use it from CDN
@@ -30,7 +39,7 @@ Or use it from CDN
3039## Usage/Examples
3140
3241> [ !WARNING]
33- > Set your GeoJSON source with ` clusterMaxZoom: 22 ` in order to let the plugin handle cluster/ individual marker rendering across all zoom level
42+ > Set your GeoJSON source with ` clusterMaxZoom: 22 ` in order to let the plugin handle individual marker rendering at the highest zoom level.
3443
3544``` javascript
3645import { TeritorioCluster } from ' @teritorio/maplibre-gl-teritorio-cluster'
@@ -41,8 +50,7 @@ const map = new maplibregl.Map({
4150 container: ' map' ,
4251 style: {
4352 version: 8 ,
44- name: ' Empty Style' ,
45- metadata: { ' maputnik:renderer' : ' mlgljs' },
53+ name: ' MapLibre GL Teritorio Cluster' ,
4654 sources: {
4755 points: {
4856 type: ' geojson' ,
@@ -68,22 +76,22 @@ const map = new maplibregl.Map({
6876 },
6977 glyphs: ' https://orangemug.github.io/font-glyphs/glyphs/{fontstack}/{range}.pbf' ,
7078 layers: [],
71- id: ' muks8j3 '
79+ id: ' maplibre-gl-teritorio-cluster '
7280 }
7381})
7482
7583map .on (' load' , () => {
76- const teritorioLayer = new TeritorioCluster (
84+ const clusterLayer = new TeritorioCluster (
7785 ' teritorio-cluster-layer' ,
7886 ' points' ,
7987 options
8088 )
8189
8290 // Add the layer to map
83- map .addLayer (teritorioLayer )
91+ map .addLayer (clusterLayer )
8492
8593 // Subscribe to feature click event
86- teritorioLayer .addEventListener (' feature-click' , (event ) => {
94+ clusterLayer .addEventListener (' feature-click' , (event ) => {
8795 console .log (event .detail .selectedFeature )
8896 })
8997})
@@ -103,7 +111,7 @@ function pinMarkerRender(coords, offset) {}
103111#### Constructor
104112
105113``` js
106- const teritorioLayer = new TeritorioCluster (id, sourceId, options)
114+ const clusterLayer = new TeritorioCluster (id, sourceId, options)
107115```
108116
109117| Parameter | Type | Description |
@@ -118,10 +126,10 @@ const teritorioLayer = new TeritorioCluster(id, sourceId, options)
118126| -------------------------- | ----------------------------- | ---------------------------- | -------------------------------------------------------------- |
119127| ` clusterMaxZoom ` | ` number ` | ` 17 ` | Maximum zoom level where clusters are visible. |
120128| ` clusterMinZoom ` | ` number ` | ` 0 ` | Minimum zoom level where clustering starts. |
121- | ` clusterRender ` | ` (feature) => HTMLElement ` | ` clusterRenderDefault ` | Custom function to render cluster. |
129+ | ` clusterRender ` | ` (feature) => HTMLElement ` | ` clusterRenderDefault ` | Custom function to render cluster. |
122130| ` markerRender ` | ` (feature) => HTMLElement ` | ` markerRenderDefault ` | Custom function to render individual markers. |
123131| ` markerSize ` | ` number ` | ` 24 ` | Pixel size of rendered markers. |
124- | ` unfoldedClusterRender ` | ` (features) => HTMLElement[] ` | ` unfoldedClusterRenderSmart ` | Function to render unfolded cluster. |
132+ | ` unfoldedClusterRender ` | ` (features) => HTMLElement[] ` | ` unfoldedClusterRenderSmart ` | Custom function to render unfolded cluster. |
125133| ` unfoldedClusterMaxLeaves ` | ` number ` | ` 7 ` | Maximum number of features to show when a cluster is unfolded. |
126134| ` fitBoundsOptions ` | ` mapboxgl.FitBoundsOptions ` | ` { padding: 20 } ` | Options for [ fitBounds] ( https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#fitbounds ) method |
127135| ` initialFeature ` | ` GeoJSONFeature \| undefined ` | ` undefined ` | Feature to auto-select on load. |
@@ -130,7 +138,7 @@ const teritorioLayer = new TeritorioCluster(id, sourceId, options)
130138## Events
131139
132140``` js
133- teritorioLayer .addEventListener (' feature-click' , (event ) => {
141+ clusterLayer .addEventListener (' feature-click' , (event ) => {
134142 console .log (' Selected feature:' , event .detail .selectedFeature )
135143})
136144```
@@ -139,25 +147,25 @@ teritorioLayer.addEventListener('feature-click', (event) => {
139147Clone the project
140148
141149``` bash
142- git clone https://github.com/teritorio/maplibre-gl-teritorio-cluster.git
150+ git clone https://github.com/teritorio/maplibre-gl-teritorio-cluster.git
143151```
144152
145153Go to the project directory
146154
147155``` bash
148- cd maplibre-gl-teritorio-cluster
156+ cd maplibre-gl-teritorio-cluster
149157```
150158
151159Install dependencies
152160
153161``` bash
154- yarn install
162+ yarn install
155163```
156164
157165Start the server
158166
159167``` bash
160- yarn dev
168+ yarn dev
161169```
162170
163171## Contributing
@@ -169,6 +177,7 @@ See [`CONTRIBUTING.md`](CONTRIBUTING.md) for ways to get started.
169177## Authors
170178
171179- [ Teritorio] ( https://teritorio.fr )
180+
172181## License
173182
174183[ MIT] ( https://choosealicense.com/licenses/mit/ )
0 commit comments