changeset 1022:74229d9f7028

refac: restructure maptool for understandability
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 24 Oct 2018 12:03:51 +0200
parents 957613a71b35
children 337a7f4c8a16
files client/src/map/Maplayer.vue
diffstat 1 files changed, 32 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/map/Maplayer.vue	Wed Oct 24 11:20:30 2018 +0200
+++ b/client/src/map/Maplayer.vue	Wed Oct 24 12:03:51 2018 +0200
@@ -194,25 +194,9 @@
           var vectorSource = this.getLayerByName(
             "Fairway Dimensions"
           ).data.getSource();
-          vectorSource.forEachFeatureIntersectingExtent(
-            // need to use EPSG:3857 which is the proj of vectorSource
-            profileLine
-              .clone()
-              .transform("EPSG:4326", "EPSG:3857")
-              .getExtent(),
-            feature => {
-              // transform back to prepare for usage
-              var intersectingPolygon = feature
-                .getGeometry()
-                .clone()
-                .transform("EPSG:3857", "EPSG:4326");
-              this.addToFairwayRectangle(
-                profileLine,
-                intersectingPolygon,
-                DEMODATA
-              );
-            }
-          );
+          this.calculateIntersection(vectorSource, profileLine);
+        })
+        .then(() => {
           this.$store.commit("application/openSplitScreen");
         })
         .catch(error => {
@@ -223,7 +207,34 @@
           });
         });
     },
-    addToFairwayRectangle(profileLine, fairwayGeometry, depth) {
+    calculateIntersection(vectorSource, profileLine) {
+      const transformedLine = profileLine
+        .clone()
+        .transform("EPSG:4326", "EPSG:3857")
+        .getExtent();
+      const featureCallback = feature => {
+        // transform back to prepare for usage
+        var intersectingPolygon = feature
+          .getGeometry()
+          .clone()
+          .transform("EPSG:3857", "EPSG:4326");
+        const fairwayCoordinates = this.calculateFairwayCoordinates(
+          profileLine,
+          intersectingPolygon,
+          DEMODATA
+        );
+        this.$store.commit(
+          "fairwayprofile/setFairwayCoordinates",
+          fairwayCoordinates
+        );
+      };
+      vectorSource.forEachFeatureIntersectingExtent(
+        // need to use EPSG:3857 which is the proj of vectorSource
+        transformedLine,
+        featureCallback
+      );
+    },
+    calculateFairwayCoordinates(profileLine, fairwayGeometry, depth) {
       // both geometries have to be in EPSG:4326
       // uses turfjs distance() function
       let fairwayCoordinates = [];
@@ -247,10 +258,7 @@
           ]);
         }
       }
-      this.$store.commit(
-        "fairwayprofile/setFairwayCoordinates",
-        fairwayCoordinates
-      );
+      return fairwayCoordinates;
     },
     activateInteraction() {
       const interaction = this.createInteraction(this.drawMode);