comparison client/src/map/Maplayer.vue @ 1020:e89be4af3a9f

restructure surveyrequest
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 24 Oct 2018 10:56:41 +0200
parents ca628dce90dd
children 74229d9f7028
comparison
equal deleted inserted replaced
1019:ca628dce90dd 1020:e89be4af3a9f
40 */ 40 */
41 import { HTTP } from "../application/lib/http"; 41 import { HTTP } from "../application/lib/http";
42 import { mapGetters, mapState } from "vuex"; 42 import { mapGetters, mapState } from "vuex";
43 import "ol/ol.css"; 43 import "ol/ol.css";
44 import { Map, View } from "ol"; 44 import { Map, View } from "ol";
45 import Feature from "ol/Feature";
46 import { WFS, GeoJSON } from "ol/format.js"; 45 import { WFS, GeoJSON } from "ol/format.js";
47 import LineString from "ol/geom/LineString.js"; 46 import LineString from "ol/geom/LineString.js";
48 import Point from "ol/geom/Point.js"; 47 import Point from "ol/geom/Point.js";
49 import Draw from "ol/interaction/Draw.js"; 48 import Draw from "ol/interaction/Draw.js";
50 import { Vector as VectorLayer } from "ol/layer.js"; 49 import { Vector as VectorLayer } from "ol/layer.js";
51 import { Vector as VectorSource } from "ol/source.js"; 50 import { Vector as VectorSource } from "ol/source.js";
52 import { getLength } from "ol/sphere.js"; 51 import { getLength } from "ol/sphere.js";
53 import { Icon, Stroke, Style, Fill } from "ol/style.js"; 52 import { Icon, Stroke, Style, Fill } from "ol/style.js";
53 import { generateFeatureRequest } from "../application/lib/geo.js";
54 54
55 import distance from "@turf/distance"; 55 import distance from "@turf/distance";
56 import { 56 import {
57 lineString as turfLineString, 57 lineString as turfLineString,
58 polygon as turfPolygon 58 polygon as turfPolygon
169 // if a survey has been selected, request a profile 169 // if a survey has been selected, request a profile
170 // TODO an improvement could be to check if the line intersects 170 // TODO an improvement could be to check if the line intersects
171 // with the bottleneck area's polygon before trying the server request 171 // with the bottleneck area's polygon before trying the server request
172 if (this.selectedMorph) { 172 if (this.selectedMorph) {
173 console.log("requesting profile for", this.selectedMorph); 173 console.log("requesting profile for", this.selectedMorph);
174 this.requestProfile(event, this.selectedMorph); 174 const inputLineString = event.feature.getGeometry().clone();
175 } 175 inputLineString.transform("EPSG:3857", "EPSG:4326");
176 }, 176 const [start, end] = inputLineString.getCoordinates();
177 requestProfile(event, survey) { 177 this.$store.commit("fairwayprofile/setStartPoint", start);
178 this.$store.commit("fairwayprofile/setEndPoint", end);
179 this.requestProfile(start, end, this.selectedMorph);
180 }
181 },
182 requestProfile(start, end, survey) {
178 // survey has to have the properties bottleneck_id and date_info 183 // survey has to have the properties bottleneck_id and date_info
179
180 // prepare to send the first line seqment to the server as GeoJSON 184 // prepare to send the first line seqment to the server as GeoJSON
181 const inputLineString = event.feature.getGeometry().clone();
182 inputLineString.transform("EPSG:3857", "EPSG:4326");
183 const [start, end] = inputLineString.getCoordinates();
184 this.$store.commit("fairwayprofile/setStartPoint", start);
185 this.$store.commit("fairwayprofile/setEndPoint", end);
186 const profileLine = new LineString([start, end]); 185 const profileLine = new LineString([start, end]);
187 const feature = new Feature({ 186 const geoJSON = generateFeatureRequest(profileLine, survey);
188 geometry: profileLine, 187 HTTP.post("/cross", geoJSON, {
189 bottleneck: survey.bottleneck_id, 188 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
190 date: survey.date_info 189 })
191 }); 190 .then(response => {
192 const geoJSON = new GeoJSON({ geometryName: "geometry" }).writeFeature( 191 this.$store.commit("fairwayprofile/profileLoaded", response);
193 feature 192 })
194 );
195 this.$store
196 .dispatch("fairwayprofile/loadProfile", geoJSON)
197 .then(() => { 193 .then(() => {
198 var vectorSource = this.getLayerByName( 194 var vectorSource = this.getLayerByName(
199 "Fairway Dimensions" 195 "Fairway Dimensions"
200 ).data.getSource(); 196 ).data.getSource();
201 vectorSource.forEachFeatureIntersectingExtent( 197 vectorSource.forEachFeatureIntersectingExtent(