Automatically zoom to GPS location if no coordinate is specified in the URL
This commit is contained in:
parent
dad579c895
commit
61b6721342
3 changed files with 17 additions and 9 deletions
|
@ -6,6 +6,7 @@ import {LocalStorageSource} from "../Web/LocalStorageSource";
|
|||
import {VariableUiElement} from "../../UI/Base/VariableUIElement";
|
||||
import BaseUIElement from "../../UI/BaseUIElement";
|
||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
|
||||
import {QueryParameters} from "../Web/QueryParameters";
|
||||
|
||||
export default class GeoLocationHandler extends VariableUiElement {
|
||||
/**
|
||||
|
@ -94,8 +95,6 @@ export default class GeoLocationHandler extends VariableUiElement {
|
|||
super(
|
||||
hasLocation.map(
|
||||
(hasLocationData) => {
|
||||
let icon: BaseUIElement;
|
||||
console.log("Determining icon:", permission.data, isActive.data, hasLocationData, isLocked.data, lastClickWithinThreeSecs.data)
|
||||
if (permission.data === "denied") {
|
||||
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 => {
|
||||
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;
|
||||
|
||||
if (self._isActive.data) {
|
||||
|
@ -231,7 +233,7 @@ export default class GeoLocationHandler extends VariableUiElement {
|
|||
?.then(function (status) {
|
||||
console.log("Geolocation is already", status);
|
||||
if (status.state === "granted") {
|
||||
self.StartGeolocating(false);
|
||||
self.StartGeolocating(forceZoom);
|
||||
}
|
||||
self._permission.setData(status.state);
|
||||
status.onchange = function () {
|
||||
|
@ -243,10 +245,10 @@ export default class GeoLocationHandler extends VariableUiElement {
|
|||
}
|
||||
|
||||
if (askPermission) {
|
||||
self.StartGeolocating(true);
|
||||
self.StartGeolocating(forceZoom);
|
||||
} else if (this._previousLocationGrant.data === "granted") {
|
||||
this._previousLocationGrant.setData("");
|
||||
self.StartGeolocating(false);
|
||||
self.StartGeolocating(forceZoom);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import Combine from "../../UI/Base/Combine";
|
|||
export class QueryParameters {
|
||||
|
||||
private static order: string [] = ["layout", "test", "z", "lat", "lon"];
|
||||
private static _wasInitialized: Set<string> = new Set()
|
||||
private static knownSources = {};
|
||||
private static initialized = false;
|
||||
private static defaults = {}
|
||||
|
@ -91,6 +92,7 @@ export class QueryParameters {
|
|||
const kv = param.split("=");
|
||||
const key = decodeURIComponent(kv[0]);
|
||||
QueryParameters.addOrder(key)
|
||||
QueryParameters._wasInitialized.add(key)
|
||||
const v = decodeURIComponent(kv[1]);
|
||||
const source = new UIEventSource<string>(v);
|
||||
source.addCallback(() => QueryParameters.Serialize())
|
||||
|
@ -102,6 +104,10 @@ export class QueryParameters {
|
|||
console.log(QueryParameters.GenerateQueryParameterDocs())
|
||||
}
|
||||
}
|
||||
|
||||
public static wasInitialized(key: string) : boolean{
|
||||
return QueryParameters._wasInitialized.has(key)
|
||||
}
|
||||
|
||||
private static Serialize() {
|
||||
const parts = []
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Utils } from "../Utils";
|
|||
|
||||
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
|
||||
public static userJourney = {
|
||||
|
|
Loading…
Reference in a new issue