Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

_getWaypointIndices: function() {
if (!this._wpIndices) {
this._wpIndices = this._route.waypointIndices || this._findWaypointIndices();
this._wpIndices = this._findWaypointIndices();
}

return this._wpIndices;
Expand Down
58 changes: 41 additions & 17 deletions src/osrm-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
*/
module.exports = L.Class.extend({
options: {
optimised: false,
serviceUrl: 'https://router.project-osrm.org/route/v1',
profile: 'driving',
timeout: 30 * 1000,
routingOptions: {
alternatives: true,
steps: true
},
tripOptions: {
roundtrip:true,
source:"first",
geometries: "polyline",
destination:"last",
steps: true
},
polylinePrecision: 5,
useHints: true,
suppressDemoServerWarning: false,
Expand Down Expand Up @@ -62,7 +70,7 @@
i,
xhr;

options = L.extend({}, this.options.routingOptions, options);
options = L.extend({}, this.options.optimised ? this.options.routingOptions : this.options.tripOptions, options) ;
url = this.buildRouteUrl(waypoints, options);
if (this.options.requestParameters) {
url += L.Util.getParamString(this.options.requestParameters, url);
Expand Down Expand Up @@ -158,12 +166,23 @@

actualWaypoints = this._toWaypoints(inputWaypoints, response.waypoints);

for (i = 0; i < response.routes.length; i++) {
route = this._convertRoute(response.routes[i]);
route.inputWaypoints = inputWaypoints;
route.waypoints = actualWaypoints;
route.properties = {isSimplified: !options || !options.geometryOnly || options.simplifyGeometry};
alts.push(route);
if (this.options.optimised) {
for (i = 0; i < response.trips.length; i++) {
route = this._convertRoute(response.trips[i]);
route.inputWaypoints = inputWaypoints;
route.waypoints = actualWaypoints;
route.properties = { isSimplified: !options || !options.geometryOnly || options.simplifyGeometry };
alts.push(route);
}
}
else {
for (i = 0; i < response.routes.length; i++) {
route = this._convertRoute(response.routes[i]);
route.inputWaypoints = inputWaypoints;
route.waypoints = actualWaypoints;
route.properties = {isSimplified: !options || !options.geometryOnly || options.simplifyGeometry};
alts.push(route);
}
}

this._saveHintData(response.waypoints, inputWaypoints);
Expand Down Expand Up @@ -334,9 +353,7 @@
var locs = [],
hints = [],
wp,
latLng,
computeInstructions,
computeAlternative = true;
latLng;

for (var i = 0; i < waypoints.length; i++) {
wp = waypoints[i];
Expand All @@ -345,14 +362,21 @@
hints.push(this._hints.locations[this._locationKey(latLng)] || '');
}

computeInstructions =
true;

return this.options.serviceUrl + '/' + this.options.profile + '/' +
locs.join(';') + '?' +
if (this.options.optimised)
return this.options.serviceUrl + '/' + this.options.profile + '/' +
locs.join(';') + '?' +
(options.geometryOnly ? (options.simplifyGeometry ? '' : 'overview=full') : 'overview=false') +
'&geometries='+ this.options.tripOptions.geometries +
'&steps=' + this.options.tripOptions.steps.toString() +
'&source=' + this.options.tripOptions.source +
'&destination=' + this.options.tripOptions.destination +
'&roundtrip=' + this.options.tripOptions.roundtrip;
else
return this.options.serviceUrl + '/' + this.options.profile + '/' +
locs.join(';') + '?' +
(options.geometryOnly ? (options.simplifyGeometry ? '' : 'overview=full') : 'overview=false') +
'&alternatives=' + computeAlternative.toString() +
'&steps=' + computeInstructions.toString() +
'&alternatives=' + this.options.routingOptions.alternatives.toString() +
'&steps=' + this.options.routingOptions.steps.toString() +
(this.options.useHints ? '&hints=' + hints.join(';') : '') +
(options.allowUTurns ? '&continue_straight=' + !options.allowUTurns : '');
},
Expand Down