[gnome-maps/wip/mlundblad/fold-route-instructions] WIP: graphHopper: Fold consequetive route instructions



commit 08411358ae5dce5596507761ff39ea33f748ca90
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Apr 9 22:43:58 2019 +0200

    WIP: graphHopper: Fold consequetive route instructions
    
    Fold consequetive route instructions of type "continue",
    "keep left", or "keep right" if the street name is the same
    as previous ones.
    
    Fixes #171

 src/graphHopper.js | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/src/graphHopper.js b/src/graphHopper.js
index 0953b01..d0192ba 100644
--- a/src/graphHopper.js
+++ b/src/graphHopper.js
@@ -85,7 +85,7 @@ var GraphHopper = class GraphHopper {
         this._queryGraphHopper(points, transportationType,
                                (result, exception) => {
             if (exception) {
-                Utils.debug(e);
+                Utils.debug(exception);
                 if (this._query.latest)
                     this._query.latest.place = null;
                 else
@@ -189,7 +189,7 @@ var GraphHopper = class GraphHopper {
             time:        0,
             turnAngle:   0
         });
-        let rest = instructions.map((instr) => {
+        let rest = this._foldInstructions(instructions).map((instr) => {
             let type = this._createTurnPointType(instr.sign);
             let text = instr.text;
             if (type === Route.TurnPointType.VIA) {
@@ -209,6 +209,27 @@ var GraphHopper = class GraphHopper {
         return [startPoint].concat(rest);
     }
 
+    _foldInstructions(instructions) {
+        let currInstruction = instructions[0];
+        let res = [];
+
+        for (let i = 1; i < instructions.length; i++) {
+            let newInstruction = instructions[i];
+            let newSign = newInstruction.sign;
+            let newStreetname = newInstruction.street_name;
+
+            if ((newSign === 0 || newSign === -7 || newSign === 7) &&
+                newStreetname === currInstruction.street_name) {
+                currInstruction.distance += newInstruction.distance;
+            } else {
+                res.push(currInstruction);
+                currInstruction = instructions[i];
+            }
+        }
+
+        return res;
+    }
+
     _createTurnPointType(sign) {
         let type = sign + 3;
         let min  = Route.TurnPointType.SHARP_LEFT;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]