diff --git a/public/js/map-ui.js b/public/js/map-ui.js index 9f6fe67..cb10e4b 100644 --- a/public/js/map-ui.js +++ b/public/js/map-ui.js @@ -247,13 +247,13 @@ document.querySelector(".popup-close").onclick = () => { document.querySelectorAll(".building").forEach((building) => { building.addEventListener("mouseenter", async (e) => { try { - const id = building.dataset.id; + // data-id bevorzugen, sonst ID aus href extrahieren (z.B. "/building/5" → "5") + const id = building.dataset.id || building.getAttribute("href")?.split("/").pop(); + if (!id) return; if (!tooltipCache[id]) { const res = await fetch("/api/building/" + id); - if (!res.ok) throw new Error("API Fehler"); - tooltipCache[id] = await res.json(); }