changeset 5172:d750fb514a82 detectvisiblesoundings

first draft for SR-detection
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 21 Apr 2020 09:15:24 +0200
parents 6dc74d7e6582
children 58ef2c163d14
files client/src/components/Pdftool.vue
diffstat 1 files changed, 56 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue	Wed Apr 15 11:28:30 2020 +0200
+++ b/client/src/components/Pdftool.vue	Tue Apr 21 09:15:24 2020 +0200
@@ -119,6 +119,7 @@
 import { displayError } from "@/lib/errors";
 import { pdfgen, templateLoader } from "@/lib/mixins";
 import sanitize from "sanitize-filename";
+import { WFS } from "ol/format";
 
 const paperSizes = {
   // in millimeter, landscape [width, height]
@@ -261,7 +262,61 @@
       this.form.paperSize = this.templateData.properties.paperSize;
       this.form.resolution = this.templateData.properties.resolution;
     },
+    areSoundingsVisible() {
+      return new Promise((resolve, reject) => {
+        const map = this.openLayersMap();
+        const currentExtent = map.getView().calculateExtent(map.getSize());
+        const getSoundingResultFeatures = new WFS().writeGetFeature({
+          srsName: "EPSG:4326",
+          featureNS: "gemma",
+          featurePrefix: "gemma",
+          featureTypes: ["sounding_results_areas_geoserver"],
+          outputFormat: "application/json",
+          resultType: "hits",
+          bbox: currentExtent,
+          geometryName: "areas"
+        });
+        HTTP.post(
+          "/internal/wfs",
+          new XMLSerializer().serializeToString(getSoundingResultFeatures),
+          {
+            headers: {
+              "X-Gemma-Auth": localStorage.getItem("token"),
+              "Content-type": "text/xml; charset=UTF-8"
+            }
+          }
+        )
+          .then(response => {
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
+      });
+    },
     download() {
+      this.areSoundingsVisible()
+        .then(response => {
+          const parser = new DOMParser();
+          const responseXML = parser.parseFromString(response.data, "text/xml");
+          const totalNumber = responseXML
+            .getElementsByTagName("wfs:FeatureCollection")[0]
+            .getAttribute("numberOfFeatures");
+          this.generatePDF(totalNumber > 0);
+        })
+        .catch(error => {
+          let message = "Backend not reachable";
+          if (error.response) {
+            const { status, data } = error.response;
+            message = `${status}: ${data.message || data}`;
+          }
+          displayError({
+            title: this.$gettext("Backend Error"),
+            message: message
+          });
+        });
+    },
+    generatePDF(soundingsVisible) {
       /**
        * In order to generate the image with the appropriate resolution
        * we have to temporaily scale the visible part of the map.
@@ -274,6 +329,7 @@
        * Details: https://gis.stackexchange.com/questions/328933/openlayers-generating-clientside-pdfs
        *
        */
+      console.log(soundingsVisible);
       this.readyToGenerate = false;
       if (this.form.format !== "portrait") {
         this.pdf.width = paperSizes[this.form.paperSize][0];