From c0e70b225fa4e7090c6f6652a9f1e2df089ac5b5 Mon Sep 17 00:00:00 2001 From: Atharva Sawant Date: Fri, 13 Dec 2024 15:27:31 +0530 Subject: [PATCH] Improvement to popup and zoom behavior --- src/components/MapView.vue | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/MapView.vue b/src/components/MapView.vue index bd319f0..0e594ea 100644 --- a/src/components/MapView.vue +++ b/src/components/MapView.vue @@ -21,6 +21,7 @@ export default { setup(props) { const map = ref(null) const trackLayers = ref([]) + const hasAutoFitted = ref(false) const getLocationFromIP = async () => { try { @@ -43,11 +44,14 @@ export default { } const renderTracks = () => { - // Clear existing track layers + // Clear existing track layers and popups trackLayers.value.forEach(layer => { map.value.removeLayer(layer) }) trackLayers.value = [] + + // Close any existing popups + map.value.closePopup() if (!props.tracks || props.tracks.length === 0) return @@ -114,7 +118,7 @@ export default { }) }) - // Focus on selected track if one is selected, otherwise show all tracks + // Focus on selected track if one is selected if (selectedTrackBounds.length > 0) { const selectedGroup = L.latLngBounds(selectedTrackBounds) @@ -124,9 +128,11 @@ export default { paddingTopLeft: [50, 120], // Extra top padding for popup paddingBottomRight: [50, 50] }) - } else if (allBounds.length > 0) { + } else if (allBounds.length > 0 && !hasAutoFitted.value) { + // Only auto-fit to all tracks on initial load, not when deselecting const group = new L.featureGroup(trackLayers.value.map(item => item.polyline)) map.value.fitBounds(group.getBounds(), { padding: [20, 20] }) + hasAutoFitted.value = true } }