diff --git a/Logic/Actors/GeoLocationHandler.ts b/Logic/Actors/GeoLocationHandler.ts index 2237dff6f..15ad99aa3 100644 --- a/Logic/Actors/GeoLocationHandler.ts +++ b/Logic/Actors/GeoLocationHandler.ts @@ -8,6 +8,7 @@ import { UIEventSource } from "../UIEventSource" /** * The geolocation-handler takes a map-location and a geolocation state. * It'll move the map as appropriate given the state of the geolocation-API + * It will also copy the geolocation into the appropriate FeatureSource to display on the map */ export default class GeoLocationHandler { public readonly geolocationState: GeoLocationState @@ -117,7 +118,11 @@ export default class GeoLocationHandler { private CopyGeolocationIntoMapstate() { const state = this._state - this.geolocationState.currentGPSLocation.addCallbackAndRunD((location) => { + this.geolocationState.currentGPSLocation.addCallbackAndRun((location) => { + if (location === undefined) { + state.currentUserLocation?.features?.setData([]) + return + } const feature = { type: "Feature", properties: { diff --git a/Logic/State/GeoLocationState.ts b/Logic/State/GeoLocationState.ts index f70e7e212..c76ccecee 100644 --- a/Logic/State/GeoLocationState.ts +++ b/Logic/State/GeoLocationState.ts @@ -57,7 +57,6 @@ export class GeoLocationState { if (state === "granted") { self._previousLocationGrant.setData("true") self._grantedThisSession.setData(true) - await self.startWatching() } if (state === "prompt" && self._grantedThisSession.data) { // This is _really_ weird: we had a grant earlier, but it's 'prompt' now? @@ -65,6 +64,7 @@ export class GeoLocationState { // self.permission.setData("denied") self._previousLocationGrant.setData("false") self.permission.setData("denied") + self.currentGPSLocation.setData(undefined) console.warn("Detected a downgrade in permissions!") } if (state === "denied") { @@ -72,6 +72,7 @@ export class GeoLocationState { } }) + console.log("Previous location grant:", this._previousLocationGrant.data) if (this._previousLocationGrant.data === "true") { // A previous visit successfully granted permission. Chance is high that we are allowed to use it again! @@ -80,6 +81,7 @@ export class GeoLocationState { console.log("Requesting access to GPS as this was previously granted") this.requestPermission() } + window["geolocation_state"] = this } /** @@ -91,6 +93,7 @@ export class GeoLocationState { navigator.geolocation.watchPosition( function (position) { self.currentGPSLocation.setData(position.coords) + self._previousLocationGrant.setData("true") }, function () { console.warn("Could not get location with navigator.geolocation") @@ -121,12 +124,13 @@ export class GeoLocationState { navigator?.permissions ?.query({ name: "geolocation" }) .then((status) => { - console.log("Geolocation permission is ", status.state) + console.log("Status update: received geolocation permission is ", status.state) this.permission.setData(status.state) const self = this status.onchange = function () { self.permission.setData(status.state) } + this.permission.setData("requested") // We _must_ call 'startWatching', as that is the actual trigger for the popup... self.startWatching() }) diff --git a/UI/BigComponents/GeolocationControl.ts b/UI/BigComponents/GeolocationControl.ts index 75a7e92e6..a6689cff4 100644 --- a/UI/BigComponents/GeolocationControl.ts +++ b/UI/BigComponents/GeolocationControl.ts @@ -28,10 +28,10 @@ export class GeolocationControl extends VariableUiElement { return Svg.location_locked_svg() } - if (permission === "prompt") { - return Svg.location_empty_svg() - } - if (geolocationState.currentGPSLocation === undefined) { + if (geolocationState.currentGPSLocation.data === undefined) { + if (permission === "prompt") { + return Svg.location_empty_svg() + } // Position not yet found, but permission is either requested or granted: we spin to indicate activity const icon = !geolocationHandler.mapHasMoved.data ? Svg.location_svg() @@ -41,6 +41,8 @@ export class GeolocationControl extends VariableUiElement { .SetStyle("animation: spin 4s linear infinite;") } + // We have a location, so we show a dot in the center + if ( lastClickWithinThreeSecs.data && geolocationState.permission.data === "granted"