]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions_engines/osrm.js
Merge pull request #30 from zerebubuth/routing-ui-tweaks-2
[rails.git] / app / assets / javascripts / index / directions_engines / osrm.js
index ebcbf1fb13eeb88697ae9ace538b4d54314ff032..69b78c25ee2f7be16b635ba3fbcf46ec53505d98 100644 (file)
@@ -2,12 +2,14 @@
 // Doesn't yet support hints
 
 function OSRMEngine() {
+  var previousPoints, hintData;
+
   return {
-    name: "javascripts.directions.engines.osrm_car",
+    id: "osrm_car",
     creditline: '<a href="http://project-osrm.org/" target="_blank">OSRM</a>',
     draggable: true,
 
-    getRoute: function (isFinal, points, callback) {
+    getRoute: function (points, callback) {
       var TURN_INSTRUCTIONS = [
         "",
         I18n.t('javascripts.directions.instructions.continue_on'),      // 1
@@ -29,14 +31,18 @@ function OSRMEngine() {
         I18n.t('javascripts.directions.instructions.end_oneway')        // 17
       ];
 
-      var url = "http://router.project-osrm.org/viaroute?z=14&output=json";
+      var url = "http://router.project-osrm.org/viaroute?z=14&output=json&instructions=true";
 
       for (var i = 0; i < points.length; i++) {
         url += "&loc=" + points[i].lat + ',' + points[i].lng;
+        if (hintData && previousPoints && previousPoints[i].equals(points[i])) {
+          url += "&hint=" + hintData.locations[i];
+        }
       }
 
-      if (isFinal)
-        url += "&instructions=true";
+      if (hintData && hintData.checksum) {
+        url += "&checksum=" + hintData.checksum;
+      }
 
       $.ajax({
         url: url,
@@ -45,6 +51,9 @@ function OSRMEngine() {
           if (data.status == 207)
             return callback(true);
 
+          previousPoints = points;
+          hintData = data.hint_data;
+
           var line = L.PolylineUtil.decode(data.route_geometry);
           for (var i = 0; i < line.length; i++) {
             line[i].lat /= 10;