summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2019-04-22 15:27:19 +0200
committerMarcus Lundblad <ml@update.uu.se>2019-04-22 21:06:51 +0200
commit4ebdbf6f0867b58af5cffe5c1f84edcbf1ff16ea (patch)
tree7bf595415dbd7d5de5e47e581f4dbc3bf0743ae0
parent5093b8737539b711121ca8c382ce177658668bdb (diff)
downloadgnome-maps-wip/mlundblad/merge-route-streetname-common.tar.gz
graphHopper: Fold instruction with common street names / numberswip/mlundblad/merge-route-streetname-common
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
-rw-r--r--src/graphHopper.js35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/graphHopper.js b/src/graphHopper.js
index 427419df..5512bda0 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;
}