Mercurial > gemma
changeset 1437:1cd1549aab47
fixed panning problem when drawing cross cuts
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 30 Nov 2018 10:42:00 +0100 |
parents | 59c9dbb26bb0 |
children | 71eb96690f91 |
files | client/src/components/map/fairway/Profiles.vue client/src/store/fairway.js client/src/store/map.js |
diffstat | 3 files changed, 143 insertions(+), 138 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/map/fairway/Profiles.vue Fri Nov 30 09:40:39 2018 +0100 +++ b/client/src/components/map/fairway/Profiles.vue Fri Nov 30 10:42:00 2018 +0100 @@ -327,19 +327,10 @@ } }, toggleCutTool() { - if (this.selectedSurvey) { - this.cutTool.setActive(!this.cutTool.getActive()); - this.lineTool.setActive(false); - this.polygonTool.setActive(false); - this.$store.commit("map/setCurrentMeasurement", null); - - // toggle identifyTool (map events singleclick and dblclick) - this.$store.dispatch( - this.cutTool.getActive() - ? "map/disableIdentifyTool" - : "map/enableIdentifyTool" - ); - } + this.cutTool.setActive(!this.cutTool.getActive()); + this.lineTool.setActive(false); + this.polygonTool.setActive(false); + this.$store.commit("map/setCurrentMeasurement", null); }, onCopyCoordinates() { displayInfo({
--- a/client/src/store/fairway.js Fri Nov 30 09:40:39 2018 +0100 +++ b/client/src/store/fairway.js Fri Nov 30 10:42:00 2018 +0100 @@ -153,79 +153,82 @@ } }, cut({ commit, dispatch, rootState, rootGetters }, cut) { - const length = getLength(cut.getGeometry()); - commit( - "map/setCurrentMeasurement", - { - quantity: "Length", - unitSymbol: "m", - value: Math.round(length * 10) / 10 - }, - { root: true } - ); + return new Promise((resolve, reject) => { + const length = getLength(cut.getGeometry()); + commit( + "map/setCurrentMeasurement", + { + quantity: "Length", + unitSymbol: "m", + value: Math.round(length * 10) / 10 + }, + { root: true } + ); - // 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 - if (rootState.bottlenecks.selectedSurvey) { - const inputLineString = cut.getGeometry().clone(); - inputLineString.transform("EPSG:3857", "EPSG:4326"); - const [start, end] = inputLineString - .getCoordinates() - .map(coords => coords.map(coord => parseFloat(coord.toFixed(8)))); - commit("setStartPoint", start); - commit("setEndPoint", end); - const profileLine = new LineString([start, end]); + // 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 + if (rootState.bottlenecks.selectedSurvey) { + const inputLineString = cut.getGeometry().clone(); + inputLineString.transform("EPSG:3857", "EPSG:4326"); + const [start, end] = inputLineString + .getCoordinates() + .map(coords => coords.map(coord => parseFloat(coord.toFixed(8)))); + commit("setStartPoint", start); + commit("setEndPoint", end); + const profileLine = new LineString([start, end]); - const profileLoaders = [ - dispatch("loadProfile", rootState.bottlenecks.selectedSurvey) - ]; - if (rootState.fairwayprofile.additionalSurvey) { - profileLoaders.push( - dispatch("loadProfile", rootState.fairwayprofile.additionalSurvey) - ); - } + const profileLoaders = [ + dispatch("loadProfile", rootState.bottlenecks.selectedSurvey) + ]; + if (rootState.fairwayprofile.additionalSurvey) { + profileLoaders.push( + dispatch("loadProfile", rootState.fairwayprofile.additionalSurvey) + ); + } - commit("profileLoading", true); - Promise.all(profileLoaders) - .then(() => { - dispatch("map/enableIdentifyTool", null, { root: true }); - rootState.map.cutTool.setActive(false); - rootGetters["map/getVSourceByName"]( - "Fairway Dimensions" - ).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() + commit("profileLoading", true); + Promise.all(profileLoaders) + .then(() => { + rootState.map.cutTool.setActive(false); + rootGetters["map/getVSourceByName"]( + "Fairway Dimensions" + ).forEachFeatureIntersectingExtent( + // need to use EPSG:3857 which is the proj of vectorSource + profileLine .clone() - .transform("EPSG:3857", "EPSG:4326"); - const fairwayCoordinates = calculateFairwayCoordinates( - profileLine, - intersectingPolygon, - DEMODATA - ); - commit("setFairwayCoordinates", fairwayCoordinates); - } - ); - }) - .catch(error => { - const { status, data } = error.response; - displayError({ - title: "Backend Error", - message: `${status}: ${data.message || data}` + .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 + ); + commit("setFairwayCoordinates", fairwayCoordinates); + resolve(); + } + ); + }) + .catch(error => { + const { status, data } = error.response; + displayError({ + title: "Backend Error", + message: `${status}: ${data.message || data}` + }); + reject(); + }) + .finally(() => { + commit("application/showSplitscreen", true, { root: true }); + commit("profileLoading", false); }); - }) - .finally(() => { - commit("application/showSplitscreen", true, { root: true }); - commit("profileLoading", false); - }); - } + } else reject(); + }); }, previousCuts({ commit, rootState }) { const previousCuts =
--- a/client/src/store/map.js Fri Nov 30 09:40:39 2018 +0100 +++ b/client/src/store/map.js Fri Nov 30 10:42:00 2018 +0100 @@ -462,11 +462,17 @@ }); cutTool.setActive(false); cutTool.on("drawstart", () => { + dispatch("disableIdentifyTool"); cutVectorSrc.clear(); }); cutTool.on("drawend", event => { commit("fairwayprofile/selectedCut", null, { root: true }); - dispatch("fairwayprofile/cut", event.feature, { root: true }); + dispatch("fairwayprofile/cut", event.feature, { root: true }).then(() => + // This setTimeout is an ugly workaround. If we would enable the + // identifyTool here immediately then the click event from ending the + // cut will trigger it. We don't want that. + setTimeout(() => dispatch("enableIdentifyTool"), 1000) + ); }); map.addInteraction(lineTool); @@ -480,70 +486,75 @@ }, disableIdentifyTool({ state }) { unByKey(state.identifyTool); + state.identifyTool = null; }, enableIdentifyTool({ state, commit, dispatch, getters }) { - state.identifyTool = state.openLayersMap.on( - ["singleclick", "dblclick"], - event => { - commit("setIdentifiedFeatures", []); - // checking our WFS layers - var features = state.openLayersMap.getFeaturesAtPixel(event.pixel); - if (features) { - commit("setIdentifiedFeatures", features); + if (!state.identifyTool) { + state.identifyTool = state.openLayersMap.on( + ["singleclick", "dblclick"], + event => { + commit("setIdentifiedFeatures", []); + // checking our WFS layers + var features = state.openLayersMap.getFeaturesAtPixel(event.pixel); + if (features) { + commit("setIdentifiedFeatures", features); - // get selected bottleneck from identified features - for (let feature of features) { - let id = feature.getId(); - // RegExp.prototype.test() works with number, str and undefined - if (/^bottlenecks\./.test(id)) { - dispatch( - "bottlenecks/setSelectedBottleneck", - feature.get("objnam"), - { root: true } - ); - commit("moveMap", { - coordinates: getCenter( - feature - .getGeometry() - .clone() - .transform("EPSG:3857", "EPSG:4326") - .getExtent() - ), - zoom: 17, - preventZoomOut: true - }); + // get selected bottleneck from identified features + for (let feature of features) { + let id = feature.getId(); + // RegExp.prototype.test() works with number, str and undefined + if (/^bottlenecks\./.test(id)) { + dispatch( + "bottlenecks/setSelectedBottleneck", + feature.get("objnam"), + { root: true } + ); + commit("moveMap", { + coordinates: getCenter( + feature + .getGeometry() + .clone() + .transform("EPSG:3857", "EPSG:4326") + .getExtent() + ), + zoom: 17, + preventZoomOut: true + }); + } } } - } + + // DEBUG output and example how to remove the GeometryName + /* + for (let feature of features) { + console.log("Identified:", feature.getId()); + for (let key of feature.getKeys()) { + if (key != feature.getGeometryName()) { + console.log(key, feature.get(key)); + } + } + } + */ - // DEBUG output and example how to remove the GeometryName - /* - for (let feature of features) { - console.log("Identified:", feature.getId()); - for (let key of feature.getKeys()) { - if (key != feature.getGeometryName()) { - console.log(key, feature.get(key)); - } + // trying the GetFeatureInfo way for WMS + var wmsSource = getters.getVSourceByName( + "Inland ECDIS chart Danube" + ); + var url = wmsSource.getGetFeatureInfoUrl( + event.coordinate, + 100 /* resolution */, + "EPSG:3857", + // { INFO_FORMAT: "application/vnd.ogc.gml" } // not allowed by d4d + { INFO_FORMAT: "text/plain" } + ); + + if (url) { + // cannot directly query here because of SOP + console.log("GetFeatureInfo url:", url); } } - */ - - // trying the GetFeatureInfo way for WMS - var wmsSource = getters.getVSourceByName("Inland ECDIS chart Danube"); - var url = wmsSource.getGetFeatureInfoUrl( - event.coordinate, - 100 /* resolution */, - "EPSG:3857", - // { INFO_FORMAT: "application/vnd.ogc.gml" } // not allowed by d4d - { INFO_FORMAT: "text/plain" } - ); - - if (url) { - // cannot directly query here because of SOP - console.log("GetFeatureInfo url:", url); - } - } - ); + ); + } } } };