From 27b63a3560c119bae48e87ebbdc0153951e21486 Mon Sep 17 00:00:00 2001 From: Bigood Date: Thu, 6 Jun 2019 19:03:49 +0200 Subject: [PATCH 1/3] Considering options passed when building URL Using the argument routingOptions. A "default" key will result as the parameter not being added at all on the query string, otherwise, if a boolean is provided, it will be appended with the corresponding key. --- src/osrm-v1.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/osrm-v1.js b/src/osrm-v1.js index ffbebac1..47e74eca 100644 --- a/src/osrm-v1.js +++ b/src/osrm-v1.js @@ -331,12 +331,14 @@ }, buildRouteUrl: function(waypoints, options) { + var locs = [], hints = [], wp, latLng, - computeInstructions, - computeAlternative = true; + computeInstructions = options.steps !== "default" ? true : false, + computeRoundtrip = options.roundtrip !== "default" ? true : false, + computeAlternative = options.alternatives !== "default" ? true : false; for (var i = 0; i < waypoints.length; i++) { wp = waypoints[i]; @@ -345,14 +347,13 @@ hints.push(this._hints.locations[this._locationKey(latLng)] || ''); } - computeInstructions = - true; return this.options.serviceUrl + '/' + this.options.profile + '/' + locs.join(';') + '?' + (options.geometryOnly ? (options.simplifyGeometry ? '' : 'overview=full') : 'overview=false') + - '&alternatives=' + computeAlternative.toString() + - '&steps=' + computeInstructions.toString() + + (computeAlternative ? '&alternatives=' + (typeof options.steps == "boolean" ? options.steps : true).toString() : '') + + (computeInstructions ? '&steps=' + (typeof options.roundtrip == "boolean" ? options.roundtrip : false).toString() : '') + + (computeRoundtrip ? '&roundtrip=' + (typeof options.alternatives == "boolean" ? options.alternatives : true).toString() : '') + (this.options.useHints ? '&hints=' + hints.join(';') : '') + (options.allowUTurns ? '&continue_straight=' + !options.allowUTurns : ''); }, From 267c6db1530f5106a11c06aaa55a58723ff6224c Mon Sep 17 00:00:00 2001 From: Bigood Date: Thu, 6 Jun 2019 19:05:55 +0200 Subject: [PATCH 2/3] Select either routes or trips Mapbox optimization route returns trips instead of routes --- src/osrm-v1.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/osrm-v1.js b/src/osrm-v1.js index 47e74eca..0f97c9f6 100644 --- a/src/osrm-v1.js +++ b/src/osrm-v1.js @@ -157,9 +157,10 @@ } actualWaypoints = this._toWaypoints(inputWaypoints, response.waypoints); - - for (i = 0; i < response.routes.length; i++) { - route = this._convertRoute(response.routes[i]); + //Mapbox optimization route returns trips instead of routes + let routes = response.routes || response.trips; + for (i = 0; i < routes.length; i++) { + route = this._convertRoute(routes[i]); route.inputWaypoints = inputWaypoints; route.waypoints = actualWaypoints; route.properties = {isSimplified: !options || !options.geometryOnly || options.simplifyGeometry}; From 7eb805ca04c4787feb5ecc7043cc87ab2ea51626 Mon Sep 17 00:00:00 2001 From: Bigood Date: Fri, 7 Jun 2019 10:53:43 +0200 Subject: [PATCH 3/3] Fixed messed up ternary operators --- src/osrm-v1.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/osrm-v1.js b/src/osrm-v1.js index 0f97c9f6..ed8228b6 100644 --- a/src/osrm-v1.js +++ b/src/osrm-v1.js @@ -337,9 +337,9 @@ hints = [], wp, latLng, - computeInstructions = options.steps !== "default" ? true : false, - computeRoundtrip = options.roundtrip !== "default" ? true : false, - computeAlternative = options.alternatives !== "default" ? true : false; + computeInstructions = options.steps && options.steps !== "default" ? true : false, + computeRoundtrip = options.roundtrip && options.roundtrip !== "default" ? true : false, + computeAlternative = options.alternatives && options.alternatives !== "default" ? true : false; for (var i = 0; i < waypoints.length; i++) { wp = waypoints[i]; @@ -352,9 +352,9 @@ return this.options.serviceUrl + '/' + this.options.profile + '/' + locs.join(';') + '?' + (options.geometryOnly ? (options.simplifyGeometry ? '' : 'overview=full') : 'overview=false') + - (computeAlternative ? '&alternatives=' + (typeof options.steps == "boolean" ? options.steps : true).toString() : '') + - (computeInstructions ? '&steps=' + (typeof options.roundtrip == "boolean" ? options.roundtrip : false).toString() : '') + - (computeRoundtrip ? '&roundtrip=' + (typeof options.alternatives == "boolean" ? options.alternatives : true).toString() : '') + + (computeInstructions ? '&steps=' + (typeof options.steps == "boolean" ? options.steps : true).toString() : '') + + (computeRoundtrip ? '&roundtrip=' + (typeof options.roundtrip == "boolean" ? options.roundtrip : false).toString() : '') + + (computeAlternative ? '&alternatives=' + (typeof options.alternatives == "boolean" ? options.alternatives : true).toString() : '') + (this.options.useHints ? '&hints=' + hints.join(';') : '') + (options.allowUTurns ? '&continue_straight=' + !options.allowUTurns : ''); },