summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2019-04-15 22:50:45 +0200
committerMarcus Lundblad <ml@update.uu.se>2019-04-15 22:50:45 +0200
commita8d4d5309372118ce85c4b49eb2c3dfda71dc73b (patch)
treecdd9e58d16ab2db0cec4b673b37b98aeff86c6e2
parent6249e7b1e5d4d1c908096444b494c362ff55bd53 (diff)
downloadgnome-maps-a8d4d5309372118ce85c4b49eb2c3dfda71dc73b.tar.gz
graphHopper: Declare sign constants with names
-rw-r--r--src/graphHopper.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/graphHopper.js b/src/graphHopper.js
index d0192ba6..427419df 100644
--- a/src/graphHopper.js
+++ b/src/graphHopper.js
@@ -30,6 +30,25 @@ const Route = imports.route;
const RouteQuery = imports.routeQuery;
const Utils = imports.utils;
+/**
+ * Directional sign from the GraphHopper API.
+ * https://github.com/graphhopper/graphhopper/blob/master/docs/web/api-doc.md
+ */
+var Sign = {
+ KEEP_LEFT: -7,
+ TURN_SHARP_LEFT: -3,
+ TURN_LEFT: -2,
+ TURN_SLIGHT_LEFT: -1,
+ CONTINUE_ON_STREET: 0,
+ TURN_SLIGHT_RIGHT: 1,
+ TURN_RIGHT: 2,
+ TURN_SHARP_RIGHT: 3,
+ FINISH: 4,
+ REACHED_VIA: 5,
+ USE_ROUNDABOUT: 6,
+ KEEP_RIGHT: 7
+}
+
var GraphHopper = class GraphHopper {
get route() {
@@ -218,8 +237,13 @@ var GraphHopper = class GraphHopper {
let newSign = newInstruction.sign;
let newStreetname = newInstruction.street_name;
- if ((newSign === 0 || newSign === -7 || newSign === 7) &&
- newStreetname === currInstruction.street_name) {
+ /* if the direction is to continue straight, or keep left or keep
+ * right on the same street/road number, 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)) {
currInstruction.distance += newInstruction.distance;
} else {
res.push(currInstruction);