Browse Source

feat(leaflet): ajoute des overlays par type de projet

tags/v096
François Poulain François Poulain 4 months ago
parent
commit
c36722d9c3
1 changed files with 25 additions and 11 deletions
  1. +25
    -11
      assets/js/lib/leaflet.js

+ 25
- 11
assets/js/lib/leaflet.js View File

@@ -43,6 +43,7 @@ $(() => {
const height = mapdiv.width() * ratio;
const apiPath = '/api/v2/pages/';
const icon = {};
const group = {};
const colors = {
primary: '#9c1006',
secondary: '#00767b',
@@ -58,21 +59,25 @@ $(() => {
const content = projet.content;
if (projet.latitude && projet.longitude) {
const coords = [projet.latitude, projet.longitude];
icon[projet.type.nom] = L.icon({
iconUrl: projet.type.url,
iconSize: [42, 42],
iconAnchor: [24, 24],
popupAnchor: [0, -30]
});
L.marker(coords, {
icon: icon[projet.type.nom]
}).addTo(map)
.bindPopup(content, {
if (typeof icon[projet.type.nom] === 'undefined') {
icon[projet.type.nom] = L.icon({
iconUrl: projet.type.url,
iconSize: [42, 42],
iconAnchor: [24, 24],
popupAnchor: [0, -30]
});
group[projet.type.nom] = [];
}
group[projet.type.nom].push(
L.marker(coords, {
icon: icon[projet.type.nom]
}).bindPopup(content, {
className: 'leaflet-map-popup',
maxHeight: height - 120,
minWidth: 300,
keepInView: true
});
})
);
} else if (projet.geometry) {
const color = colors[projet.theme];
const territoire = JSON.parse(projet.geometry);
@@ -100,6 +105,15 @@ $(() => {
}
return false;
});
const overlayMaps = {};
for (const typename in group) {
if (typename) {
overlayMaps[typename] = L.layerGroup(group[typename]).addTo(map);
}
}
L.control.layers({}, overlayMaps, {
collapsed: false
}).addTo(map);
});
return false;
});


Loading…
Cancel
Save