From 7e94f335acd14e355495ec5f0378321a694693f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 11 Mar 2026 18:16:24 +0400 Subject: [PATCH] Prevent zooming when selecting saved places --- app/components/map.gjs | 10 +++++++++- app/routes/place.js | 4 +++- app/services/map-ui.js | 8 +++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/components/map.gjs b/app/components/map.gjs index 996a3b0..41bd482 100644 --- a/app/components/map.gjs +++ b/app/components/map.gjs @@ -441,6 +441,7 @@ export default class MapComponent extends Component { // Track the selected place from the UI Service (Router -> Map) updateSelectedPin = modifier(() => { const selected = this.mapUi.selectedPlace; + const options = this.mapUi.selectionOptions || {}; if (!this.selectedPinOverlay || !this.selectedPinElement) return; @@ -471,7 +472,12 @@ export default class MapComponent extends Component { } } - if (selected.bbox) { + if (options.preventZoom) { + // If we are preventing zoom (e.g. user clicked a bookmark), we still need to center + // but without changing the zoom level. + // We use animateToSmartCenter without a second argument (zoom=null). + this.animateToSmartCenter(coords); + } else if (selected.bbox) { this.zoomToBbox(selected.bbox); } else { this.handlePinVisibility(coords); @@ -870,6 +876,7 @@ export default class MapComponent extends Component { 'Clicked bookmark while sidebar open (switching):', clickedBookmark ); + this.mapUi.preventNextZoom = true; this.router.transitionTo('place', clickedBookmark); return; } @@ -884,6 +891,7 @@ export default class MapComponent extends Component { // Normal behavior (sidebar is closed) if (clickedBookmark) { console.debug('Clicked bookmark:', clickedBookmark); + this.mapUi.preventNextZoom = true; this.router.transitionTo('place', clickedBookmark); return; } diff --git a/app/routes/place.js b/app/routes/place.js index daf5e04..0c86a57 100644 --- a/app/routes/place.js +++ b/app/routes/place.js @@ -72,7 +72,9 @@ export default class PlaceRoute extends Route { // Notify the Map UI to show the pin if (model) { - this.mapUi.selectPlace(model); + const options = { preventZoom: this.mapUi.preventNextZoom }; + this.mapUi.selectPlace(model, options); + this.mapUi.preventNextZoom = false; } // Stop the pulse animation if it was running (e.g. redirected from search) this.mapUi.stopSearch(); diff --git a/app/services/map-ui.js b/app/services/map-ui.js index f595395..b0a99d3 100644 --- a/app/services/map-ui.js +++ b/app/services/map-ui.js @@ -9,18 +9,24 @@ export default class MapUiService extends Service { @tracked returnToSearch = false; @tracked currentCenter = null; @tracked searchBoxHasFocus = false; + @tracked selectionOptions = {}; + @tracked preventNextZoom = false; - selectPlace(place) { + selectPlace(place, options = {}) { this.selectedPlace = place; + this.selectionOptions = options; } clearSelection() { this.selectedPlace = null; + this.selectionOptions = {}; + this.preventNextZoom = false; } startSearch() { this.isSearching = true; this.isCreating = false; + this.preventNextZoom = false; } stopSearch() {