From 1cf966e3b170386e90b37ece549b1022b46723ba Mon Sep 17 00:00:00 2001 From: Manuel Garcia Date: Tue, 6 Aug 2024 17:32:50 +0200 Subject: [PATCH] refactor: Rename useMapViewStore to useAnswerMapViewStore --- frontend/stores/answerMapview.js | 47 +++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/frontend/stores/answerMapview.js b/frontend/stores/answerMapview.js index 611b9f32..97166e16 100644 --- a/frontend/stores/answerMapview.js +++ b/frontend/stores/answerMapview.js @@ -9,7 +9,7 @@ import { useGlobalStore } from './global' import { da, el, th } from 'vuetify/locale'; -export const useMapViewStore = defineStore('answerMapView', { +export const useAnswerMapViewStore = defineStore('answerMapView', { state: () => ({ id: null, url: null, @@ -93,9 +93,6 @@ export const useMapViewStore = defineStore('answerMapView', { throw new Error('Unsupported geometry type //> ', feature.geometry.type) } - // console.log('feature geometry //> ', feature.geometry) - - const {data, error, pending } = await useAsyncData( () => $cmsApi(feature_endpoint, { method: 'POST', headers: {'Content-Type': 'application/json'}, @@ -118,6 +115,46 @@ export const useMapViewStore = defineStore('answerMapView', { return this.location }, + async updateLocations(){ + /** + * Updates locations using the geometries in state.geometries + * + * returns new state of location. + */ + // create the location collection, if there are geometries + + this.geometries.features.forEach( async (feature) => { + + var feature_endpoint; + if (feature.geometry.type === "Point"){ + feature_endpoint = `/pointfeatures/`; + } else if (feature.geometry.type === "LineString") { + feature_endpoint = `/linefeatures/`; + } else if (feature.geometry.type === "Polygon") { + feature_endpoint = `/polygonfeatures/` + } else { + throw new Error('Unsupported geometry type //> ', feature.geometry.type) + } + + const {data, error, pending } = await useAsyncData( () => $cmsApi(feature_endpoint, + { method: 'PUT', + headers: {'Content-Type': 'application/json'}, + body: { + geom: feature.geometry, + annotation: 'created from mapview store', + location: this.location + } + } + )); + + if (error.value) { + throw new Error('Error creating feature //> ', error.value) + } + }) + + return this.location + }, + async createMapview() { /** * Create a new mapview in the backend with the current state of the store @@ -178,6 +215,8 @@ export const useMapViewStore = defineStore('answerMapView', { } }) + // CONTINUE HERE, approach the issue of updating the location starting from here the updateMapview (below). Update the mapview instead of updating the location if possible. + // TODO: modify to update locations and geometries const { data, error, refresh } = await useAsyncData( () => $cmsApi(`${mapview_url}`, config)); if (error.value) {