# HG changeset patch # User Raimund Renkert # Date 1550148834 -3600 # Node ID 627bfcbbf63100fa0eb1c9f1b61bc437aaf6f8e9 # Parent 7efa29d16e770325ab5cc06cc091d7f7cb3dcd20 client: Draw fairway dimensions for all LoS and in more "cut cases". diff -r 7efa29d16e77 -r 627bfcbbf631 client/package.json --- a/client/package.json Thu Feb 14 12:21:25 2019 +0100 +++ b/client/package.json Thu Feb 14 13:53:54 2019 +0100 @@ -25,7 +25,11 @@ "@turf/center": "^6.0.1", "@turf/distance": "^6.0.1", "@turf/helpers": "^6.1.4", + "@turf/line-split": "^5.1.5", + "@turf/line-slice": "^5.1.5", "@turf/line-intersect": "^6.0.2", + "@turf/boolean-within": "^6.0.1", + "@turf/boolean-contains": "^6.0.1", "animate.css": "^3.7.0", "axios": "^0.18.0", "bootstrap": "^4.1.1", diff -r 7efa29d16e77 -r 627bfcbbf631 client/src/components/fairway/Fairwayprofile.vue --- a/client/src/components/fairway/Fairwayprofile.vue Thu Feb 14 12:21:25 2019 +0100 +++ b/client/src/components/fairway/Fairwayprofile.vue Thu Feb 14 13:53:54 2019 +0100 @@ -127,7 +127,7 @@ "additionalSurvey", "minAlt", "maxAlt", - "fairwayCoordinates", + "fairwayData", "waterLevels", "selectedWaterLevel", "profileLoading" @@ -190,7 +190,7 @@ selectedWaterLevel() { this.drawDiagram(); }, - fairwayCoordinates() { + fairwayData() { this.drawDiagram(); } }, @@ -242,8 +242,12 @@ } }, drawFairway({ graph, xScale, yScaleRight }) { - for (let coordinates of this.fairwayCoordinates) { - const [startPoint, endPoint, depth] = coordinates; + if (this.fairwayData === undefined) { + return + } + for (let data of this.fairwayData) { + const [startPoint, endPoint, depth] = data.coordinates[0]; + const style = data.style(); let fairwayArea = d3 .area() .x(function(d) { @@ -257,9 +261,8 @@ .append("path") .datum([{ x: startPoint, y: depth }, { x: endPoint, y: depth }]) .attr("fill", "#002AFF") - .attr("stroke-opacity", 0.65) .attr("fill-opacity", 0.65) - .attr("stroke", "#FFD20D") + .attr("stroke", style[0].getStroke().getColor()) .attr("d", fairwayArea); } }, @@ -334,6 +337,7 @@ graph .append("path") .datum([{ x: 0, y: 0 }, { x: this.totalLength, y: 0 }]) + .attr("fill-opacity", 0.65) .attr("fill", this.waterColor) .attr("stroke", this.waterColor) .attr("d", waterArea); diff -r 7efa29d16e77 -r 627bfcbbf631 client/src/lib/geo.js --- a/client/src/lib/geo.js Thu Feb 14 12:21:25 2019 +0100 +++ b/client/src/lib/geo.js Thu Feb 14 13:53:54 2019 +0100 @@ -26,7 +26,11 @@ lineString as turfLineString, polygon as turfPolygon } from "@turf/helpers"; +import lineSplit from "@turf/line-split"; +import lineSlice from "@turf/line-slice"; import lineIntersect from "@turf/line-intersect"; +import booleanWithin from "@turf/boolean-within"; +import booleanContains from "@turf/boolean-contains"; const EARTHRADIUS = 6378137.0; @@ -184,24 +188,58 @@ var line = turfLineString(profileLine.getCoordinates()); var polygon = turfPolygon(fairwayGeometry.getCoordinates()); var intersects = lineIntersect(line, polygon); - var l = intersects.features.length; - if (l % 2 != 0) { - console.log("Ignoring fairway because profile only intersects once."); + + var startPoint, endPoint + + if (intersects.features.length == 2) { + let line1 = lineSlice(intersects.features[0].geometry, intersects.features[1].geometry, line); + startPoint = line1.geometry.coordinates[0]; + endPoint = line1.geometry.coordinates[1]; + } else if (booleanWithin(line, polygon)) { + startPoint = line.geometry.coordinates[0]; + endPoint = line.geometry.coordinates[1]; } else { - for (let i = 0; i < l; i += 2) { - let pStartPoint = profileLine.getCoordinates()[0]; - let fStartPoint = intersects.features[i].geometry.coordinates; - let fEndPoint = intersects.features[i + 1].geometry.coordinates; - let opts = { units: "kilometers" }; - - fairwayCoordinates.push([ - distance(pStartPoint, fStartPoint, opts) * 1000, - distance(pStartPoint, fEndPoint, opts) * 1000, - depth - ]); + let split = lineSplit(line, polygon); + for (let feature of split.features) { + if (booleanWithin(feature, polygon)){ + startPoint = feature.geometry.coordinates[0]; + endPoint = feature.geometry.coordinates[1]; + } + if (booleanContains(polygon, feature)){ + startPoint = feature.geometry.coordinates[0]; + endPoint = feature.geometry.coordinates[1]; + } } } + + let opts = { units: "kilometers" }; + let pStartPoint = profileLine.getCoordinates()[0]; + fairwayCoordinates.push([ + distance(pStartPoint, startPoint, opts) * 1000, + distance(pStartPoint, endPoint, opts) * 1000, + depth + ]); + return fairwayCoordinates; }; -export { generateFeatureRequest, prepareProfile, calculateFairwayCoordinates }; +const featureToFairwayCoordinates = (feature, profileLine) => { + // need to use EPSG:3857 which is the proj of vectorSource + var intersectingPolygon = feature + .getGeometry() + .clone() + .transform("EPSG:3857", "EPSG:4326"); + const fairwayCoordinates = calculateFairwayCoordinates( + profileLine, + intersectingPolygon, + feature.get("min_depth") ? feature.get("min_depth") / 100 : 2.5 + ); + return fairwayCoordinates; +}; + +export { + generateFeatureRequest, + prepareProfile, + calculateFairwayCoordinates, + featureToFairwayCoordinates +}; diff -r 7efa29d16e77 -r 627bfcbbf631 client/src/store/fairway.js --- a/client/src/store/fairway.js Thu Feb 14 12:21:25 2019 +0100 +++ b/client/src/store/fairway.js Thu Feb 14 13:53:54 2019 +0100 @@ -18,11 +18,10 @@ import LineString from "ol/geom/LineString.js"; import { generateFeatureRequest } from "../lib/geo.js"; import { getLength } from "ol/sphere.js"; -import { calculateFairwayCoordinates } from "../lib/geo.js"; import { displayError } from "../lib/errors.js"; +import { featureToFairwayCoordinates } from "../lib/geo.js"; const DEMOLEVEL = 149.345; -const DEMODATA = 2.5; // initial state const init = () => { @@ -33,7 +32,7 @@ currentProfile: {}, waterLevels: [{ year: "2016", level: DEMOLEVEL, color: "#005DFF" }], selectedWaterLevel: DEMOLEVEL, - fairwayCoordinates: [], + fairwayData: [], startPoint: null, endPoint: null, previousCuts: [], @@ -92,8 +91,11 @@ setEndPoint: (state, end) => { state.endPoint = end; }, - setFairwayCoordinates: (state, coordinates) => { - state.fairwayCoordinates = coordinates; + addFairwayData: (state, coordinates) => { + state.fairwayData.push(coordinates); + }, + clearFairwayData: state => { + state.fairwayData = []; }, clearCurrentProfile: state => { state.additionalSurvey = null; @@ -101,7 +103,7 @@ state.minAlt = null; state.maxAlt = null; state.totalLength = null; - state.fairwayCoordinates = []; + state.fairwayData = []; state.startPoint = null; state.endPoint = null; }, @@ -173,7 +175,7 @@ }, { root: true } ); - + commit("clearFairwayData") // if a survey has been selected, request a profile // TODO an improvement could be to check if the line intersects // with the bottleneck area's polygon before trying the server request @@ -200,30 +202,76 @@ Promise.all(profileLoaders) .then(() => { rootState.map.cutTool.setActive(false); - rootGetters["map/getVSourceByName"]( + const los3 = rootGetters["map/getLayerByName"]( "Fairway Dimensions LOS 3" - ).forEachFeatureIntersectingExtent( - // need to use EPSG:3857 which is the proj of vectorSource + ); + los3.data.getSource().forEachFeatureIntersectingExtent( + profileLine + .clone() + .transform("EPSG:4326", "EPSG:3857") + .getExtent(), + feature => { + const fairwayCoordinates = featureToFairwayCoordinates( + feature, + profileLine + ); + let fairwayData = { + coordinates: fairwayCoordinates, + style: los3.data.getStyle() + }; + if (fairwayCoordinates.length > 0) { + commit("addFairwayData", fairwayData); + commit("application/showSplitscreen", true, { root: true }); + } + } + ); + const los2 = rootGetters["map/getLayerByName"]( + "Fairway Dimensions LOS 2" + ); + los2.data.getSource().forEachFeatureIntersectingExtent( 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"); - const fairwayCoordinates = calculateFairwayCoordinates( - profileLine, - intersectingPolygon, - DEMODATA + let fairwayCoordinates = featureToFairwayCoordinates( + feature, + profileLine ); - commit("setFairwayCoordinates", fairwayCoordinates); - commit("application/showSplitscreen", true, { root: true }); - resolve(); + let fairwayData = { + coordinates: fairwayCoordinates, + style: los2.data.getStyle() + }; + if (fairwayCoordinates.length > 0) { + commit("addFairwayData", fairwayData); + commit("application/showSplitscreen", true, { root: true }); + } } ); + const los1 = rootGetters["map/getLayerByName"]( + "Fairway Dimensions LOS 1" + ); + los1.data.getSource().forEachFeatureIntersectingExtent( + profileLine + .clone() + .transform("EPSG:4326", "EPSG:3857") + .getExtent(), + feature => { + const fairwayCoordinates = featureToFairwayCoordinates( + feature, + profileLine + ); + let fairwayData = { + coordinates: fairwayCoordinates, + style: los1.data.getStyle() + }; + if (fairwayCoordinates.length > 0) { + commit("addFairwayData", fairwayData); + commit("application/showSplitscreen", true, { root: true }); + } + } + ); + resolve(); }) .catch(error => { const { status, data } = error.response; @@ -251,6 +299,6 @@ }) .sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1)) ); - } - } + }, + }, }; diff -r 7efa29d16e77 -r 627bfcbbf631 client/yarn.lock --- a/client/yarn.lock Thu Feb 14 12:21:25 2019 +0100 +++ b/client/yarn.lock Thu Feb 14 13:53:54 2019 +0100 @@ -743,6 +743,60 @@ "@turf/helpers" "6.x" "@turf/meta" "6.x" +"@turf/bbox@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/bbox/-/bbox-5.1.5.tgz#3051df514ad4c50f4a4f9b8a2d15fd8b6840eda3" + integrity sha1-MFHfUUrUxQ9KT5uKLRX9i2hA7aM= + dependencies: + "@turf/helpers" "^5.1.5" + "@turf/meta" "^5.1.5" + +"@turf/bearing@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/bearing/-/bearing-5.1.5.tgz#7a0b790136c4ef4797f0246305d45cbe2d27b3f7" + integrity sha1-egt5ATbE70eX8CRjBdRcvi0ns/c= + dependencies: + "@turf/helpers" "^5.1.5" + "@turf/invariant" "^5.1.5" + +"@turf/boolean-contains@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/@turf/boolean-contains/-/boolean-contains-6.0.1.tgz#c3c583215fc5bda47ede51cf52d735ffdc1006a5" + integrity sha512-usAexEdWu7dV43paowGSFEM0PljexnlOuj09HF/VDZwO3FKelwUovF2ymetYatuG7KcIYcexeNEkQ5qQnGExlw== + dependencies: + "@turf/bbox" "6.x" + "@turf/boolean-point-in-polygon" "6.x" + "@turf/boolean-point-on-line" "6.x" + "@turf/helpers" "6.x" + "@turf/invariant" "6.x" + +"@turf/boolean-point-in-polygon@6.x": + version "6.0.1" + resolved "https://registry.yarnpkg.com/@turf/boolean-point-in-polygon/-/boolean-point-in-polygon-6.0.1.tgz#5836677afd77d2ee391af0056a0c29b660edfa32" + integrity sha512-FKLOZ124vkJhjzNSDcqpwp2NvfnsbYoUOt5iAE7uskt4svix5hcjIEgX9sELFTJpbLGsD1mUbKdfns8tZxcMNg== + dependencies: + "@turf/helpers" "6.x" + "@turf/invariant" "6.x" + +"@turf/boolean-point-on-line@6.x": + version "6.0.1" + resolved "https://registry.yarnpkg.com/@turf/boolean-point-on-line/-/boolean-point-on-line-6.0.1.tgz#d943c242a5fdcde03f8ad0221750fd1aacf06223" + integrity sha512-Vl724Tzh4CF/13kgblOAQnMcHagromCP1EfyJ9G/8SxpSoTYeY2G6FmmcpbW51GqKxC7xgM9+Pck50dun7oYkg== + dependencies: + "@turf/helpers" "6.x" + "@turf/invariant" "6.x" + +"@turf/boolean-within@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/@turf/boolean-within/-/boolean-within-6.0.1.tgz#eac2ebe4962e840dd16f0dc56486469eeb92975f" + integrity sha512-fAzDoWzA4UvUE99G8VqQjVg+PSrPBACM9+SLcl0vkbxIhTjoknpTUwSfH86EgKiCkTDttiDIs/q27xZ4H+mgLQ== + dependencies: + "@turf/bbox" "6.x" + "@turf/boolean-point-in-polygon" "6.x" + "@turf/boolean-point-on-line" "6.x" + "@turf/helpers" "6.x" + "@turf/invariant" "6.x" + "@turf/center@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/@turf/center/-/center-6.0.1.tgz#40a17d0a170df5bba09ad93e133b904d8eb14601" @@ -751,6 +805,22 @@ "@turf/bbox" "6.x" "@turf/helpers" "6.x" +"@turf/destination@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/destination/-/destination-5.1.5.tgz#ed35381bdce83bbddcbd07a2e2bce2bddffbcc26" + integrity sha1-7TU4G9zoO73cvQei4rzivd/7zCY= + dependencies: + "@turf/helpers" "^5.1.5" + "@turf/invariant" "^5.1.5" + +"@turf/distance@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/distance/-/distance-5.1.5.tgz#39cf18204bbf87587d707e609a60118909156409" + integrity sha1-Oc8YIEu/h1h9cH5gmmARiQkVZAk= + dependencies: + "@turf/helpers" "^5.1.5" + "@turf/invariant" "^5.1.5" + "@turf/distance@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/@turf/distance/-/distance-6.0.1.tgz#0761f28784286e7865a427c4e7e3593569c2dea8" @@ -759,11 +829,16 @@ "@turf/helpers" "6.x" "@turf/invariant" "6.x" -"@turf/helpers@6.x", "@turf/helpers@^6.1.4": +"@turf/helpers@*", "@turf/helpers@6.x", "@turf/helpers@^6.1.4": version "6.1.4" resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-6.1.4.tgz#d6fd7ebe6782dd9c87dca5559bda5c48ae4c3836" integrity sha512-vJvrdOZy1ngC7r3MDA7zIGSoIgyrkWcGnNIEaqn/APmw+bVLF2gAW7HIsdTxd12s5wQMqEpqIQrmrbRRZ0xC7g== +"@turf/helpers@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-5.1.5.tgz#153405227ab933d004a5bb9641a9ed999fcbe0cf" + integrity sha1-FTQFInq5M9AEpbuWQantmZ/L4M8= + "@turf/invariant@6.x": version "6.1.2" resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-6.1.2.tgz#6013ed6219f9ac2edada9b31e1dfa5918eb0a2f7" @@ -771,6 +846,24 @@ dependencies: "@turf/helpers" "6.x" +"@turf/invariant@^5.1.5": + version "5.2.0" + resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-5.2.0.tgz#f0150ff7290b38577b73d088b7932c1ee0aa90a7" + integrity sha1-8BUP9ykLOFd7c9CIt5MsHuCqkKc= + dependencies: + "@turf/helpers" "^5.1.5" + +"@turf/line-intersect@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/line-intersect/-/line-intersect-5.1.5.tgz#0e29071ae403295e491723bc49f5cfac8d11ddf3" + integrity sha1-DikHGuQDKV5JFyO8SfXPrI0R3fM= + dependencies: + "@turf/helpers" "^5.1.5" + "@turf/invariant" "^5.1.5" + "@turf/line-segment" "^5.1.5" + "@turf/meta" "^5.1.5" + geojson-rbush "2.1.0" + "@turf/line-intersect@^6.0.2": version "6.0.2" resolved "https://registry.yarnpkg.com/@turf/line-intersect/-/line-intersect-6.0.2.tgz#b45b7a4e7e08c39a0e4e91099580ed377ef7335f" @@ -791,13 +884,83 @@ "@turf/invariant" "6.x" "@turf/meta" "6.x" -"@turf/meta@6.x": +"@turf/line-segment@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/line-segment/-/line-segment-5.1.5.tgz#3207aaee546ab24c3d8dc3cc63f91c770b8013e5" + integrity sha1-Mgeq7lRqskw9jcPMY/kcdwuAE+U= + dependencies: + "@turf/helpers" "^5.1.5" + "@turf/invariant" "^5.1.5" + "@turf/meta" "^5.1.5" + +"@turf/line-slice@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/line-slice/-/line-slice-5.1.5.tgz#1ecfce1462a378579754cedf4464cde26829f2b5" + integrity sha1-Hs/OFGKjeFeXVM7fRGTN4mgp8rU= + dependencies: + "@turf/helpers" "^5.1.5" + "@turf/invariant" "^5.1.5" + "@turf/nearest-point-on-line" "^5.1.5" + +"@turf/line-split@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/line-split/-/line-split-5.1.5.tgz#5b2df4c37619b72ef725b5163cf9926d5540acb7" + integrity sha1-Wy30w3YZty73JbUWPPmSbVVArLc= + dependencies: + "@turf/bbox" "^5.1.5" + "@turf/helpers" "^5.1.5" + "@turf/invariant" "^5.1.5" + "@turf/line-intersect" "^5.1.5" + "@turf/line-segment" "^5.1.5" + "@turf/meta" "^5.1.5" + "@turf/nearest-point-on-line" "^5.1.5" + "@turf/square" "^5.1.5" + "@turf/truncate" "^5.1.5" + geojson-rbush "2.1.0" + +"@turf/meta@*", "@turf/meta@6.x": version "6.0.2" resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-6.0.2.tgz#eb92951126d24a613ac1b7b99d733fcc20fd30cf" integrity sha512-VA7HJkx7qF1l3+GNGkDVn2oXy4+QoLP6LktXAaZKjuT1JI0YESat7quUkbCMy4zP9lAUuvS4YMslLyTtr919FA== dependencies: "@turf/helpers" "6.x" +"@turf/meta@^5.1.5": + version "5.2.0" + resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-5.2.0.tgz#3b1ad485ee0c3b0b1775132a32c384d53e4ba53d" + integrity sha1-OxrUhe4MOwsXdRMqMsOE1T5LpT0= + dependencies: + "@turf/helpers" "^5.1.5" + +"@turf/nearest-point-on-line@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/nearest-point-on-line/-/nearest-point-on-line-5.1.5.tgz#5606ae297f15947524bea51a2a9ef51ec1bf9c36" + integrity sha1-VgauKX8VlHUkvqUaKp71HsG/nDY= + dependencies: + "@turf/bearing" "^5.1.5" + "@turf/destination" "^5.1.5" + "@turf/distance" "^5.1.5" + "@turf/helpers" "^5.1.5" + "@turf/invariant" "^5.1.5" + "@turf/line-intersect" "^5.1.5" + "@turf/meta" "^5.1.5" + +"@turf/square@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/square/-/square-5.1.5.tgz#aa7b21e6033cc9252c3a5bd6f3d88dabd6fed180" + integrity sha1-qnsh5gM8ySUsOlvW89iNq9b+0YA= + dependencies: + "@turf/distance" "^5.1.5" + "@turf/helpers" "^5.1.5" + +"@turf/truncate@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@turf/truncate/-/truncate-5.1.5.tgz#9eedfb3b18ba81f2c98d3ead09431cca1884ad89" + integrity sha1-nu37Oxi6gfLJjT6tCUMcyhiErYk= + dependencies: + "@turf/helpers" "^5.1.5" + "@turf/meta" "^5.1.5" + "@types/babel-types@*", "@types/babel-types@^7.0.0": version "7.0.4" resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.4.tgz#bfd5b0d0d1ba13e351dff65b6e52783b816826c8" @@ -4960,6 +5123,15 @@ dependencies: globule "^1.0.0" +geojson-rbush@2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/geojson-rbush/-/geojson-rbush-2.1.0.tgz#3bd73be391fc10b0ae693d9b8acea2aae0b83a8d" + integrity sha1-O9c745H8ELCuaT2bis6iquC4Oo0= + dependencies: + "@turf/helpers" "*" + "@turf/meta" "*" + rbush "*" + geojson-rbush@3.x: version "3.1.1" resolved "https://registry.yarnpkg.com/geojson-rbush/-/geojson-rbush-3.1.1.tgz#dd40bdd26e92813d888d7b489e8d2980695a49b4"