simplify application and remove window references
Sonarqube Scanner / Build and analyze (push) Failing after 1m27s
Sonarqube Scanner / Build and analyze (push) Failing after 1m27s
This commit is contained in:
+26
-14
@@ -1,8 +1,17 @@
|
||||
(function (ns) {
|
||||
'use strict';
|
||||
|
||||
const WATCH_OPTIONS = Object.freeze({
|
||||
enableHighAccuracy: true,
|
||||
timeout: 20000,
|
||||
maximumAge: 5000
|
||||
});
|
||||
let watchId = null;
|
||||
|
||||
function geolocation() {
|
||||
return globalThis.navigator?.geolocation;
|
||||
}
|
||||
|
||||
function normalize(position) {
|
||||
return {
|
||||
lat: position.coords.latitude,
|
||||
@@ -15,19 +24,24 @@
|
||||
};
|
||||
}
|
||||
|
||||
function unsupportedError() {
|
||||
return new Error('Dieses Gerät unterstützt keine Geolokalisierung.');
|
||||
}
|
||||
|
||||
ns.Geo = {
|
||||
current() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!navigator.geolocation) {
|
||||
reject(new Error('Dieses Gerät unterstützt keine Geolokalisierung.'));
|
||||
const service = geolocation();
|
||||
if (!service) {
|
||||
reject(unsupportedError());
|
||||
return;
|
||||
}
|
||||
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
service.getCurrentPosition(
|
||||
position => resolve(normalize(position)),
|
||||
reject,
|
||||
{
|
||||
enableHighAccuracy: true,
|
||||
...WATCH_OPTIONS,
|
||||
timeout: ns.Config.geolocationTimeoutMs,
|
||||
maximumAge: 30000
|
||||
}
|
||||
@@ -37,25 +51,23 @@
|
||||
|
||||
start(callback, onError) {
|
||||
this.stop();
|
||||
if (!navigator.geolocation) {
|
||||
onError?.(new Error('Dieses Gerät unterstützt keine Geolokalisierung.'));
|
||||
const service = geolocation();
|
||||
if (!service) {
|
||||
onError?.(unsupportedError());
|
||||
return;
|
||||
}
|
||||
|
||||
watchId = navigator.geolocation.watchPosition(
|
||||
watchId = service.watchPosition(
|
||||
position => callback(normalize(position)),
|
||||
onError,
|
||||
{
|
||||
enableHighAccuracy: true,
|
||||
timeout: 20000,
|
||||
maximumAge: 5000
|
||||
}
|
||||
WATCH_OPTIONS
|
||||
);
|
||||
},
|
||||
|
||||
stop() {
|
||||
if (watchId != null) navigator.geolocation.clearWatch(watchId);
|
||||
const service = geolocation();
|
||||
if (watchId != null) service?.clearWatch(watchId);
|
||||
watchId = null;
|
||||
}
|
||||
};
|
||||
}(window.Wegwichtel));
|
||||
}(globalThis.Wegwichtel));
|
||||
|
||||
Reference in New Issue
Block a user