From 5e0b30759d1a97183468d809dab90cfc62a0bc0f Mon Sep 17 00:00:00 2001 From: Mathieu Moran Date: Mon, 10 Aug 2026 05:46:45 -0400 Subject: [PATCH] fix: always add tile layer at map init, fix zoom bounds - tiles.addTo(map) now called at init instead of lazily on first trip click (fixes blank map on page load on the server portal) - minZoom/maxZoom read from data-min-zoom/data-max-zoom attributes with correct NaN fallback (parseInt || default) - Pi template: data-min-zoom=8 data-max-zoom=15 (matches cached tile range) - Server template: data-min-zoom=3 data-max-zoom=19 (full OSM range) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- static/js/history.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/static/js/history.js b/static/js/history.js index 256bf54..b6600e6 100644 --- a/static/js/history.js +++ b/static/js/history.js @@ -13,14 +13,14 @@ const mapEl = document.getElementById("history-map"); const tileUrl = mapEl.dataset.tileUrl || "/static/vendor/tiles/{z}/{x}/{y}.png"; const tileAttrib = mapEl.dataset.tileAttrib || "© MapTiler © OpenStreetMap contributors"; - const minZoom = parseInt(mapEl.dataset.minZoom || "3", 10); - const maxZoom = parseInt(mapEl.dataset.maxZoom || "19", 10); - const map = L.map("history-map", { minZoom, maxZoom }).setView([48.505, -0.09], 12); + const minZoom = parseInt(mapEl.dataset.minZoom, 10) || 3; + const maxZoom = parseInt(mapEl.dataset.maxZoom, 10) || 19; + const map = L.map("history-map", { minZoom: minZoom, maxZoom: maxZoom }).setView([48.505, -0.09], 12); const tiles = L.tileLayer(tileUrl, { - minZoom, - maxZoom, + minZoom: minZoom, + maxZoom: maxZoom, attribution: tileAttrib, - }); + }).addTo(map); let routeLayer = null; let vehicleMarker = null; let replayPoints = []; @@ -147,9 +147,6 @@ if (routeLayer) { routeLayer.remove(); } - if (!map.hasLayer(tiles)) { - tiles.addTo(map); - } const coordinates = result.points.map(function (point) { return [point.latitude, point.longitude]; });