Icones de tailles varibles suivant le zoom

This commit is contained in:
leosw committed 2026-10-18 17:28:05 +02:00
1 parent 860f1077aa
commit d26d198dab
1 file changed
+18 -26
+18 -26
View File
@@ -202,19 +202,6 @@ $(document).ready(function() {
); );
}); });
// ---------------------------------------------------------
// Icônes
// ---------------------------------------------------------
for (const type in window.poi_icons) {
icons[type] = L.icon({
iconUrl: window.poi_icons[type],
iconSize: [32, 32],
iconAnchor: [16, 32],
popupAnchor: [0, -32]
});
}
// --------------------------------------------------------- // ---------------------------------------------------------
// Chargement des POI visibles // Chargement des POI visibles
// --------------------------------------------------------- // ---------------------------------------------------------
@@ -224,6 +211,19 @@ $(document).ready(function() {
return; return;
var b = mymap.getBounds(); var b = mymap.getBounds();
var currentZoom = mymap.getZoom();
// helper local : construit un L.Icon en fonction du type et du zoom
function getMarkerIconFor(type, zoom) {
var size = (zoom > 11) ? 32 : 24;
return L.icon({
iconUrl: window.poi_icons[type],
iconSize: [size, size],
iconAnchor: [Math.floor(size / 2), size],
popupAnchor: [0, -size]
});
}
$.getJSON( $.getJSON(
root + "poi/api_bbox", root + "poi/api_bbox",
@@ -237,14 +237,12 @@ $(document).ready(function() {
poiLayer.clearLayers(); poiLayer.clearLayers();
pois.forEach(function(poi) { pois.forEach(function(poi) {
var icon = var markerIcon = getMarkerIconFor(poi.type, currentZoom);
icons[poi.type] ||
icons["default"];
var marker = L.marker( var marker = L.marker(
[poi.lat, poi.lon], [poi.lat, poi.lon],
{ {
icon: icon icon: markerIcon
} }
); );
@@ -258,15 +256,9 @@ $(document).ready(function() {
} }
); );
marker.on( marker.on("click", function() {
"click", window.location = root + "poi/" + poi.permalink;
function() { });
window.location =
root +
"poi/" +
poi.permalink;
}
);
poiLayer.addLayer(marker); poiLayer.addLayer(marker);
}); });