Only fit map bounds on initial load, not on every activity update
Prevents the map from resetting zoom/pan when new activities stream in from relays. Users can now freely zoom and pan without being snapped back to the world view. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
276e1a8135
commit
a75885ca76
1 changed files with 4 additions and 2 deletions
|
|
@ -15,6 +15,7 @@ const router = useRouter()
|
||||||
const mapContainer = ref<HTMLElement | null>(null)
|
const mapContainer = ref<HTMLElement | null>(null)
|
||||||
let map: L.Map | null = null
|
let map: L.Map | null = null
|
||||||
let markerGroup: L.LayerGroup | null = null
|
let markerGroup: L.LayerGroup | null = null
|
||||||
|
let hasFittedBounds = false
|
||||||
|
|
||||||
// Fix Leaflet default icon paths (broken by bundlers)
|
// Fix Leaflet default icon paths (broken by bundlers)
|
||||||
const defaultIcon = L.icon({
|
const defaultIcon = L.icon({
|
||||||
|
|
@ -90,8 +91,9 @@ function updateMarkers() {
|
||||||
markerGroup.addLayer(marker)
|
markerGroup.addLayer(marker)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fit bounds if there are markers
|
// Fit bounds only on first load, not when new activities stream in
|
||||||
if (geoActivities.length > 0) {
|
if (!hasFittedBounds && geoActivities.length > 0) {
|
||||||
|
hasFittedBounds = true
|
||||||
const bounds = L.latLngBounds(
|
const bounds = L.latLngBounds(
|
||||||
geoActivities.map(a => [a.coordinates!.lat, a.coordinates!.lng] as L.LatLngTuple)
|
geoActivities.map(a => [a.coordinates!.lat, a.coordinates!.lng] as L.LatLngTuple)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue