// // Map // var map = L.map('map', { zoomControl: false, attributionControl: false }) // // Icons // doc : https://onestepcode.com/leaflet-markers-svg-icons/ // const mspIcon = L.divIcon({ html: ` `, className: "", iconSize: [48, 48], iconAnchor: [12, 40], }); const pharmacyIcon = L.divIcon({ html: ` `, className: "", iconSize: [48, 48], iconAnchor: [12, 40], }); // // Markers // const markersMSP = new L.MarkerClusterGroup({ chunkedLoading: true }); const markersPharmacy = new L.MarkerClusterGroup({ chunkedLoading: true }); export function updateLayers(layerMSPChecked, layerPharmacieChecked) { // MSP if (layerMSPChecked && !map.hasLayer(markersMSP)) { map.addLayer(markersMSP) } else if (!layerMSPChecked && map.hasLayer(markersMSP)) { map.removeLayer(markersMSP) } //Pharmacy if (layerPharmacieChecked && !map.hasLayer(markersPharmacy)) { map.addLayer(markersPharmacy) } else if (!layerPharmacieChecked && map.hasLayer(markersPharmacy)) { map.removeLayer(markersPharmacy) } } export function initMap(data, dataP4Pillon, columns, getName, displayInfo, layerMSPChecked, layerPharmacieChecked) { for (const msp of data) { if (msp[columns.x] && msp[columns.y]) { const isMSP = msp[columns.categetab] == "603" const marker = L.marker([msp[columns.x], msp[columns.y]], { title: getName(msp, dataP4Pillon[msp[columns.finessET]]), icon: isMSP ? mspIcon : pharmacyIcon }) .on("click", (e)=> { window.msp = msp displayInfo(msp, dataP4Pillon[msp[columns.finessET]]) }); isMSP ? markersMSP.addLayer(marker) : markersPharmacy.addLayer(marker) } } if (layerMSPChecked) { map.addLayer(markersMSP) } if (layerPharmacieChecked) { map.addLayer(markersPharmacy) } } // tileLayer var tileLayer = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', { maxZoom: 19, subdomains: 'abcd', attribution: '' }) map.addLayer(tileLayer) // Localisation function getMapLocation() { const mapLocation = L.Permalink.getMapLocation(); const mapLocationDefaultCenter = [52.26869,-113.81034] const defaultCenter = [46.55886, 3.21924] const defaultZoom = 6 function isDefaultCenter() { return JSON.stringify(mapLocation.center) == JSON.stringify(defaultCenter) } return { getCenter : () => { return isDefaultCenter() ? defaultCenter : mapLocation.center }, getZoom : () => { return isDefaultCenter() ? defaultZoom : mapLocation.zoom }, } } const mapLocation = getMapLocation(); map.setView(mapLocation.getCenter(), mapLocation.getZoom()) // Zoom export function zoomIn() { map.zoomIn() } export function zoomOut() { map.zoomOut() } // Changement d'URL L.Permalink.setup(map);