// =============================== // MAPPA GLOBALE — stile Google Photos Web // =============================== window.globalMap = null; window.globalMarkers = null; document.addEventListener("DOMContentLoaded", () => { const openBtn = document.getElementById("openMapBtn"); if (!openBtn) return; openBtn.addEventListener("click", openGlobalMap); const RADIUS_PX = 50; const DISABLE_CLUSTER_AT_ZOOM = 18; const OPEN_STRIP_CHILDREN_MAX = 20; // =============================== // APRI / CHIUDI MAPPA // =============================== async function openGlobalMap() { const mapDiv = document.getElementById("globalMap"); const gallery = document.getElementById("gallery"); if (!mapDiv) return; const isOpen = mapDiv.classList.contains("open"); if (isOpen) { mapDiv.classList.remove("open"); gallery?.classList.remove("hidden"); window.closeBottomSheet?.(); return; } mapDiv.classList.add("open"); gallery?.classList.add("hidden"); await new Promise(r => requestAnimationFrame(r)); if (!window.globalMap) initMap(); else window.globalMap.invalidateSize(); redrawPhotoMarkers(); } // =============================== // INIZIALIZZA MAPPA // =============================== function initMap() { console.log("Inizializzo mappa Leaflet + MarkerCluster…"); window.globalMap = L.map("globalMap", { zoomControl: true, attributionControl: true }).setView([42.5, 12.5], 6); L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { maxZoom: 19 }).addTo(window.globalMap); window.globalMarkers = L.markerClusterGroup({ showCoverageOnHover: false, spiderfyOnMaxZoom: true, disableClusteringAtZoom: DISABLE_CLUSTER_AT_ZOOM, iconCreateFunction: clusterIconRenderer }); window.globalMarkers.on("clusterclick", onClusterClick); window.globalMap.addLayer(window.globalMarkers); } // =============================== // RENDER CLUSTER // =============================== function clusterIconRenderer(cluster) { const count = cluster.getChildCount(); const size = Math.min(92, Math.round(28 + Math.sqrt(count) * 6)); const cls = count > 200 ? "cluster-xl" : count > 50 ? "cluster-lg" : count > 10 ? "cluster-md" : "cluster-sm"; const children = cluster.getAllChildMarkers().slice(0, 4); const thumbs = children .map(m => m.__photo?.thub2 || m.__photo?.thub1) .filter(Boolean) .map(t => toAbsoluteUrl(t, children[0].__photo.name, "thumbs", children[0].__photo.cartella)); const collage = thumbs.length ? `