Fix camera jumping - debounce fitBounds when points load
Some checks failed
Build Docker Image / build (push) Has been cancelled

This commit is contained in:
Ruslan Bakiev
2026-01-27 12:21:35 +07:00
parent 5aa460fd8a
commit 497a80f0c6

View File

@@ -693,25 +693,35 @@ watch(() => props.hoveredItem, () => {
}
}, { 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) => {
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
if (source) {
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) {
const bounds = new LngLatBounds()
points.forEach(p => {
bounds.extend([p.longitude, p.latitude])
})
if (!bounds.isEmpty()) {
mapRef.value.fitBounds(bounds, { padding: 80, maxZoom: 12 })
}
fitBoundsTimeout = setTimeout(() => {
if (!mapRef.value) return
const bounds = new LngLatBounds()
points.forEach(p => {
bounds.extend([p.longitude, p.latitude])
})
if (!bounds.isEmpty()) {
mapRef.value.fitBounds(bounds, { padding: 80, maxZoom: 12 })
}
}, 300) // Wait 300ms for all points to load
}
}, { deep: true })