map: fix cameras vanishing after opening a camera popup and zooming
Some checks failed
build-and-deploy / build (push) Failing after 52s
Some checks failed
build-and-deploy / build (push) Failing after 52s
Root cause: Leaflet 1.9.4's Map.closePopup() never nulls map._popup (only unbindPopup does), so the moveend guard 'if (map._popup) return' skipped every overlay reload forever after the first popup was ever opened. Opening one camera popup froze the marker layer: zoom out and the map kept showing the stale zoomed-in subset (or nothing) until a full page refresh. Track real popup state via popupopen/popupclose events instead, and close the popup on user zoom/drag so the moveend reload always runs after navigation; the autopan skip still protects the popup when it pans itself into view.
This commit is contained in:
parent
5cea0a5940
commit
b2369bcc20
1 changed files with 15 additions and 6 deletions
|
|
@ -833,13 +833,22 @@ async function initMap() {
|
||||||
if (activeHls) { try { activeHls.destroy(); } catch (_) {} activeHls = null; }
|
if (activeHls) { try { activeHls.destroy(); } catch (_) {} activeHls = null; }
|
||||||
});
|
});
|
||||||
updateHeatLegend();
|
updateHeatLegend();
|
||||||
// Reload overlays when the user pans/zooms. Skip when a popup is open:
|
// Reload overlays when the user pans/zooms. A live popup makes the
|
||||||
// opening a camera popup auto-pans the map to fit it, and that moveend
|
// rebuild skip (so the popup's autopan doesn't destroy it), but user
|
||||||
// must NOT rebuild the marker group under the open popup (which would
|
// zoom/drag must close the popup FIRST — otherwise zooming out with a
|
||||||
// close it). Leaflet closes popups on manual drag, so a live popup here
|
// camera popup open leaves the stale, zoomed-in marker group on the
|
||||||
// means the move was autopan — safe to skip.
|
// map and the cameras "vanish" until a refresh.
|
||||||
|
//
|
||||||
|
// NOTE: `map._popup` is NOT a reliable open-check in Leaflet 1.9.4 —
|
||||||
|
// Map.closePopup() never nulls it, so once any popup has been opened
|
||||||
|
// it stays truthy forever. Track the real state via popupopen/close.
|
||||||
|
let camPopupOpen = false;
|
||||||
|
map.on('popupopen', () => { camPopupOpen = true; });
|
||||||
|
map.on('popupclose', () => { camPopupOpen = false; });
|
||||||
|
map.on('zoomstart', () => { if (camPopupOpen) map.closePopup(); });
|
||||||
|
map.on('dragstart', () => { if (camPopupOpen) map.closePopup(); });
|
||||||
map.on('moveend', () => {
|
map.on('moveend', () => {
|
||||||
if (map._popup) return;
|
if (camPopupOpen) return; // only the popup's own autopan now
|
||||||
if (firesOn) loadFires();
|
if (firesOn) loadFires();
|
||||||
if (camsOn) loadCams();
|
if (camsOn) loadCams();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue