Automatically zoom to GPS location if no coordinate is specified in the URL

This commit is contained in:
Pieter Vander Vennet 2021-08-26 12:15:26 +02:00
parent dad579c895
commit 61b6721342
3 changed files with 17 additions and 9 deletions

View file

@ -6,6 +6,7 @@ import {LocalStorageSource} from "../Web/LocalStorageSource";
import {VariableUiElement} from "../../UI/Base/VariableUIElement"; import {VariableUiElement} from "../../UI/Base/VariableUIElement";
import BaseUIElement from "../../UI/BaseUIElement"; import BaseUIElement from "../../UI/BaseUIElement";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"; import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import {QueryParameters} from "../Web/QueryParameters";
export default class GeoLocationHandler extends VariableUiElement { export default class GeoLocationHandler extends VariableUiElement {
/** /**
@ -94,8 +95,6 @@ export default class GeoLocationHandler extends VariableUiElement {
super( super(
hasLocation.map( hasLocation.map(
(hasLocationData) => { (hasLocationData) => {
let icon: BaseUIElement;
console.log("Determining icon:", permission.data, isActive.data, hasLocationData, isLocked.data, lastClickWithinThreeSecs.data)
if (permission.data === "denied") { if (permission.data === "denied") {
return Svg.location_refused_svg(); return Svg.location_refused_svg();
} }
@ -167,9 +166,12 @@ export default class GeoLocationHandler extends VariableUiElement {
} }
} }
self.init(true); self.init(true, true);
}); });
this.init(false);
const latLonGiven = QueryParameters.wasInitialized("lat") && QueryParameters.wasInitialized("lon")
this.init(false, !latLonGiven);
isLocked.addCallbackAndRunD(isLocked => { isLocked.addCallbackAndRunD(isLocked => {
if (isLocked) { if (isLocked) {
@ -217,7 +219,7 @@ export default class GeoLocationHandler extends VariableUiElement {
}); });
} }
private init(askPermission: boolean) { private init(askPermission: boolean, forceZoom: boolean) {
const self = this; const self = this;
if (self._isActive.data) { if (self._isActive.data) {
@ -231,7 +233,7 @@ export default class GeoLocationHandler extends VariableUiElement {
?.then(function (status) { ?.then(function (status) {
console.log("Geolocation is already", status); console.log("Geolocation is already", status);
if (status.state === "granted") { if (status.state === "granted") {
self.StartGeolocating(false); self.StartGeolocating(forceZoom);
} }
self._permission.setData(status.state); self._permission.setData(status.state);
status.onchange = function () { status.onchange = function () {
@ -243,10 +245,10 @@ export default class GeoLocationHandler extends VariableUiElement {
} }
if (askPermission) { if (askPermission) {
self.StartGeolocating(true); self.StartGeolocating(forceZoom);
} else if (this._previousLocationGrant.data === "granted") { } else if (this._previousLocationGrant.data === "granted") {
this._previousLocationGrant.setData(""); this._previousLocationGrant.setData("");
self.StartGeolocating(false); self.StartGeolocating(forceZoom);
} }
} }

View file

@ -10,6 +10,7 @@ import Combine from "../../UI/Base/Combine";
export class QueryParameters { export class QueryParameters {
private static order: string [] = ["layout", "test", "z", "lat", "lon"]; private static order: string [] = ["layout", "test", "z", "lat", "lon"];
private static _wasInitialized: Set<string> = new Set()
private static knownSources = {}; private static knownSources = {};
private static initialized = false; private static initialized = false;
private static defaults = {} private static defaults = {}
@ -91,6 +92,7 @@ export class QueryParameters {
const kv = param.split("="); const kv = param.split("=");
const key = decodeURIComponent(kv[0]); const key = decodeURIComponent(kv[0]);
QueryParameters.addOrder(key) QueryParameters.addOrder(key)
QueryParameters._wasInitialized.add(key)
const v = decodeURIComponent(kv[1]); const v = decodeURIComponent(kv[1]);
const source = new UIEventSource<string>(v); const source = new UIEventSource<string>(v);
source.addCallback(() => QueryParameters.Serialize()) source.addCallback(() => QueryParameters.Serialize())
@ -102,6 +104,10 @@ export class QueryParameters {
console.log(QueryParameters.GenerateQueryParameterDocs()) console.log(QueryParameters.GenerateQueryParameterDocs())
} }
} }
public static wasInitialized(key: string) : boolean{
return QueryParameters._wasInitialized.has(key)
}
private static Serialize() { private static Serialize() {
const parts = [] const parts = []

View file

@ -2,7 +2,7 @@ import { Utils } from "../Utils";
export default class Constants { export default class Constants {
public static vNumber = "0.9.2"; public static vNumber = "0.9.3";
// The user journey states thresholds when a new feature gets unlocked // The user journey states thresholds when a new feature gets unlocked
public static userJourney = { public static userJourney = {