diff --git a/src/api/util.js b/src/api/util.js new file mode 100644 index 0000000..97f178e --- /dev/null +++ b/src/api/util.js @@ -0,0 +1,8 @@ +export const isLnglat = lnglat => { + const { lng, lat } = lnglat + + if (isNaN(lng) || lng > 180 || lng < -180) return false + if (isNaN(lat) || lat > 90 || lat < -90 ) return false + + return true +} \ No newline at end of file diff --git a/src/components/LocatingPoint.vue b/src/components/LocatingPoint.vue index b798522..a12a89a 100644 --- a/src/components/LocatingPoint.vue +++ b/src/components/LocatingPoint.vue @@ -1,7 +1,11 @@ \ No newline at end of file diff --git a/src/components/LonlatForm.vue b/src/components/LonlatForm.vue index 88ac9ed..23e5c9b 100644 --- a/src/components/LonlatForm.vue +++ b/src/components/LonlatForm.vue @@ -1,24 +1,34 @@ \ No newline at end of file diff --git a/src/stores/position.js b/src/stores/position.js new file mode 100644 index 0000000..434ab9d --- /dev/null +++ b/src/stores/position.js @@ -0,0 +1,24 @@ +import { defineStore } from 'pinia' +import { isLnglat } from '/@/api/util' + + +export const usePositionStore = defineStore({ + id: 'position', + state: () => ({ + lng: NaN, + lat: NaN, + }), + getters: { + value: (state) => { state.lng, state.lat } + }, + actions: { + set(position) { + if ( !isLnglat(position) ) return false + + this.lng = position.lng + this.lat = position.lat + + return true + }, + }, +})