diff client/src/store/map.js @ 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 ad271887fd8d
children 9d57c5765474
line wrap: on
line diff
--- 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;
     },