From 322f706e68c9239d04b7955c814a19f79bbf2d3a Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sat, 29 May 2021 20:30:36 +0200 Subject: [PATCH] Small improvement in geolocation handling --- Logic/Actors/GeoLocationHandler.ts | 52 ++++++++++++++++++------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/Logic/Actors/GeoLocationHandler.ts b/Logic/Actors/GeoLocationHandler.ts index 01c8725e79..772f57304f 100644 --- a/Logic/Actors/GeoLocationHandler.ts +++ b/Logic/Actors/GeoLocationHandler.ts @@ -136,25 +136,7 @@ export default class GeoLocationHandler extends UIElement { const timeSinceRequest = (new Date().getTime() - (self._lastUserRequest?.getTime() ?? 0)) / 1000; if (timeSinceRequest < 30) { - self._lastUserRequest = undefined; - - // We use the layout location - const b = this._layoutToUse.data.lockLocation - let inRange = true; - if(b){ - if(b!== true){ - // B is an array with our locklocation - inRange = b[0][0] <= location.latlng[0] && location.latlng[0] <= b[1][0] && - b[0][1] <= location.latlng[1] && location.latlng[1] <= b[1][1]; - } - } - if (!inRange) { - console.log("Not zooming to GPS location: out of bounds", b, location.latlng) - } else { - this._leafletMap.data.setView( - location.latlng, this._leafletMap.data.getZoom() - ); - } + self.MoveToCurrentLoction(16) } let color = "#1111cc"; @@ -226,6 +208,35 @@ export default class GeoLocationHandler extends UIElement { } } + private MoveToCurrentLoction(targetZoom = 16) { + const location = this._currentGPSLocation.data; + this._lastUserRequest = undefined; + + + if (this._currentGPSLocation.data.latlng[0] === 0 && this._currentGPSLocation.data.latlng[1] === 0) { + console.debug("Not moving to GPS-location: it is null island") + return; + } + + // We check that the GPS location is not out of bounds + const b = this._layoutToUse.data.lockLocation + let inRange = true; + if (b) { + if (b !== true) { + // B is an array with our locklocation + inRange = b[0][0] <= location.latlng[0] && location.latlng[0] <= b[1][0] && + b[0][1] <= location.latlng[1] && location.latlng[1] <= b[1][1]; + } + } + if (!inRange) { + console.log("Not zooming to GPS location: out of bounds", b, location.latlng) + } else { + this._leafletMap.data.setView( + location.latlng, targetZoom + ); + } + } + private StartGeolocating(zoomToGPS = true) { const self = this; console.log("Starting geolocation") @@ -236,8 +247,7 @@ export default class GeoLocationHandler extends UIElement { return ""; } if (this._currentGPSLocation.data !== undefined) { - this._currentGPSLocation.ping() - this._leafletMap.data.setZoom(16) + this.MoveToCurrentLoction(16) }