diff client/src/store/map.js @ 1437:1cd1549aab47

fixed panning problem when drawing cross cuts
author Markus Kottlaender <markus@intevation.de>
date Fri, 30 Nov 2018 10:42:00 +0100
parents 7fa030127b05
children 71eb96690f91
line wrap: on
line diff
--- a/client/src/store/map.js	Fri Nov 30 09:40:39 2018 +0100
+++ b/client/src/store/map.js	Fri Nov 30 10:42:00 2018 +0100
@@ -462,11 +462,17 @@
       });
       cutTool.setActive(false);
       cutTool.on("drawstart", () => {
+        dispatch("disableIdentifyTool");
         cutVectorSrc.clear();
       });
       cutTool.on("drawend", event => {
         commit("fairwayprofile/selectedCut", null, { root: true });
-        dispatch("fairwayprofile/cut", event.feature, { root: true });
+        dispatch("fairwayprofile/cut", event.feature, { root: true }).then(() =>
+          // This setTimeout is an ugly workaround. If we would enable the
+          // identifyTool here immediately then the click event from ending the
+          // cut will trigger it. We don't want that.
+          setTimeout(() => dispatch("enableIdentifyTool"), 1000)
+        );
       });
 
       map.addInteraction(lineTool);
@@ -480,70 +486,75 @@
     },
     disableIdentifyTool({ state }) {
       unByKey(state.identifyTool);
+      state.identifyTool = null;
     },
     enableIdentifyTool({ state, commit, dispatch, getters }) {
-      state.identifyTool = state.openLayersMap.on(
-        ["singleclick", "dblclick"],
-        event => {
-          commit("setIdentifiedFeatures", []);
-          // checking our WFS layers
-          var features = state.openLayersMap.getFeaturesAtPixel(event.pixel);
-          if (features) {
-            commit("setIdentifiedFeatures", features);
+      if (!state.identifyTool) {
+        state.identifyTool = state.openLayersMap.on(
+          ["singleclick", "dblclick"],
+          event => {
+            commit("setIdentifiedFeatures", []);
+            // checking our WFS layers
+            var features = state.openLayersMap.getFeaturesAtPixel(event.pixel);
+            if (features) {
+              commit("setIdentifiedFeatures", features);
 
-            // get selected bottleneck from identified features
-            for (let feature of features) {
-              let id = feature.getId();
-              // RegExp.prototype.test() works with number, str and undefined
-              if (/^bottlenecks\./.test(id)) {
-                dispatch(
-                  "bottlenecks/setSelectedBottleneck",
-                  feature.get("objnam"),
-                  { root: true }
-                );
-                commit("moveMap", {
-                  coordinates: getCenter(
-                    feature
-                      .getGeometry()
-                      .clone()
-                      .transform("EPSG:3857", "EPSG:4326")
-                      .getExtent()
-                  ),
-                  zoom: 17,
-                  preventZoomOut: true
-                });
+              // get selected bottleneck from identified features
+              for (let feature of features) {
+                let id = feature.getId();
+                // RegExp.prototype.test() works with number, str and undefined
+                if (/^bottlenecks\./.test(id)) {
+                  dispatch(
+                    "bottlenecks/setSelectedBottleneck",
+                    feature.get("objnam"),
+                    { root: true }
+                  );
+                  commit("moveMap", {
+                    coordinates: getCenter(
+                      feature
+                        .getGeometry()
+                        .clone()
+                        .transform("EPSG:3857", "EPSG:4326")
+                        .getExtent()
+                    ),
+                    zoom: 17,
+                    preventZoomOut: true
+                  });
+                }
               }
             }
-          }
+
+            // DEBUG output and example how to remove the GeometryName
+            /*
+            for (let feature of features) {
+              console.log("Identified:", feature.getId());
+              for (let key of feature.getKeys()) {
+                if (key != feature.getGeometryName()) {
+                  console.log(key, feature.get(key));
+                }
+              }
+            }
+            */
 
-          // DEBUG output and example how to remove the GeometryName
-          /*
-          for (let feature of features) {
-            console.log("Identified:", feature.getId());
-            for (let key of feature.getKeys()) {
-              if (key != feature.getGeometryName()) {
-                console.log(key, feature.get(key));
-              }
+            // trying the GetFeatureInfo way for WMS
+            var wmsSource = getters.getVSourceByName(
+              "Inland ECDIS chart Danube"
+            );
+            var url = wmsSource.getGetFeatureInfoUrl(
+              event.coordinate,
+              100 /* resolution */,
+              "EPSG:3857",
+              // { INFO_FORMAT: "application/vnd.ogc.gml" } // not allowed by d4d
+              { INFO_FORMAT: "text/plain" }
+            );
+
+            if (url) {
+              // cannot directly query here because of SOP
+              console.log("GetFeatureInfo url:", url);
             }
           }
-          */
-
-          // trying the GetFeatureInfo way for WMS
-          var wmsSource = getters.getVSourceByName("Inland ECDIS chart Danube");
-          var url = wmsSource.getGetFeatureInfoUrl(
-            event.coordinate,
-            100 /* resolution */,
-            "EPSG:3857",
-            // { INFO_FORMAT: "application/vnd.ogc.gml" } // not allowed by d4d
-            { INFO_FORMAT: "text/plain" }
-          );
-
-          if (url) {
-            // cannot directly query here because of SOP
-            console.log("GetFeatureInfo url:", url);
-          }
-        }
-      );
+        );
+      }
     }
   }
 };