fix: pan to clicked marker without zoom reset — closes #86
This commit is contained in:
@@ -107,20 +107,14 @@ function SelectionController({ places, selectedPlaceId, dayPlaces, paddingOpts }
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedPlaceId && selectedPlaceId !== prev.current) {
|
if (selectedPlaceId && selectedPlaceId !== prev.current) {
|
||||||
// Fit all day places into view (so you see context), but ensure selected is visible
|
// Pan to the selected place without changing zoom
|
||||||
const toFit = dayPlaces.length > 0 ? dayPlaces : places.filter(p => p.id === selectedPlaceId)
|
const selected = places.find(p => p.id === selectedPlaceId)
|
||||||
const withCoords = toFit.filter(p => p.lat && p.lng)
|
if (selected?.lat && selected?.lng) {
|
||||||
if (withCoords.length > 0) {
|
map.panTo([selected.lat, selected.lng], { animate: true })
|
||||||
try {
|
|
||||||
const bounds = L.latLngBounds(withCoords.map(p => [p.lat, p.lng]))
|
|
||||||
if (bounds.isValid()) {
|
|
||||||
map.fitBounds(bounds, { ...paddingOpts, maxZoom: 16, animate: true })
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prev.current = selectedPlaceId
|
prev.current = selectedPlaceId
|
||||||
}, [selectedPlaceId, places, dayPlaces, paddingOpts, map])
|
}, [selectedPlaceId, places, map])
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user