Mercurial > gemma
changeset 754:105c421f99b1
refac: small improvements to code structure
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 24 Sep 2018 17:30:55 +0200 |
parents | e6f8d58434f4 |
children | 1a1a8b5f2d02 |
files | client/src/map/Maplayer.vue client/src/map/store.js |
diffstat | 2 files changed, 68 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/map/Maplayer.vue Mon Sep 24 17:10:18 2018 +0200 +++ b/client/src/map/Maplayer.vue Mon Sep 24 17:30:55 2018 +0200 @@ -16,12 +16,11 @@ import { HTTP } from "../application/lib/http"; import { mapGetters } from "vuex"; import "ol/ol.css"; -// openlayers imports, sorted by module name import { Map, View } from "ol"; import Feature from "ol/Feature"; // import { bbox as bboxFilter } from "ol/format/filter.js"; import { WFS, GeoJSON } from "ol/format.js"; -import GeometryType from "ol/geom/GeometryType.js"; +// import GeometryType from "ol/geom/GeometryType.js"; import LineString from "ol/geom/LineString.js"; import Draw from "ol/interaction/Draw.js"; import { Vector as VectorLayer } from "ol/layer.js"; @@ -48,7 +47,7 @@ }; }, computed: { - ...mapGetters("mapstore", ["layers"]), + ...mapGetters("mapstore", ["layers", "getLayerByName"]), mapStyle() { return { mapfull: !this.split, @@ -88,68 +87,68 @@ draw.on("drawend", this.drawEnd); return draw; }, + findFeature(profileLine) { + return new Feature({ + geometry: profileLine, + // FIXME: hardcoded bottleneck and survey date + bottleneck: "AT_Bottleneck_44", + date: "2017-11-20" + }); + }, drawEnd(event) { - var inputLineString = event.feature.getGeometry().clone(); - if (inputLineString.getType() == GeometryType.LINE_STRING) { - // prepare to send the first line seqment to the server as GeoJSON - inputLineString.transform("EPSG:3857", "EPSG:4326"); - var coords = inputLineString.getCoordinates(); - if (coords.length >= 2) { - var profileLine = new LineString([coords[0], coords[1]]); - var feature = new Feature({ - geometry: profileLine, - // FIXME: hardcoded bottleneck and survey date - bottleneck: "AT_Bottleneck_44", - date: "2017-11-20" - }); - var gStr = new GeoJSON({ geometryName: "geometry" }).writeFeature( - feature - ); - console.log("Ready to start profile view with: ", feature, gStr); - - // FIXME: assuming that we have the fairway dimensions loaded - var vectorSource = this.getLayerByName( - "Fairway Dimensions" - ).data.getSource(); - console.log(vectorSource); + const inputLineString = event.feature.getGeometry().clone(); + // prepare to send the first line seqment to the server as GeoJSON + inputLineString.transform("EPSG:3857", "EPSG:4326"); + const [start, end] = inputLineString.getCoordinates(); + const profileLine = new LineString([start, end]); + const feature = this.findFeature(profileLine); + const geoJSON = new GeoJSON({ geometryName: "geometry" }).writeFeature( + feature + ); + console.log("Feature: ", feature); + console.log("geoJSON", geoJSON); - var diagStack = []; - vectorSource.forEachFeatureIntersectingExtent( - // need to use EPSG:3857 which is the proj of vectorSource - profileLine - .clone() - .transform("EPSG:4326", "EPSG:3857") - .getExtent(), - feature => { - // transform back to prepare for usage - var intersectingPolygon = feature - .getGeometry() - .clone() - .transform("EPSG:3857", "EPSG:4326"); - console.log("intersecting:", intersectingPolygon); - this.addToFairwayRectangle( - profileLine, - intersectingPolygon, - 2.5, // FIXME use real fairway depth value for this feature - diagStack - ); - } - ); - } - } + // // FIXME: assuming that we have the fairway dimensions loaded + // var vectorSource = this.getLayerByName( + // "Fairway Dimensions" + // ).data.getSource(); + // console.log(vectorSource); + + // var diagStack = []; + // vectorSource.forEachFeatureIntersectingExtent( + // // need to use EPSG:3857 which is the proj of vectorSource + // profileLine + // .clone() + // .transform("EPSG:4326", "EPSG:3857") + // .getExtent(), + // feature => { + // // transform back to prepare for usage + // var intersectingPolygon = feature + // .getGeometry() + // .clone() + // .transform("EPSG:3857", "EPSG:4326"); + // console.log("intersecting:", intersectingPolygon); + // this.addToFairwayRectangle( + // profileLine, + // intersectingPolygon, + // 2.5, // FIXME use real fairway depth value for this feature + // diagStack + // ); + // } + // ); }, addToFairwayRectangle(profileLine, fairwayGeometry, depth, diagStack) { // both geometries have to be in EPSG:4326 // uses turfjs distance() function // pushes pairs of diagram points into diagStack - console.log( - "addToFairwayRectangle(", - profileLine, - fairwayGeometry, - depth, - diagStack, - ")" - ); + // console.log( + // "addToFairwayRectangle(", + // profileLine, + // fairwayGeometry, + // depth, + // diagStack, + // ")" + // ); var line = turfLineString(profileLine.getCoordinates()); var polygon = turfPolygon(fairwayGeometry.getCoordinates()); var intersects = lineIntersect(line, polygon); @@ -157,7 +156,7 @@ var l = intersects.features.length; if (l % 2 != 0) { - console.log("Ignoring fairway because profile only intersects once."); + //console.log("Ignoring fairway because profile only intersects once."); } else { for (let i = 0; i < l; i += 2) { let pStartPoint = profileLine.getCoordinates()[0]; @@ -172,7 +171,7 @@ ]); } } - console.log("Resulting diagStack:", diagStack); + //console.log("Resulting diagStack:", diagStack); }, activateInteraction() { const interaction = this.createInteraction(this.drawMode); @@ -207,12 +206,12 @@ JSON.stringify(response.data) ); vectorSource.addFeatures(features); - console.log( - "loaded", - features.length, - featureRequestOptions.featureTypes, - "features" - ); + // console.log( + // "loaded", + // features.length, + // featureRequestOptions.featureTypes, + // "features" + // ); // DEBUG console.log("loaded ", features, "for", vectorSource); // eslint-disable-next-line }) @@ -221,13 +220,6 @@ }); }; return loader; - }, - getLayerByName(name) { - for (let layer of this.layers) { - if (layer.name === name) { - return layer; - } - } } }, watch: {
--- a/client/src/map/store.js Mon Sep 24 17:10:18 2018 +0200 +++ b/client/src/map/store.js Mon Sep 24 17:30:55 2018 +0200 @@ -152,6 +152,9 @@ getters: { layers: state => { return state.layers; + }, + getLayerByName: state => name => { + return state.layers.find(layer => layer.name === name); } }, mutations: {