mirror of
https://github.com/zvx-echo6/navi.git
synced 2026-05-20 22:54:42 +02:00
fix: zoom indicator now updates live via dedicated useEffect
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6db09fd3d3
commit
ec6f4254b9
1 changed files with 21 additions and 3 deletions
|
|
@ -643,9 +643,6 @@ const MapView = forwardRef(function MapView(_, ref) {
|
||||||
type: 'geojson',
|
type: 'geojson',
|
||||||
data: { type: 'FeatureCollection', features: [] },
|
data: { type: 'FeatureCollection', features: [] },
|
||||||
})
|
})
|
||||||
// Initialize zoom indicator and subscribe to zoom changes
|
|
||||||
setZoomLevel(map.getZoom())
|
|
||||||
map.on("zoom", () => setZoomLevel(map.getZoom()))
|
|
||||||
|
|
||||||
// Restore overlay layers from localStorage prefs
|
// Restore overlay layers from localStorage prefs
|
||||||
try {
|
try {
|
||||||
|
|
@ -973,6 +970,27 @@ const MapView = forwardRef(function MapView(_, ref) {
|
||||||
}
|
}
|
||||||
}, [stops, route, gpsOrigin, geoPermission])
|
}, [stops, route, gpsOrigin, geoPermission])
|
||||||
|
|
||||||
|
// Track zoom level for indicator
|
||||||
|
useEffect(() => {
|
||||||
|
const map = mapInstance.current
|
||||||
|
if (!map) return
|
||||||
|
|
||||||
|
const updateZoom = () => setZoomLevel(map.getZoom())
|
||||||
|
|
||||||
|
// Set initial zoom
|
||||||
|
if (map.loaded()) {
|
||||||
|
updateZoom()
|
||||||
|
} else {
|
||||||
|
map.once("load", updateZoom)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribe to zoom changes
|
||||||
|
map.on("zoom", updateZoom)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
map.off("zoom", updateZoom)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative w-full h-full">
|
<div className="relative w-full h-full">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue