Auto-scope selection to current map bounds
All checks were successful
Build Docker Image / build (push) Successful in 4m36s

This commit is contained in:
Ruslan Bakiev
2026-02-06 14:37:37 +07:00
parent 161a1426e4
commit fa0465fabb

View File

@@ -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')