Mercurial > gemma
changeset 1020:e89be4af3a9f
restructure surveyrequest
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Wed, 24 Oct 2018 10:56:41 +0200 |
parents | ca628dce90dd |
children | 957613a71b35 |
files | client/src/application/lib/geo.js client/src/fairway/store.js client/src/map/Maplayer.vue |
diffstat | 3 files changed, 28 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/application/lib/geo.js Wed Oct 24 09:42:32 2018 +0200 +++ b/client/src/application/lib/geo.js Wed Oct 24 10:56:41 2018 +0200 @@ -20,6 +20,9 @@ * */ +import { GeoJSON } from "ol/format.js"; +import Feature from "ol/Feature"; + const EARTHRADIUS = 6378137.0; /** @@ -160,4 +163,13 @@ }; }; -export { prepareProfile }; +const generateFeatureRequest = (profileLine, survey) => { + const feature = new Feature({ + geometry: profileLine, + bottleneck: survey.bottleneck_id, + date: survey.date_info + }); + return new GeoJSON({ geometryName: "geometry" }).writeFeature(feature); +}; + +export { generateFeatureRequest, prepareProfile };
--- a/client/src/fairway/store.js Wed Oct 24 09:42:32 2018 +0200 +++ b/client/src/fairway/store.js Wed Oct 24 10:56:41 2018 +0200 @@ -13,7 +13,6 @@ * Thomas Junk <thomas.junk@intevation.de> */ -import { HTTP } from "../application/lib/http"; import { prepareProfile } from "../application/lib/geo"; const DEMOLEVEL = 149.345; @@ -69,23 +68,6 @@ clearCurrentProfile: state => { state.currentProfile = []; } - }, - - actions: { - loadProfile({ commit }, geoJSON) { - return new Promise((resolve, reject) => { - HTTP.post("/cross", geoJSON, { - headers: { "X-Gemma-Auth": localStorage.getItem("token") } - }) - .then(response => { - commit("profileLoaded", response); - resolve(response); - }) - .catch(error => { - reject(error); - }); - }); - } } };
--- a/client/src/map/Maplayer.vue Wed Oct 24 09:42:32 2018 +0200 +++ b/client/src/map/Maplayer.vue Wed Oct 24 10:56:41 2018 +0200 @@ -42,7 +42,6 @@ import { mapGetters, mapState } from "vuex"; import "ol/ol.css"; import { Map, View } from "ol"; -import Feature from "ol/Feature"; import { WFS, GeoJSON } from "ol/format.js"; import LineString from "ol/geom/LineString.js"; import Point from "ol/geom/Point.js"; @@ -51,6 +50,7 @@ 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 { @@ -171,29 +171,25 @@ // with the bottleneck area's polygon before trying the server request if (this.selectedMorph) { console.log("requesting profile for", this.selectedMorph); - this.requestProfile(event, this.selectedMorph); + const inputLineString = event.feature.getGeometry().clone(); + inputLineString.transform("EPSG:3857", "EPSG:4326"); + const [start, end] = inputLineString.getCoordinates(); + this.$store.commit("fairwayprofile/setStartPoint", start); + this.$store.commit("fairwayprofile/setEndPoint", end); + this.requestProfile(start, end, this.selectedMorph); } }, - requestProfile(event, survey) { + 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 inputLineString = event.feature.getGeometry().clone(); - inputLineString.transform("EPSG:3857", "EPSG:4326"); - const [start, end] = inputLineString.getCoordinates(); - this.$store.commit("fairwayprofile/setStartPoint", start); - this.$store.commit("fairwayprofile/setEndPoint", end); const profileLine = new LineString([start, end]); - const feature = new Feature({ - geometry: profileLine, - bottleneck: survey.bottleneck_id, - date: survey.date_info - }); - const geoJSON = new GeoJSON({ geometryName: "geometry" }).writeFeature( - feature - ); - this.$store - .dispatch("fairwayprofile/loadProfile", geoJSON) + const geoJSON = generateFeatureRequest(profileLine, survey); + HTTP.post("/cross", geoJSON, { + headers: { "X-Gemma-Auth": localStorage.getItem("token") } + }) + .then(response => { + this.$store.commit("fairwayprofile/profileLoaded", response); + }) .then(() => { var vectorSource = this.getLayerByName( "Fairway Dimensions"