Mercurial > gemma
view client/src/store/fairway.js @ 1096:aa1f5daf6fc9
refac: centralized stores
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Tue, 30 Oct 2018 16:55:29 +0100 |
parents | client/src/fairway/store.js@7242b5a427bc |
children | f106aee673e7 |
line wrap: on
line source
/* * This is Free Software under GNU Affero General Public License v >= 3.0 * without warranty, see README.md and license for details. * * SPDX-License-Identifier: AGPL-3.0-or-later * License-Filename: LICENSES/AGPL-3.0.txt * * Copyright (C) 2018 by via donau * – Österreichische Wasserstraßen-Gesellschaft mbH * Software engineering by Intevation GmbH * * Author(s): * Thomas Junk <thomas.junk@intevation.de> * Markus Kottländer <markuks.kottlaender@intevation.de> */ import Vue from "vue"; import { HTTP } from "../application/lib/http"; import { prepareProfile } from "../application/lib/geo"; import LineString from "ol/geom/LineString.js"; import { generateFeatureRequest } from "../application/lib/geo.js"; const DEMOLEVEL = 149.345; const FairwayProfile = { namespaced: true, state: { additionalSurvey: "", availableSurveys: null, totalLength: 0, minAlt: 0, maxAlt: 0, currentProfile: {}, waterLevels: [{ year: "2016", level: DEMOLEVEL, color: "#005DFF" }], selectedWaterLevel: DEMOLEVEL, fairwayCoordinates: [], startPoint: null, endPoint: null, selectedMorph: null }, getters: { length: state => { return state.totalLength; }, additionalSurvey: state => { return state.additionalSurvey; } }, mutations: { setAdditionalSurvey: (state, additionalSurvey) => { state.additionalSurvey = additionalSurvey; }, setSelectedMorph: (state, selectedMorph) => { state.selectedMorph = selectedMorph; }, setAvailableSurveys: (state, surveys) => { state.availableSurveys = surveys; }, setSelectedWaterLevel: (state, level) => { state.selectedWaterLevel = level; }, profileLoaded: (state, answer) => { const { response, surveyDate } = answer; const { data } = response; const coordinates = data.geometry.coordinates; if (!coordinates) return; const startPoint = state.startPoint; const endPoint = state.endPoint; const geoJSON = data; const result = prepareProfile({ geoJSON, startPoint, endPoint }); // Use Vue.set() to make new object properties rective // https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats Vue.set(state.currentProfile, surveyDate, result.points); if (!state.minAlt || state.minAlt > result.minAlt) { state.minAlt = result.minAlt; } if (!state.maxAlt || state.maxAlt < result.maxAlt) { state.maxAlt = result.maxAlt; } if (!state.totalLength || state.totalLength < result.lengthPolyLine) { state.totalLength = result.lengthPolyLine; } }, setStartPoint: (state, start) => { state.startPoint = start; }, setEndPoint: (state, end) => { state.endPoint = end; }, setFairwayCoordinates: (state, coordinates) => { state.fairwayCoordinates = coordinates; }, clearCurrentProfile: state => { state.additionalSurvey = ""; state.currentProfile = {}; state.minAlt = null; state.maxAlt = null; state.totalLength = null; state.fairwayCoordinates = []; state.startPoint = null; state.endPoint = null; } }, actions: { loadProfile({ commit, state }, date_info) { return new Promise((resolve, reject) => { const profileLine = new LineString([state.startPoint, state.endPoint]); const geoJSON = generateFeatureRequest( profileLine, state.selectedMorph.bottleneck_id, date_info ); HTTP.post("/cross", geoJSON, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("profileLoaded", { response: response, surveyDate: date_info }); resolve(response); }) .catch(error => { reject(error); }); }); } } }; export default FairwayProfile;