fix(openstreetmap): use map.once('moveend') for reliable viewport sync

This commit is contained in:
2026-08-06 23:23:15 +02:00
parent 7f07a563b6
commit 17331a5792
@@ -13,6 +13,7 @@ type LeafletMap = {
getCenter: () => { lat: number; lng: number };
getZoom: () => number;
on: (event: string, fn: () => void) => void;
once: (event: string, fn: () => void) => void;
off: (event: string, fn: () => void) => void;
remove: () => void;
};
@@ -132,10 +133,10 @@ export function BotsuOpenStreetMap() {
if (!map) return;
syncingRef.current = true;
map.setView([viewport.lat, viewport.lng], viewport.zoom);
// Reset syncing flag after animation (~300ms)
setTimeout(() => {
// Reset syncing flag only after the animation actually finishes
map.once('moveend', () => {
syncingRef.current = false;
}, 300);
});
});
}, [mapViewportBridge]);