[gnome-maps/wip/mlundblad/merge-route-streetname-common] graphHopper: Fold instruction with common street names / numbers
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/merge-route-streetname-common] graphHopper: Fold instruction with common street names / numbers
- Date: Mon, 22 Apr 2019 19:07:59 +0000 (UTC)
commit 4ebdbf6f0867b58af5cffe5c1f84edcbf1ff16ea
Author: Marcus Lundblad <ml update uu se>
Date: Mon Apr 22 15:27:19 2019 +0200
graphHopper: Fold instruction with common street names / numbers
Fold together consequetive instructions sharing a common set
of road names or number into a single instruction bearing
the common set of names and numbers.
Also fix the missing finish instruction.
Fixes #176
src/graphHopper.js | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
---
diff --git a/src/graphHopper.js b/src/graphHopper.js
index 427419d..5512bda 100644
--- a/src/graphHopper.js
+++ b/src/graphHopper.js
@@ -228,6 +228,21 @@ var GraphHopper = class GraphHopper {
return [startPoint].concat(rest);
}
+ _splitStreetNames(names) {
+ return names.split(',').map(n => n.trim());
+ }
+
+ /**
+ * Returns names found in both the arrays names1 and names2
+ */
+ _namesIntersection(names1, names2) {
+ return names1.filter(Set.prototype.has, new Set(names2));
+ }
+
+ _concatStreetNames(names) {
+ return names.join(', ');
+ }
+
_foldInstructions(instructions) {
let currInstruction = instructions[0];
let res = [];
@@ -235,22 +250,30 @@ var GraphHopper = class GraphHopper {
for (let i = 1; i < instructions.length; i++) {
let newInstruction = instructions[i];
let newSign = newInstruction.sign;
- let newStreetname = newInstruction.street_name;
+ let currStreetnames = this._splitStreetNames(currInstruction.street_name);
+ let newStreetnames = this._splitStreetNames(newInstruction.street_name);
+ let namesIntersect =
+ this._namesIntersection(currStreetnames, newStreetnames);
/* if the direction is to continue straight, or keep left or keep
- * right on the same street/road number, fold the instruction into
+ * right on the same subset of street/road numbers, fold the instruction into
* the previous one
*/
- if (newSign === Sign.CONTINUE_ON_STREET ||
- ((newSign === Sign.KEEP_LEFT || newSign === Sign.KEEP_RIGHT) &&
- newStreetname === currInstruction.street_name)) {
+ if ((newSign === Sign.CONTINUE_ON_STREET ||
+ newSign === Sign.KEEP_LEFT || newSign === Sign.KEEP_RIGHT) &&
+ namesIntersect.length > 0) {
currInstruction.distance += newInstruction.distance;
+ currInstruction.street_name =
+ this._concatStreetNames(namesIntersect);
} else {
res.push(currInstruction);
- currInstruction = instructions[i];
+ currInstruction = newInstruction;
}
}
+ // push finish instruction
+ res.push(instructions[instructions.length - 1]);
+
return res;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]