From b805374a6c40d28e95b9ab82db862c318a520957 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Tue, 14 Apr 2026 02:02:34 +0000 Subject: [PATCH] Fix not panning to location when map is loaded --- ts/components/MapLocator.vue | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/ts/components/MapLocator.vue b/ts/components/MapLocator.vue index 244591f3..bafbee84 100644 --- a/ts/components/MapLocator.vue +++ b/ts/components/MapLocator.vue @@ -388,7 +388,7 @@ const updateMarkers = () => { }; // Frame all markers in view -const frameMarkers = () => { +function frameMarkers() { if (!map.value || props.markers.length === 0) return; if (props.markers.length === 1) { @@ -406,17 +406,13 @@ const frameMarkers = () => { // Defer this until the map is loaded or we'll drop updates if (map.value) { - map.value.on("load", () => { - if (!map.value) return; - map.value.panTo( - { - lat: props.markers[0].location.latitude, - lng: props.markers[0].location.longitude, - }, - { duration: 1000, zoom: zoom }, - { isInternalUpdate: true }, - ); - }); + if (isLoaded.value) { + panToLocation(props.markers[0].location, zoom); + } else { + map.value.on("load", () => { + panToLocation(props.markers[0].location, zoom); + }); + } } else { console.error("Can't frame markers before the map is created"); } @@ -433,7 +429,19 @@ const frameMarkers = () => { { isInternalUpdate: true }, ); } -}; +} + +function panToLocation(location: Location, zoom: number) { + if (!map.value) return; + map.value.panTo( + { + lat: props.markers[0].location.latitude, + lng: props.markers[0].location.longitude, + }, + { duration: 1000, zoom: zoom }, + { isInternalUpdate: true }, + ); +} // Watch for modelValue changes to pan to location watch(