# HG changeset patch # User Thomas Junk # Date 1540375431 -7200 # Node ID 74229d9f70280c02a233be8d538e286d8b149893 # Parent 957613a71b354645a68f346e4559fc6a456e0b3d refac: restructure maptool for understandability diff -r 957613a71b35 -r 74229d9f7028 client/src/map/Maplayer.vue --- 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);