Auto-scope selection to current map bounds
All checks were successful
Build Docker Image / build (push) Successful in 4m36s
All checks were successful
Build Docker Image / build (push) Successful in 4m36s
This commit is contained in:
@@ -100,6 +100,7 @@ const catalogPageRef = ref<{ currentBounds: Ref<MapBounds | null> } | null>(null
|
|||||||
|
|
||||||
// Current map bounds (local state, updated when map moves)
|
// Current map bounds (local state, updated when map moves)
|
||||||
const currentMapBounds = ref<MapBounds | null>(null)
|
const currentMapBounds = ref<MapBounds | null>(null)
|
||||||
|
const selectionBoundsBackup = ref<{ hadBounds: boolean; bounds: { west: number; south: number; east: number; north: number } | null } | null>(null)
|
||||||
|
|
||||||
// Hovered item for map highlight
|
// Hovered item for map highlight
|
||||||
const hoveredItemId = ref<string | null>(null)
|
const hoveredItemId = ref<string | null>(null)
|
||||||
@@ -235,8 +236,43 @@ const onLoadMore = () => {
|
|||||||
if (selectMode.value === 'supplier') loadMoreSuppliers()
|
if (selectMode.value === 'supplier') loadMoreSuppliers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getSelectionBounds = () => {
|
||||||
|
const bounds = currentMapBounds.value ?? catalogPageRef.value?.currentBounds?.value ?? null
|
||||||
|
if (!bounds) return null
|
||||||
|
return { west: bounds.west, south: bounds.south, east: bounds.east, north: bounds.north }
|
||||||
|
}
|
||||||
|
|
||||||
|
const applySelectionBounds = () => {
|
||||||
|
if (!selectionBoundsBackup.value) {
|
||||||
|
selectionBoundsBackup.value = {
|
||||||
|
hadBounds: !!urlBounds.value,
|
||||||
|
bounds: urlBounds.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const bounds = getSelectionBounds()
|
||||||
|
if (bounds) {
|
||||||
|
setBoundsInUrl(bounds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const restoreSelectionBounds = () => {
|
||||||
|
const prev = selectionBoundsBackup.value
|
||||||
|
if (!prev) return
|
||||||
|
if (prev.hadBounds && prev.bounds) {
|
||||||
|
setBoundsInUrl(prev.bounds)
|
||||||
|
} else {
|
||||||
|
clearBoundsFromUrl()
|
||||||
|
}
|
||||||
|
selectionBoundsBackup.value = null
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize data and sync map view when selectMode changes
|
// Initialize data and sync map view when selectMode changes
|
||||||
watch(selectMode, async (mode) => {
|
watch(selectMode, async (mode) => {
|
||||||
|
if (mode) {
|
||||||
|
applySelectionBounds()
|
||||||
|
} else {
|
||||||
|
restoreSelectionBounds()
|
||||||
|
}
|
||||||
if (mode === 'product') {
|
if (mode === 'product') {
|
||||||
await initProducts()
|
await initProducts()
|
||||||
setMapViewMode('offers')
|
setMapViewMode('offers')
|
||||||
|
|||||||
Reference in New Issue
Block a user