diff options
author | Marcus Lundblad <ml@update.uu.se> | 2019-04-09 22:43:58 +0200 |
---|---|---|
committer | Marcus Lundblad <ml@update.uu.se> | 2019-04-14 22:23:11 +0200 |
commit | 6249e7b1e5d4d1c908096444b494c362ff55bd53 (patch) | |
tree | d52220fd561b4b2fc5e2ffef251bdba2238a41ae | |
parent | de77a94ba1db07da899838cfb5346197f4862ea8 (diff) | |
download | gnome-maps-6249e7b1e5d4d1c908096444b494c362ff55bd53.tar.gz |
graphHopper: Fold consequetive route instructionswip/mlundblad/fold-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
-rw-r--r-- | src/graphHopper.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/graphHopper.js b/src/graphHopper.js index 0953b012..d0192ba6 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; |