X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/14086728a63933dffdceb9f5e5f25422fc288969..ed75d4710b0d4aec2c57f610083762d6fd63e9c9:/app/assets/javascripts/routing_engines/osrm.js
diff --git a/app/assets/javascripts/routing_engines/osrm.js b/app/assets/javascripts/routing_engines/osrm.js
index b40d5b306..6a197bb98 100644
--- a/app/assets/javascripts/routing_engines/osrm.js
+++ b/app/assets/javascripts/routing_engines/osrm.js
@@ -1,60 +1,69 @@
// OSRM car engine
// Doesn't yet support hints
-OSRMEngine = function(vehicleName, baseURL, locale) {
- this.vehicleName = vehicleName;
- this.baseURL = baseURL;
- this.locale = locale;
- if (!locale)
- this.locale = "en";
+OSRMEngine = function (vehicleName, baseURL, locale) {
+ this.vehicleName = vehicleName;
+ this.baseURL = baseURL;
+ this.locale = locale;
+ if (!locale)
+ this.locale = "en";
};
-OSRMEngine.prototype.createConfig = function() {
- var that = this;
- return {
- name: "javascripts.directions.engines.osrm_"+this.vehicleName.toLowerCase(),
- creditline: 'OSRM',
- draggable: true,
- _hints: {},
- getRoute: function(isFinal,points) {
- var url=that.baseURL+"?z=14&output=json";
- for (var i=0; i ";
- instText+=TURN_INSTRUCTIONS[instCodes[0]];
- if (instCodes[1]) { instText+="exit "+instCodes[1]+" "; }
- if (instCodes[0]!=15) { instText+=s[1] ? ""+s[1]+"" : I18n.t('javascripts.directions.instructions.unnamed'); }
- if ((i+1)OSRM',
+ draggable: true,
+ _hints: {},
+
+ getRoute: function (isFinal, points) {
+ var url = that.baseURL + "?z=14&output=json";
+ for (var i = 0; i < points.length; i++) {
+ var pair = points[i].join(',');
+ url += "&loc=" + pair;
+ if (this._hints[pair]) url += "&hint=" + this._hints[pair];
+ }
+ if (isFinal) url += "&instructions=true";
+ this.requestCORS(url);
+ },
+
+ gotRoute: function (router, data) {
+ if (data.status == 207) {
+ return false;
+ }
+ // Draw polyline
+ var line = L.PolylineUtil.decode(data.route_geometry);
+ for (i = 0; i < line.length; i++) {
+ line[i].lat /= 10;
+ line[i].lng /= 10;
+ }
+ router.setPolyline(line);
+ // Assemble instructions
+ var steps = [];
+ for (i = 0; i < data.route_instructions.length; i++) {
+ var s = data.route_instructions[i];
+ var linesegend;
+ var instCodes = s[0].split('-');
+ var instText = "" + (i + 1) + ". ";
+ instText += TURN_INSTRUCTIONS[instCodes[0]];
+ if (instCodes[1]) {
+ instText += "exit " + instCodes[1] + " ";
+ }
+ if (instCodes[0] != 15) {
+ instText += s[1] ? "" + s[1] + "" : I18n.t('javascripts.directions.instructions.unnamed');
+ }
+ if ((i + 1) < data.route_instructions.length) {
+ linesegend = data.route_instructions[i + 1][3] + 1;
+ } else {
+ linesegend = s[3] + 1;
}
- };
+ steps.push([line[s[3]], s[0].split('-')[0], instText, s[2], line.slice(s[3], linesegend)]);
+ }
+ if (steps.length) router.setItinerary({ steps: steps, distance: data.route_summary.total_distance, time: data.route_summary.total_time });
+ return true;
+ }
+ };
};
OSM.RoutingEngines.add(false, new OSRMEngine("Car", "http://router.project-osrm.org/viaroute").createConfig());