changeset 4865:e51b9b265df0

right click toggles single layer selection
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 12 Dec 2019 17:13:34 +0100
parents 6a148617e012
children 9df7794ec969
files client/src/components/layers/Layerselect.vue client/src/store/map.js
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/layers/Layerselect.vue	Tue Dec 10 11:20:22 2019 +0100
+++ b/client/src/components/layers/Layerselect.vue	Thu Dec 12 17:13:34 2019 +0100
@@ -79,12 +79,7 @@
   },
   methods: {
     selectSingle() {
-      console.log("right click");
-      this.openLayersMaps.forEach(m => {
-        m.getLayers().forEach(l => {
-          l.setVisible(l.get("id") == this.layerId);
-        });
-      });
+      this.$store.commit("map/viewSingleLayer", this.layerId);
     },
     refreshLegend() {
       if (this.layer.get("id") === "BOTTLENECKISOLINE") {
--- a/client/src/store/map.js	Tue Dec 10 11:20:22 2019 +0100
+++ b/client/src/store/map.js	Thu Dec 12 17:13:34 2019 +0100
@@ -30,6 +30,8 @@
 // initial state
 const init = () => {
   return {
+    oldLayerVisibility: [],
+    singleLayerVisible: false,
     openLayersMaps: [],
     syncedMaps: [],
     syncedView: null,
@@ -69,6 +71,27 @@
     }
   },
   mutations: {
+    viewSingleLayer: (state, layerId) => {
+      state.singleLayerVisible = !state.singleLayerVisible;
+      if (state.singleLayerVisible) {
+        state.oldLayerVisibility = state.openLayersMaps.reduce((o, m) => {
+          let current = [];
+          m.getLayers().forEach(l => {
+            current.push(l.getVisible());
+            l.setVisible(l.get("id") == layerId);
+          });
+          o.push(current);
+          return o;
+        }, []);
+      } else {
+        state.oldLayerVisibility.forEach((m, i) => {
+          let layers = state.openLayersMaps[i].getLayers().getArray();
+          m.forEach((visible, index) => {
+            layers[index].setVisible(visible);
+          });
+        });
+      }
+    },
     reviewActive: (state, active) => {
       state.reviewActive = active;
     },