From fa0465fabb0b86660d783842f795c029958e8030 Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Fri, 6 Feb 2026 14:37:37 +0700 Subject: [PATCH] Auto-scope selection to current map bounds --- app/pages/catalog/index.vue | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/pages/catalog/index.vue b/app/pages/catalog/index.vue index 9480caf..7d290cc 100644 --- a/app/pages/catalog/index.vue +++ b/app/pages/catalog/index.vue @@ -100,6 +100,7 @@ const catalogPageRef = ref<{ currentBounds: Ref } | null>(null // Current map bounds (local state, updated when map moves) const currentMapBounds = ref(null) +const selectionBoundsBackup = ref<{ hadBounds: boolean; bounds: { west: number; south: number; east: number; north: number } | null } | null>(null) // Hovered item for map highlight const hoveredItemId = ref(null) @@ -235,8 +236,43 @@ const onLoadMore = () => { 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 watch(selectMode, async (mode) => { + if (mode) { + applySelectionBounds() + } else { + restoreSelectionBounds() + } if (mode === 'product') { await initProducts() setMapViewMode('offers')