Improvement to popup and zoom behavior
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user