changeset 2910:c8c7122047a2

client: stretches: select/unselect stretches by clicking on them on the map
author Markus Kottlaender <markus@intevation.de>
date Tue, 02 Apr 2019 18:59:26 +0200
parents 5105f6ad0176
children a75c546ef498
files client/src/components/ImportStretches.vue client/src/components/Maplayer.vue client/src/store/imports.js client/src/store/map.js
diffstat 4 files changed, 39 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/ImportStretches.vue	Tue Apr 02 18:19:43 2019 +0200
+++ b/client/src/components/ImportStretches.vue	Tue Apr 02 18:59:26 2019 +0200
@@ -342,7 +342,7 @@
     ...mapState("map", ["identifiedFeatures", "currentMeasurement"]),
     ...mapGetters("map", ["getVSourceByName", "getLayerByName"]),
     ...mapGetters("user", ["isSysAdmin"]),
-    ...mapState("imports", ["stretches", "selectedStretch"]),
+    ...mapState("imports", ["stretches"]),
     defineStretchesLabel() {
       return this.$gettext("Define Stretches");
     },
@@ -380,16 +380,6 @@
         this.pipetteStart = false;
         this.pipetteEnd = false;
       }
-    },
-    selectedStretch(stretch) {
-      this.getVSourceByName(LAYERS.STRETCHES)
-        .getFeatures()
-        .forEach(f => {
-          f.set("highlighted", false);
-          if (f.getId() === stretch.id) {
-            f.set("highlighted", true);
-          }
-        });
     }
   },
   methods: {
@@ -469,7 +459,7 @@
       });
     },
     moveMapToStretch(stretch) {
-      this.$store.commit("imports/selectedStretch", stretch);
+      this.$store.commit("imports/selectedStretchId", stretch.id);
       this.$store.commit("map/setLayerVisible", LAYERS.STRETCHES);
       this.$store.commit("map/moveToExtent", {
         feature: stretch,
--- a/client/src/components/Maplayer.vue	Tue Apr 02 18:19:43 2019 +0200
+++ b/client/src/components/Maplayer.vue	Tue Apr 02 18:59:26 2019 +0200
@@ -67,7 +67,7 @@
     ]),
     ...mapState("bottlenecks", ["selectedSurvey"]),
     ...mapState("application", ["showSplitscreen"]),
-    ...mapState("imports", ["selectedStretch"]),
+    ...mapState("imports", ["selectedStretchId"]),
     hasActiveInteractions() {
       return (
         (this.lineTool && this.lineTool.getActive()) ||
@@ -173,6 +173,16 @@
       } else {
         this.updateBottleneckFilter("does_not_exist", "1999-10-01");
       }
+    },
+    selectedStretchId(id) {
+      this.getVSourceByName(LAYERS.STRETCHES)
+        .getFeatures()
+        .forEach(f => {
+          f.set("highlighted", false);
+          if (id === f.getId()) {
+            f.set("highlighted", true);
+          }
+        });
     }
   },
   mounted() {
@@ -380,7 +390,7 @@
         "/internal/wfs",
         layer.data.getSource(),
         f => {
-          if (f.getId() === this.selectedStretch.id) {
+          if (f.getId() === this.selectedStretchId) {
             f.set("highlighted", true);
           }
           return f;
--- a/client/src/store/imports.js	Tue Apr 02 18:19:43 2019 +0200
+++ b/client/src/store/imports.js	Tue Apr 02 18:59:26 2019 +0200
@@ -32,7 +32,7 @@
     declined: false,
     warning: false,
     stretches: [],
-    selectedStretch: null,
+    selectedStretchId: null,
     imports: [],
     reviewed: [],
     show: null,
@@ -129,8 +129,8 @@
     setStretches: (state, stretches) => {
       state.stretches = stretches;
     },
-    selectedStretch: (state, stretch) => {
-      state.selectedStretch = stretch;
+    selectedStretchId: (state, id) => {
+      state.selectedStretchId = id;
     },
     setReviewed: (state, reviewed) => {
       state.reviewed = reviewed;
--- a/client/src/store/map.js	Tue Apr 02 18:19:43 2019 +0200
+++ b/client/src/store/map.js	Tue Apr 02 18:59:26 2019 +0200
@@ -771,7 +771,6 @@
 
               for (let feature of features) {
                 let id = feature.getId();
-
                 // avoid identifying the same feature twice
                 if (
                   identifiedFeatures.findIndex(
@@ -835,6 +834,28 @@
                     });
                   }
                 }
+
+                // get selected stretch
+                if (/^stretches/.test(id)) {
+                  if (rootState.imports.selectedStretchId === feature.getId()) {
+                    commit("imports/selectedStretchId", null, { root: true });
+                  } else {
+                    commit("imports/selectedStretchId", feature.getId(), {
+                      root: true
+                    });
+                    commit("moveMap", {
+                      coordinates: getCenter(
+                        feature
+                          .getGeometry()
+                          .clone()
+                          .transform("EPSG:3857", "EPSG:4326")
+                          .getExtent()
+                      ),
+                      zoom: null,
+                      preventZoomOut: true
+                    });
+                  }
+                }
               }
 
               commit("setIdentifiedFeatures", identifiedFeatures);