diff client/src/application/lib/geo.js @ 677:3605af94d1ee

fix: prepare profile calculation algorithm fixed The x-value of a point is determined according to its reference point * in case of the first segment, it is the first element of the line string * in case of consecutive segments it is the last point of the previous segment
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 19 Sep 2018 16:37:03 +0200
parents 4c36b0e39d78
children 87ea9d267c2b
line wrap: on
line diff
--- a/client/src/application/lib/geo.js	Wed Sep 19 16:09:09 2018 +0200
+++ b/client/src/application/lib/geo.js	Wed Sep 19 16:37:03 2018 +0200
@@ -61,6 +61,11 @@
  * c) calculating the total length of the given profile
  * d) transposes the datapoints given to the first point of the first section
  *
+ * The calculation of total equals the sum of partial distances between points
+ * The x-value of a point is determined according to its reference point
+ * in case of the first segment, it is the first element of the line string
+ * in case of consecutive segments it is the last point of the previous segment
+ *
  * @param {object} feature
  */
 const transform = feature => {
@@ -73,8 +78,9 @@
   for (let section of sections) {
     let sectionCoordinates = [];
     let previousPoint = generatePoint(section[0]);
+    let currentPoint = null;
     for (let coords of section) {
-      const currentPoint = generatePoint(coords);
+      currentPoint = generatePoint(coords);
       let x = distanceBetween(firstPoint, currentPoint);
       let y = coords[2];
       sectionCoordinates.push({
@@ -87,6 +93,7 @@
       if (y > maxAlt) maxAlt = y;
     }
     coordinates.push(sectionCoordinates);
+    firstPoint = currentPoint;
   }
   return { coordinates, totalLength, minAlt, maxAlt };
 };