Fix camera jumping - debounce fitBounds when points load
Some checks failed
Build Docker Image / build (push) Has been cancelled
Some checks failed
Build Docker Image / build (push) Has been cancelled
This commit is contained in:
@@ -693,25 +693,35 @@ watch(() => props.hoveredItem, () => {
|
|||||||
}
|
}
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|
||||||
// Update related points layer when relatedPoints changes + fit bounds
|
// Debounced fitBounds to avoid camera jumping when points load incrementally
|
||||||
|
let fitBoundsTimeout: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
|
// Update related points layer when relatedPoints changes + fit bounds (debounced)
|
||||||
watch(() => props.relatedPoints, (points) => {
|
watch(() => props.relatedPoints, (points) => {
|
||||||
if (!mapRef.value || !mapInitialized.value) return
|
if (!mapRef.value || !mapInitialized.value) return
|
||||||
|
|
||||||
// Update the source data
|
// Update the source data immediately
|
||||||
const source = mapRef.value.getSource(relatedSourceId.value) as mapboxgl.GeoJSONSource | undefined
|
const source = mapRef.value.getSource(relatedSourceId.value) as mapboxgl.GeoJSONSource | undefined
|
||||||
if (source) {
|
if (source) {
|
||||||
source.setData(relatedPointsGeoJson.value)
|
source.setData(relatedPointsGeoJson.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fit bounds to show all related points (Info mode)
|
// Debounce fitBounds - wait for all points to load before zooming
|
||||||
|
if (fitBoundsTimeout) {
|
||||||
|
clearTimeout(fitBoundsTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
if (points && points.length > 0) {
|
if (points && points.length > 0) {
|
||||||
const bounds = new LngLatBounds()
|
fitBoundsTimeout = setTimeout(() => {
|
||||||
points.forEach(p => {
|
if (!mapRef.value) return
|
||||||
bounds.extend([p.longitude, p.latitude])
|
const bounds = new LngLatBounds()
|
||||||
})
|
points.forEach(p => {
|
||||||
if (!bounds.isEmpty()) {
|
bounds.extend([p.longitude, p.latitude])
|
||||||
mapRef.value.fitBounds(bounds, { padding: 80, maxZoom: 12 })
|
})
|
||||||
}
|
if (!bounds.isEmpty()) {
|
||||||
|
mapRef.value.fitBounds(bounds, { padding: 80, maxZoom: 12 })
|
||||||
|
}
|
||||||
|
}, 300) // Wait 300ms for all points to load
|
||||||
}
|
}
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user