Mercurial > gemma
diff client/src/store/fairwayavailability.js @ 3353:b01bf2399c20
client: available fairway depth vs lnwl: fetching data for diagrams on map
Data gets stored in the client for 15 mins. Diagrams are still drawn with static data for demo purpose.
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Tue, 21 May 2019 14:42:08 +0200 |
parents | 399a2eb496ee |
children | 9625c6120d18 |
line wrap: on
line diff
--- a/client/src/store/fairwayavailability.js Tue May 21 14:24:55 2019 +0200 +++ b/client/src/store/fairwayavailability.js Tue May 21 14:42:08 2019 +0200 @@ -33,6 +33,7 @@ breadthlimit: null, fwData: null, fwLNWLData: null, + fwLNWLOverviewData: [], legend: null, LOS: 3 }; @@ -42,6 +43,13 @@ init, namespaced: true, state: init(), + getters: { + fwLNWLOverviewData: state => feature => { + return state.fwLNWLOverviewData.find( + d => d.feature.get("id") === feature.get("id") + ); + } + }, mutations: { type: (state, type) => { state.type = type; @@ -73,6 +81,14 @@ setFwData: (state, fwData) => { state.fwData = fwData; }, + addFwLNWLOverviewData: (state, data) => { + let existingIndex = state.fwLNWLOverviewData.findIndex( + d => d.feature.get("id") === data.feature.get("id") + ); + if (existingIndex !== -1) + state.fwLNWLOverviewData.splice(existingIndex, 1); + state.fwLNWLOverviewData.push(data); + }, setLegend: (state, header) => { const headerEntries = header.split(","); headerEntries.shift(); @@ -132,6 +148,29 @@ reject(error); }); }); + }, + loadAvailableFairwayDepthLNWL: (context, options) => { + return new Promise((resolve, reject) => { + const { feature, from, to, frequency, LOS } = options; + let name = + feature.constructor.name === "Feature" + ? feature.get("objnam") + : feature.properties.name; + const start = encodeURIComponent("00:00:00+00:00"); + const end = encodeURIComponent("23:59:59+00:00"); + const URL = `/data/bottleneck/availability/${encodeURIComponent( + name + )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}`; + HTTP.get(URL, { + headers: { "X-Gemma-Auth": localStorage.getItem("token") } + }) + .then(response => { + resolve(response.data); + }) + .catch(error => { + reject(error); + }); + }); } } };