Mercurial > gemma
diff client/src/store/fairway.js @ 1372:553aadd97087
new cross profile workflow (WIP)
Needs fixing of some bugs and not so nice looks.
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Tue, 27 Nov 2018 12:59:26 +0100 |
parents | ca33ad696594 |
children | fa7d647f8d77 |
line wrap: on
line diff
--- a/client/src/store/fairway.js Tue Nov 27 12:49:53 2018 +0100 +++ b/client/src/store/fairway.js Tue Nov 27 12:59:26 2018 +0100 @@ -37,7 +37,8 @@ fairwayCoordinates: [], startPoint: null, endPoint: null, - previousCuts: [] + previousCuts: [], + profileLoading: false }; }; @@ -103,6 +104,9 @@ }, previousCuts: (state, previousCuts) => { state.previousCuts = previousCuts; + }, + profileLoading: (state, loading) => { + state.profileLoading = loading; } }, actions: { @@ -116,27 +120,34 @@ .clear(); }, loadProfile({ commit, state }, survey) { - return new Promise((resolve, reject) => { - const profileLine = new LineString([state.startPoint, state.endPoint]); - const geoJSON = generateFeatureRequest( - profileLine, - survey.bottleneck_id, - survey.date_info - ); - HTTP.post("/cross", geoJSON, { - headers: { "X-Gemma-Auth": localStorage.getItem("token") } - }) - .then(response => { - commit("profileLoaded", { - response: response, - surveyDate: survey.date_info - }); - resolve(response); + if (state.startPoint && state.endPoint) { + return new Promise((resolve, reject) => { + commit("profileLoading", true); + const profileLine = new LineString([ + state.startPoint, + state.endPoint + ]); + const geoJSON = generateFeatureRequest( + profileLine, + survey.bottleneck_id, + survey.date_info + ); + HTTP.post("/cross", geoJSON, { + headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) - .catch(error => { - reject(error); - }); - }); + .then(response => { + commit("profileLoaded", { + response: response, + surveyDate: survey.date_info + }); + resolve(response); + }) + .catch(error => { + reject(error); + }) + .finally(() => commit("profileLoading", false)); + }); + } }, cut({ commit, dispatch, rootState, rootGetters }, cut) { const length = getLength(cut.getGeometry()); @@ -165,28 +176,29 @@ const profileLine = new LineString([start, end]); dispatch("loadProfile", rootState.bottlenecks.selectedSurvey) .then(() => { - rootGetters["map/getLayerByName"]("Fairway Dimensions") - .data.getSource() - .forEachFeatureIntersectingExtent( - // need to use EPSG:3857 which is the proj of vectorSource - profileLine + 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() .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 - ); - commit("setFairwayCoordinates", fairwayCoordinates); - } - ); + .transform("EPSG:3857", "EPSG:4326"); + const fairwayCoordinates = calculateFairwayCoordinates( + profileLine, + intersectingPolygon, + DEMODATA + ); + commit("setFairwayCoordinates", fairwayCoordinates); + } + ); }) .then(() => { commit("application/showSplitscreen", true, { root: true });