view client/src/store/bottlenecks.js @ 2956:974122125a76

Let it be an error if closest points of DISMARs on axis are equal This might be the case e.g. if both distance marks are very far away from the available axis geometries. Instead of returning a point in such a case, which would likely be an unexpected result, raise an exception by means of STRICT.
author Tom Gottfried <tom@intevation.de>
date Mon, 08 Apr 2019 14:53:09 +0200
parents 1686ec185155
children b74ebeb2bdc8
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):
 * Markus Kottländer <markuks.kottlaender@intevation.de>
 * Thomas Junk <thomas.junk@intevation.de>
 */
import { HTTP } from "@/lib/http";
import { WFS } from "ol/format.js";
import { displayError } from "@/lib/errors.js";
import { LAYERS } from "@/store/map.js";

// initial state
const init = () => {
  return {
    bottlenecks: [],
    bottlenecksList: [],
    selectedBottleneck: null,
    surveys: [],
    selectedSurvey: null,
    surveysLoading: false
  };
};

export default {
  init,
  namespaced: true,
  state: init(),
  mutations: {
    setBottlenecks: (state, bottlenecks) => {
      state.bottlenecks = bottlenecks;
    },
    setBottlenecksList: (state, bottlenecksList) => {
      state.bottlenecksList = bottlenecksList;
    },
    setSelectedBottleneck: (state, name) => {
      state.selectedBottleneck = name;
    },
    setSurveys(state, surveys) {
      state.surveys = surveys;
    },
    setSelectedSurveyByDate(state, date) {
      const survey = state.surveys.filter(x => x.date_info === date)[0];
      state.selectedSurvey = survey;
    },
    setFirstSurveySelected(state) {
      state.selectedSurvey = state.surveys[0];
    },
    selectedSurvey(state, survey) {
      state.selectedSurvey = survey;
    },
    surveysLoading: (state, loading) => {
      state.surveysLoading = loading;
    }
  },
  actions: {
    setSelectedBottleneck({ state, commit, rootState, rootGetters }, name) {
      return new Promise((resolve, reject) => {
        if (name !== state.selectedBottleneck) {
          commit("selectedSurvey", null);
          commit("application/splitscreenLoading", true, { root: true });
          commit("application/showSplitscreen", false, { root: true });
          commit("application/removeSplitscreen", "fairwayprofile", {
            root: true
          });
          setTimeout(() => {
            commit("fairwayprofile/clearCurrentProfile", null, { root: true });
            commit("application/splitscreenLoading", false, { root: true });
          }, 350);
          rootState.map.cutTool.setActive(false);
          rootGetters["map/getVSourceByName"](LAYERS.CUTTOOL).clear();
        }
        if (name) {
          commit("application/showProfiles", true, { root: true });
        }
        commit("setSelectedBottleneck", name);
        if (name) {
          commit("surveysLoading", true);
          HTTP.get("/surveys/" + name, {
            headers: {
              "X-Gemma-Auth": localStorage.getItem("token"),
              "Content-type": "text/xml; charset=UTF-8"
            }
          })
            .then(response => {
              const surveys = response.data.surveys.sort((a, b) =>
                a.date_info < b.date_info ? 1 : -1
              );
              commit("setSurveys", surveys);
              resolve(response);
            })
            .catch(error => {
              commit("setSurveys", []);
              commit("selectedSurvey", null);
              const { status, data } = error.response;
              displayError({
                title: "Backend Error",
                message: `${status}: ${data.message || data}`
              });
              reject(error);
            })
            .finally(() => commit("surveysLoading", false));
        } else {
          commit("setSurveys", []);
          resolve();
        }
      });
    },
    loadBottlenecksList({ commit }) {
      return new Promise((resolve, reject) => {
        var bottleneckFeatureCollectionRequest = new WFS().writeGetFeature({
          srsName: "EPSG:4326",
          featureNS: "gemma",
          featurePrefix: "gemma",
          featureTypes: ["bottleneck_overview"],
          outputFormat: "application/json"
        });
        HTTP.post(
          "/internal/wfs",
          new XMLSerializer().serializeToString(
            bottleneckFeatureCollectionRequest
          ),
          {
            headers: {
              "X-Gemma-Auth": localStorage.getItem("token"),
              "Content-type": "text/xml; charset=UTF-8"
            }
          }
        )
          .then(response => {
            commit("setBottlenecksList", response.data.features);
            resolve(response);
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    loadBottlenecks({ commit }) {
      return new Promise((resolve, reject) => {
        var bottleneckFeatureCollectionRequest = new WFS().writeGetFeature({
          srsName: "EPSG:4326",
          featureNS: "gemma",
          featurePrefix: "gemma",
          featureTypes: ["bottlenecks_geoserver"],
          outputFormat: "application/json"
        });
        HTTP.post(
          "/internal/wfs",
          new XMLSerializer().serializeToString(
            bottleneckFeatureCollectionRequest
          ),
          {
            headers: {
              "X-Gemma-Auth": localStorage.getItem("token"),
              "Content-type": "text/xml; charset=UTF-8"
            }
          }
        )
          .then(response => {
            commit("setBottlenecks", response.data.features);
            resolve(response);
          })
          .catch(error => {
            reject(error);
          });
      });
    }
  }
};