changeset 5174:b73e8cc494f6 detectvisiblesoundings

limit to selected survey
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 21 Apr 2020 13:45:54 +0200
parents 58ef2c163d14
children 6038f782e51d
files client/src/components/Pdftool.vue
diffstat 1 files changed, 40 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue	Tue Apr 21 11:30:39 2020 +0200
+++ b/client/src/components/Pdftool.vue	Tue Apr 21 13:45:54 2020 +0200
@@ -120,6 +120,7 @@
 import { pdfgen, templateLoader } from "@/lib/mixins";
 import sanitize from "sanitize-filename";
 import { WFS } from "ol/format";
+import { equalTo as equalToFilter } from "ol/format/filter";
 
 const paperSizes = {
   // in millimeter, landscape [width, height]
@@ -206,18 +207,6 @@
     ...mapGetters("map", ["openLayersMap"]),
     generatePdfLable() {
       return this.$gettext("Generate PDF");
-    },
-    filename() {
-      let filename = "map";
-      if (this.bottleneckForPrint) {
-        // TODO: Check if the view contains the selected bottleneck
-        // to avoid including bottleneck info in pdf in case view has changed to another location
-        filename = `BN-${sanitize(this.bottleneckForPrint).replace(/ /g, "-")}`;
-        if (this.selectedSurvey) {
-          filename += "-sr" + this.selectedSurvey.date_info.replace(/-/g, "");
-        }
-      }
-      return `${filename}-${this.dateForPDF()}.pdf`;
     }
   },
   methods: {
@@ -262,11 +251,11 @@
       this.form.paperSize = this.templateData.properties.paperSize;
       this.form.resolution = this.templateData.properties.resolution;
     },
-    areSoundingsVisible() {
+    numberSoundingsVisible() {
       return new Promise((resolve, reject) => {
         const map = this.openLayersMap();
         const currentExtent = map.getView().calculateExtent(map.getSize());
-        const getSoundingResultFeatures = new WFS().writeGetFeature({
+        const params = {
           srsName: "EPSG:3857",
           featureNS: "gemma",
           featurePrefix: "gemma",
@@ -275,7 +264,14 @@
           resultType: "hits",
           bbox: currentExtent,
           geometryName: "areas"
-        });
+        };
+        if (this.selectedSurvey) {
+          params["filter"] = equalToFilter(
+            "bottleneck_id",
+            this.selectedSurvey.bottleneck_id
+          );
+        }
+        const getSoundingResultFeatures = new WFS().writeGetFeature(params);
         HTTP.post(
           "/internal/wfs",
           new XMLSerializer().serializeToString(getSoundingResultFeatures),
@@ -295,7 +291,7 @@
       });
     },
     download() {
-      this.areSoundingsVisible()
+      this.numberSoundingsVisible()
         .then(response => {
           const parser = new DOMParser();
           const responseXML = parser.parseFromString(response.data, "text/xml");
@@ -305,6 +301,7 @@
           this.generatePDF(totalNumber > 0);
         })
         .catch(error => {
+          console.log(error);
           let message = "Backend not reachable";
           if (error.response) {
             const { status, data } = error.response;
@@ -438,7 +435,8 @@
                   e.offset || defaultOffset,
                   e.rounding === 0 || e.rounding ? e.rounding : defaultRounding,
                   e.color || defaultTextColor,
-                  e.brcolor || defaultBorderColor
+                  e.brcolor || defaultBorderColor,
+                  soundingsVisible
                 );
                 break;
               }
@@ -447,7 +445,8 @@
                   e.position,
                   e.offset || defaultOffset,
                   e.rounding === 0 || e.rounding ? e.rounding : defaultRounding,
-                  e.brcolor || defaultBorderColor
+                  e.brcolor || defaultBorderColor,
+                  soundingsVisible
                 );
                 break;
               }
@@ -482,7 +481,18 @@
               }
             }
           });
-          this.pdf.doc.save(this.filename);
+          let filename = "map";
+          if (this.bottleneckForPrint && soundingsVisible) {
+            filename = `BN-${sanitize(this.bottleneckForPrint).replace(
+              / /g,
+              "-"
+            )}`;
+            if (this.selectedSurvey) {
+              filename +=
+                "-sr" + this.selectedSurvey.date_info.replace(/-/g, "");
+            }
+          }
+          this.pdf.doc.save(`${filename}-${this.dateForPDF()}.pdf`);
         }
         map.setSize(this.mapSize);
         map.getView().setResolution(this.resolution);
@@ -711,8 +721,9 @@
       this.pdf.doc.setFontStyle("normal");
       this.pdf.doc.text(size < 3 ? x1 - 0.5 : x1 - 1.3, y3 + 1, "N");
     },
-    addLegend(position, offset, rounding, brcolor) {
+    addLegend(position, offset, rounding, brcolor, soundingsVisible) {
       if (
+        soundingsVisible &&
         this.bottleneckForPrint &&
         this.selectedSurvey &&
         this.openLayersMap()
@@ -752,8 +763,16 @@
         );
       }
     },
-    addBottleneckInfo(position, offset, rounding, color, brcolor) {
+    addBottleneckInfo(
+      position,
+      offset,
+      rounding,
+      color,
+      brcolor,
+      soundingsVisible
+    ) {
       if (
+        soundingsVisible &&
         this.bottleneckForPrint &&
         this.selectedSurvey &&
         this.openLayersMap()