@@ -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,34 @@ 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+
19+ let color = 'blue' ;
20+ if ( childCount > 10 ) {
21+ color = 'red' ;
22+ }
23+
24+ return L . divIcon ( {
25+ html : `
26+ <div style="
27+ background-color: ${ color } ;
28+ border-radius: 50%;
29+ color: white;
30+ text-align: center;
31+ line-height: 40px;
32+ width: 40px;
33+ height: 40px;
34+ box-shadow: 0 4px 10px ${ color } ;
35+ ">
36+ ${ childCount }
37+ </div>` ,
38+ className : 'custom-cluster-icon' ,
39+ iconSize : [ 40 , 40 ]
40+ } ) ;
41+ } ,
42+ } ) ;
1443
1544 function onEachFeature ( feature , layer ) {
1645 let content = `<h3>Perceptual model of <strong>${ feature . properties . location . long_name } </strong></h3>`
@@ -27,28 +56,28 @@ export const useMapStore = defineStore('map', () => {
2756
2857
2958 const props = feature . properties ;
30- const note = "This is not a public access article , see the url. " ;
59+ const note = "Not open access, see article for " ;
3160 if ( props . model_type . name === 'Text model' ) {
3261 if ( props . citation . attribution == "Not open-access" ) {
33- content += note
62+ content += note + "text"
3463 } else {
3564 content += `<p>${ feature . properties . textmodel_snipped } </p>`
3665 }
3766
3867 if ( ( ( props . textmodel_section_name && props . textmodel_section_name != "N/A" )
3968 || ( props . textmodel_section_number && props . textmodel_section_number != "N/A" ) )
4069 && ( props . textmodel_page_number && props . textmodel_page_number != "N/A" ) ) {
41- content += `<h5> ${ props . textmodel_section_number != "N/A" ? ( "Section " + props . textmodel_section_number ) + ' ' : '' } ${ props . textmodel_section_name != 'N/A' ? props . textmodel_section_name + ' ' : '' } ${ props . textmodel_page_number != "N/A" ? ( "(pg " + props . textmodel_page_number ) + ')' : '' } </h5 >`
70+ content += `<p class="mt-1"><b>Section ${ props . textmodel_section_number != "N/A" ? ( props . textmodel_section_number ) + '</b> ' : '</b> ' } ${ props . textmodel_section_name != 'N/A' ? props . textmodel_section_name + ' ' : '' } ${ props . textmodel_page_number != "N/A" ? ( "(Page " + props . textmodel_page_number ) + ')' : '' } </p >`
4271 }
4372 } else {
4473 if ( props . citation . attribution == "Not open-access" ) {
45- content += note
74+ content += note + "figure"
4675 } else {
4776 content += `<img src="${ feature . properties . figure_url } " style="width: 100%">`
4877 }
4978
5079 if ( props . figure_caption && props . figure_caption != "N/A" ) {
51- content += `<h5> ${ props . figure_num != "N/A" ? ( "Figure " + props . figure_num + ' : ' ) : '' } ${ props . figure_caption } </h5 >`
80+ content += `<p class="mt-1"><b>Figure ${ props . figure_num != "N/A" ? ( props . figure_num + ' :</b> ' ) : '</b> ' } ${ props . figure_caption } </p >`
5281 }
5382 }
5483 content += '<hr><br>'
@@ -118,7 +147,8 @@ export const useMapStore = defineStore('map', () => {
118147 } ,
119148 pointToLayer : pointToLayer
120149 } )
121- layerGroup . value . addLayer ( modelFeatures . value )
150+ markerClusterGroup . addLayer ( modelFeatures . value ) ; // Add features to the cluster group
151+ layerGroup . value . addLayer ( markerClusterGroup ) ;
122152 }
123153
124154 function filterFeatures ( filterFunction ) {
@@ -138,7 +168,8 @@ export const useMapStore = defineStore('map', () => {
138168 } )
139169
140170 // add filtered features
141- layerGroup . value . addLayer ( modelFeatures . value )
171+ markerClusterGroup . addLayer ( modelFeatures . value ) ;
172+ layerGroup . value . addLayer ( markerClusterGroup ) ;
142173 }
143174
144175 function resetFilter ( ) {
@@ -148,7 +179,8 @@ export const useMapStore = defineStore('map', () => {
148179 onEachFeature ( feature , layer )
149180 }
150181 } )
151- layerGroup . value . addLayer ( modelFeatures . value )
182+ markerClusterGroup . addLayer ( modelFeatures . value ) ;
183+ layerGroup . value . addLayer ( markerClusterGroup ) ;
152184 }
153185
154186 return {
0 commit comments