Mercurial > gemma
changeset 1028:dd67e46366ef
refac: loading of profile data via fairwayprofile store
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Wed, 24 Oct 2018 14:42:04 +0200 |
parents | 04a9e78dcc5f |
children | 1fdeb9404afb |
files | client/src/application/lib/geo.js client/src/fairway/store.js client/src/map/Maplayer.vue |
diffstat | 3 files changed, 51 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/application/lib/geo.js Wed Oct 24 14:17:51 2018 +0200 +++ b/client/src/application/lib/geo.js Wed Oct 24 14:42:04 2018 +0200 @@ -163,11 +163,11 @@ }; }; -const generateFeatureRequest = (profileLine, survey) => { +const generateFeatureRequest = (profileLine, bottleneck_id, date_info) => { const feature = new Feature({ geometry: profileLine, - bottleneck: survey.bottleneck_id, - date: survey.date_info + bottleneck: bottleneck_id, + date: date_info }); return new GeoJSON({ geometryName: "geometry" }).writeFeature(feature); };
--- a/client/src/fairway/store.js Wed Oct 24 14:17:51 2018 +0200 +++ b/client/src/fairway/store.js Wed Oct 24 14:42:04 2018 +0200 @@ -12,8 +12,10 @@ * Author(s): * Thomas Junk <thomas.junk@intevation.de> */ - +import { HTTP } from "../application/lib/http"; import { prepareProfile } from "../application/lib/geo"; +import LineString from "ol/geom/LineString.js"; +import { generateFeatureRequest } from "../application/lib/geo.js"; const DEMOLEVEL = 149.345; @@ -73,6 +75,32 @@ clearCurrentProfile: state => { state.currentProfile = {}; } + }, + actions: { + loadProfile({ commit, state }, date_info) { + return new Promise((resolve, reject) => { + const profileLine = new LineString([state.startPoint, state.endPoint]); + const geoJSON = generateFeatureRequest( + profileLine, + state.selectedMorph.bottleneck_id, + date_info + ); + HTTP.post("/cross", geoJSON, { + headers: { "X-Gemma-Auth": localStorage.getItem("token") } + }) + .then(response => { + commit("profileLoaded", { + response: response, + surveyDate: date_info + }); + resolve(response); + }) + .catch(error => { + commit("clear_auth"); + reject(error); + }); + }); + } } };
--- a/client/src/map/Maplayer.vue Wed Oct 24 14:17:51 2018 +0200 +++ b/client/src/map/Maplayer.vue Wed Oct 24 14:42:04 2018 +0200 @@ -50,7 +50,6 @@ import { Vector as VectorSource } from "ol/source.js"; import { getLength } from "ol/sphere.js"; import { Icon, Stroke, Style, Fill } from "ol/style.js"; -import { generateFeatureRequest } from "../application/lib/geo.js"; import distance from "@turf/distance"; import { @@ -176,39 +175,26 @@ const [start, end] = inputLineString.getCoordinates(); this.$store.commit("fairwayprofile/setStartPoint", start); this.$store.commit("fairwayprofile/setEndPoint", end); - this.requestProfile(start, end, this.selectedMorph); - } - }, - requestProfile(start, end, survey) { - // survey has to have the properties bottleneck_id and date_info - // prepare to send the first line seqment to the server as GeoJSON - const profileLine = new LineString([start, end]); - const geoJSON = generateFeatureRequest(profileLine, survey); - HTTP.post("/cross", geoJSON, { - headers: { "X-Gemma-Auth": localStorage.getItem("token") } - }) - .then(response => { - this.$store.commit("fairwayprofile/profileLoaded", { - response: response, - surveyDate: survey.date_info + const profileLine = new LineString([start, end]); + this.$store + .dispatch("fairwayprofile/loadProfile", this.selectedMorph.date_info) + .then(() => { + var vectorSource = this.getLayerByName( + "Fairway Dimensions" + ).data.getSource(); + this.calculateIntersection(vectorSource, profileLine); + }) + .then(() => { + this.$store.commit("application/openSplitScreen"); + }) + .catch(error => { + const { status, data } = error.response; + displayError({ + title: "Backend Error", + message: `${status}: ${data.message || data}` + }); }); - }) - .then(() => { - var vectorSource = this.getLayerByName( - "Fairway Dimensions" - ).data.getSource(); - this.calculateIntersection(vectorSource, profileLine); - }) - .then(() => { - this.$store.commit("application/openSplitScreen"); - }) - .catch(error => { - const { status, data } = error.response; - displayError({ - title: "Backend Error", - message: `${status}: ${data.message || data}` - }); - }); + } }, calculateIntersection(vectorSource, profileLine) { const transformedLine = profileLine