@@ -3,6 +3,7 @@ import { ref } from 'vue'
33import { ENDPOINTS } from '@/constants'
44import L from 'leaflet'
55import 'leaflet-iconmaterial/dist/leaflet.icon-material'
6+ import 'leaflet.markercluster' ;
67
78export const useMapStore = defineStore ( 'map' , ( ) => {
89 const leaflet = ref ( null )
@@ -11,6 +12,33 @@ export const useMapStore = defineStore('map', () => {
1112 const perceptualModelsGeojson = ref ( [ ] )
1213 const mapLoaded = ref ( false )
1314 let currentFilteredData = ref ( [ ] )
15+ const markerClusterGroup = L . markerClusterGroup ( {
16+ iconCreateFunction : ( cluster ) => {
17+ const childCount = cluster . getChildCount ( ) ;
18+ let color = 'blue' ;
19+ if ( childCount > 10 ) {
20+ color = 'red' ;
21+ }
22+
23+ return L . divIcon ( {
24+ html : `
25+ <div style="
26+ background-color: ${ color } ;
27+ border-radius: 50%;
28+ color: white;
29+ text-align: center;
30+ line-height: 40px;
31+ width: 40px;
32+ height: 40px;
33+ box-shadow: 0 4px 10px ${ color } ;
34+ ">
35+ ${ childCount }
36+ </div>` ,
37+ className : 'custom-cluster-icon' ,
38+ iconSize : [ 40 , 40 ] ,
39+ } ) ;
40+ } ,
41+ } ) ;
1442
1543 function onEachFeature ( feature , layer ) {
1644 let content = `<h3>Perceptual model of <strong>${ feature . properties . location . long_name } </strong></h3>`
@@ -118,7 +146,8 @@ export const useMapStore = defineStore('map', () => {
118146 } ,
119147 pointToLayer : pointToLayer
120148 } )
121- layerGroup . value . addLayer ( modelFeatures . value )
149+ markerClusterGroup . addLayer ( modelFeatures . value ) ; // Add features to the cluster group
150+ layerGroup . value . addLayer ( markerClusterGroup ) ;
122151 }
123152
124153 function filterFeatures ( filterFunction ) {
@@ -138,7 +167,8 @@ export const useMapStore = defineStore('map', () => {
138167 } )
139168
140169 // add filtered features
141- layerGroup . value . addLayer ( modelFeatures . value )
170+ markerClusterGroup . addLayer ( modelFeatures . value ) ;
171+ layerGroup . value . addLayer ( markerClusterGroup ) ;
142172 }
143173
144174 function resetFilter ( ) {
@@ -148,7 +178,8 @@ export const useMapStore = defineStore('map', () => {
148178 onEachFeature ( feature , layer )
149179 }
150180 } )
151- layerGroup . value . addLayer ( modelFeatures . value )
181+ markerClusterGroup . addLayer ( modelFeatures . value ) ;
182+ layerGroup . value . addLayer ( markerClusterGroup ) ;
152183 }
153184
154185 return {
0 commit comments