From f31b025b8dba7218576c58ef6bc2b3101052beb7 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 7 May 2023 23:25:28 +0200 Subject: [PATCH] Fix: don't move the map after we jumped to the current GPS location --- Logic/Actors/GeoLocationHandler.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Logic/Actors/GeoLocationHandler.ts b/Logic/Actors/GeoLocationHandler.ts index e5a1b195d..3daace172 100644 --- a/Logic/Actors/GeoLocationHandler.ts +++ b/Logic/Actors/GeoLocationHandler.ts @@ -35,7 +35,11 @@ export default class GeoLocationHandler { * Note that this featureSource is _derived_ from 'historicalUserLocations' */ public readonly historicalUserLocationsTrack: FeatureSource - public readonly mapHasMoved: UIEventSource = new UIEventSource(false) + + /** + * The last moment that the map has moved + */ + public readonly mapHasMoved: UIEventSource = new UIEventSource(undefined) private readonly selectedElement: UIEventSource private readonly mapProperties?: MapProperties private readonly gpsLocationHistoryRetentionTime?: UIEventSource @@ -58,7 +62,7 @@ export default class GeoLocationHandler { if (new Date().getTime() - initTime.getTime() < 250) { return } - self.mapHasMoved.setData(true) + self.mapHasMoved.setData(new Date()) return true // Unsubscribe }) @@ -66,7 +70,7 @@ export default class GeoLocationHandler { QueryParameters.wasInitialized("lat") || QueryParameters.wasInitialized("lon") if (latLonGivenViaUrl) { // The URL counts as a 'user interaction' - this.mapHasMoved.setData(true) + this.mapHasMoved.setData(new Date()) } this.geolocationState.currentGPSLocation.addCallbackAndRunD((_) => { @@ -76,7 +80,10 @@ export default class GeoLocationHandler { // The map hasn't moved yet; we received our first coordinates, so let's move there! self.MoveMapToCurrentLocation() } - if (timeSinceLastRequest < Constants.zoomToLocationTimeout) { + if (timeSinceLastRequest < Constants.zoomToLocationTimeout && + (this.mapHasMoved.data === undefined || this.mapHasMoved.data.getTime() < geolocationState.requestMoment.data?.getTime() ) + ) { + // still within request time and the map hasn't moved since requesting to jump to the current location self.MoveMapToCurrentLocation() } @@ -132,7 +139,7 @@ export default class GeoLocationHandler { }) const zoom = this.mapProperties.zoom zoom.setData(Math.max(zoom.data, 16)) - this.mapHasMoved.setData(true) + this.mapHasMoved.setData(new Date()) this.geolocationState.requestMoment.setData(undefined) }