@@ -3,13 +3,42 @@ 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 )
910 const layerGroup = ref ( null )
1011 const modelFeatures = ref ( { } )
1112 const perceptualModelsGeojson = ref ( [ ] )
1213 const mapLoaded = ref ( false )
14+ const markerClusterGroup = L . markerClusterGroup ( {
15+ iconCreateFunction : ( cluster ) => {
16+ const childCount = cluster . getChildCount ( ) ;
17+
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+ } ) ;
1342
1443 function onEachFeature ( feature , layer ) {
1544 let content = `<h3>Perceptual model of <strong>${ feature . properties . location . long_name } </strong></h3>`
@@ -117,7 +146,8 @@ export const useMapStore = defineStore('map', () => {
117146 } ,
118147 pointToLayer : pointToLayer
119148 } )
120- layerGroup . value . addLayer ( modelFeatures . value )
149+ markerClusterGroup . addLayer ( modelFeatures . value ) ; // Add features to the cluster group
150+ layerGroup . value . addLayer ( markerClusterGroup ) ;
121151 }
122152
123153 function filterFeatures ( filterFunction ) {
@@ -135,7 +165,8 @@ export const useMapStore = defineStore('map', () => {
135165 pointToLayer : pointToLayer
136166 } )
137167 // add filtered features
138- layerGroup . value . addLayer ( modelFeatures . value )
168+ markerClusterGroup . addLayer ( modelFeatures . value ) ;
169+ layerGroup . value . addLayer ( markerClusterGroup ) ;
139170 }
140171
141172 function resetFilter ( ) {
@@ -145,7 +176,8 @@ export const useMapStore = defineStore('map', () => {
145176 onEachFeature ( feature , layer )
146177 }
147178 } )
148- layerGroup . value . addLayer ( modelFeatures . value )
179+ markerClusterGroup . addLayer ( modelFeatures . value ) ;
180+ layerGroup . value . addLayer ( markerClusterGroup ) ;
149181 }
150182
151183 return {
0 commit comments