forked from MapComplete/MapComplete
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue