changeset 2445:e0f423606929

client: import soundingdata: fix npe bug Changes from bbc31150248c led to a null pointer exception, cause the default value of bottleneck was changed from empty string to null... for reasons. However, this was the inspiration to improve the UI behavior. The 'Download meta.json' button is now disabled as long as the form is lacking the necessary data.
author Markus Kottlaender <markus@intevation.de>
date Fri, 01 Mar 2019 12:42:52 +0100
parents 7ca6bdb2d174
children ba15d3534b2b
files client/src/components/ImportSoundingresults.vue client/src/components/Maplayer.vue client/src/store/map.js
diffstat 3 files changed, 73 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/ImportSoundingresults.vue	Fri Mar 01 12:24:37 2019 +0100
+++ b/client/src/components/ImportSoundingresults.vue	Fri Mar 01 12:42:52 2019 +0100
@@ -111,7 +111,10 @@
             <a
               download="meta.json"
               :href="dataLink"
-              class="btn btn-outline-info"
+              :class="[
+                'btn btn-outline-info',
+                { disabled: !bottleneck || !importDate || !depthReference }
+              ]"
             >
               <translate>Download Meta.json</translate>
             </a>
@@ -323,16 +326,18 @@
       return this.$gettext("Confirm");
     },
     dataLink() {
-      return (
-        "data:text/json;charset=utf-8," +
-        encodeURIComponent(
-          JSON.stringify({
-            depthReference: this.depthReference,
-            bottleneck: this.bottleneck.properties.objnam,
-            date: this.importDate
-          })
-        )
-      );
+      if (this.bottleneck && this.depthReference && this.import) {
+        return (
+          "data:text/json;charset=utf-8," +
+          encodeURIComponent(
+            JSON.stringify({
+              depthReference: this.depthReference,
+              bottleneck: this.bottleneck.properties.objnam,
+              date: this.importDate
+            })
+          )
+        );
+      }
     },
     depthReferenceOptions() {
       if (
--- a/client/src/components/Maplayer.vue	Fri Mar 01 12:24:37 2019 +0100
+++ b/client/src/components/Maplayer.vue	Fri Mar 01 12:42:52 2019 +0100
@@ -352,6 +352,20 @@
     );
     layer.data.setVisible(layer.isVisible);
 
+    layer = this.getLayerByName(LAYERS.BOTTLENECKSTATUS);
+    layer.data.getSource().setLoader(
+      this.buildVectorLoader(
+        {
+          featureNS: "gemma",
+          featurePrefix: "gemma",
+          featureTypes: ["bottlenecks_geoserver"],
+          geometryName: "area"
+        },
+        "/internal/wfs",
+        layer.data.getSource()
+      )
+    );
+
     layer = this.getLayerByName(LAYERS.BOTTLENECKS);
     layer.data.getSource().setLoader(
       this.buildVectorLoader(
--- a/client/src/store/map.js	Fri Mar 01 12:24:37 2019 +0100
+++ b/client/src/store/map.js	Fri Mar 01 12:42:52 2019 +0100
@@ -44,6 +44,7 @@
   WATERWAYAXIS: "Waterway Axis",
   WATERWAYPROFILES: "Waterway Profiles",
   BOTTLENECKS: "Bottlenecks",
+  BOTTLENECKSTATUS: "Bottleneck Status",
   BOTTLENECKISOLINE: "Bottleneck isolines",
   DISTANCEMARKS: "Distance marks",
   DISTANCEMARKSAXIS: "Distance marks, Axis",
@@ -279,15 +280,48 @@
           source: new VectorSource({
             strategy: bboxStrategy
           }),
-          style: new Style({
-            stroke: new Stroke({
-              color: "rgba(230, 230, 10, .8)",
-              width: 4
-            }),
-            fill: new Fill({
-              color: "rgba(230, 230, 10, .3)"
-            })
-          })
+          style: function(feature, resolution) {
+            if (resolution <= 50) {
+              return new Style({
+                stroke: new Stroke({
+                  color: "rgba(230, 230, 10, .8)",
+                  width: 4
+                }),
+                fill: new Fill({
+                  color: "rgba(230, 230, 10, .3)"
+                })
+              });
+            }
+            return [];
+          }
+        }),
+        isVisible: true,
+        showInLegend: true
+      },
+      {
+        name: LAYERS.BOTTLENECKSTATUS,
+        data: new VectorLayer({
+          source: new VectorSource({
+            strategy: bboxStrategy
+          }),
+          style: function(feature, resolution) {
+            if (resolution > 50) {
+              let bnCenter = getCenter(feature.getGeometry().getExtent());
+              let fillColor = feature.get("fa_critical")
+                ? "rgba(255, 0, 0, 0.5)"
+                : "rgba(0, 255, 0, 0.5)";
+              let strokeColor = feature.get("fa_critical") ? "red" : "green";
+              return new Style({
+                geometry: new Point(bnCenter),
+                image: new Circle({
+                  radius: 10,
+                  fill: new Fill({ color: fillColor }),
+                  stroke: new Stroke({ color: strokeColor, width: 2 })
+                })
+              });
+            }
+            return [];
+          }
         }),
         isVisible: true,
         showInLegend: true