From 009b6fe5ce753fb6d544a4e412d60dd38d40409e Mon Sep 17 00:00:00 2001 From: Pavel Zubkov Date: Sun, 1 Oct 2023 00:57:46 +0300 Subject: [PATCH] $mol_geo_position: Added --- geo/position/position.ts | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 geo/position/position.ts diff --git a/geo/position/position.ts b/geo/position/position.ts new file mode 100644 index 00000000000..f82527b1540 --- /dev/null +++ b/geo/position/position.ts @@ -0,0 +1,65 @@ +namespace $ { + + export class $mol_geo_position extends $mol_object { + + options() { + return { enableHighAccuracy: true } + } + + @ $mol_mem + watcher() { + const id = this.$.$mol_dom_context.navigator.geolocation.watchPosition( + $mol_wire_async( (val: GeolocationPosition) => this.value(val) ), + $mol_wire_async( (error: GeolocationPositionError) => this.error(error) ), + this.options(), + ) + + return { destructor: () => this.$.$mol_dom_context.navigator.geolocation.clearWatch(id) } + } + + @ $mol_mem + value(next?: GeolocationPosition) { + this.watcher() + return next ?? null + } + + @ $mol_mem + error(next?: GeolocationPositionError) { + return next ?? null + } + + accuracy() { + return this.value()?.coords?.accuracy + } + + altitude() { + return this.value()?.coords?.altitude + } + + altitudeAccuracy() { + return this.value()?.coords?.altitudeAccuracy + } + + heading() { + return this.value()?.coords?.heading + } + + latitude() { + return this.value()?.coords?.latitude + } + + longitude() { + return this.value()?.coords?.longitude + } + + speed() { + return this.value()?.coords?.speed + } + + timestamp() { + return this.value()?.timestamp + } + + } + +}