From 332e64c9ab770f8192cce6cdee804b130976febb Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Sat, 4 Apr 2026 02:32:09 +0000 Subject: [PATCH] Add basic location store for getting geoposition --- ts/rmo/content/Nuisance.vue | 14 +++++++++++++- ts/store/location.ts | 35 +++++++++++++++++++++++++++++++++++ ts/type/map.ts | 16 ++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 ts/store/location.ts create mode 100644 ts/type/map.ts diff --git a/ts/rmo/content/Nuisance.vue b/ts/rmo/content/Nuisance.vue index 7bc4ba9a..2814a05b 100644 --- a/ts/rmo/content/Nuisance.vue +++ b/ts/rmo/content/Nuisance.vue @@ -499,10 +499,11 @@ select.tall { diff --git a/ts/store/location.ts b/ts/store/location.ts new file mode 100644 index 00000000..a20e569f --- /dev/null +++ b/ts/store/location.ts @@ -0,0 +1,35 @@ +import { defineStore } from "pinia"; + +interface GeolocationOptions { + maximumAge?: number; + timeout?: number; + enableHighAccuracy?: boolean; +} +export const useLocationStore = defineStore("location", () => { + function get(options?: GeolocationOptions): Promise { + return new Promise((resolve, reject) => { + // Check if geolocation is supported by the browser + if (!navigator.geolocation) { + reject(new Error("Geolocation is not supported by your browser")); + return; + } + + // Default options if none provided + const geolocationOptions = options || { + enableHighAccuracy: true, + timeout: 5000, + maximumAge: 0, + }; + + // Call the geolocation API + navigator.geolocation.getCurrentPosition( + (position) => resolve(position), + (error) => reject(error), + geolocationOptions, + ); + }); + } + return { + get, + }; +}); diff --git a/ts/type/map.ts b/ts/type/map.ts new file mode 100644 index 00000000..1f83aa8a --- /dev/null +++ b/ts/type/map.ts @@ -0,0 +1,16 @@ +import maplibregl from "maplibre-gl"; +import type { Location } from "@/types"; + +export interface Camera { + location: Location; + zoom: number; +} + +export type MoveEndEventInternal = maplibregl.MapLibreEvent< + | maplibregl.MapMouseEvent + | maplibregl.MapTouchEvent + | maplibregl.MapWheelEvent + | undefined +> & { + isInternalUpdate: boolean; +};