Supply hints for OSRM
authorJohn Firebaugh <john.firebaugh@gmail.com>
Wed, 14 May 2014 23:00:31 +0000 (16:00 -0700)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Wed, 14 May 2014 23:00:31 +0000 (16:00 -0700)
app/assets/javascripts/index/directions_engines/osrm.js

index 706970ec50031b54ae464a5986c859d9ae9fe8dc..69b78c25ee2f7be16b635ba3fbcf46ec53505d98 100644 (file)
@@ -2,6 +2,8 @@
 // Doesn't yet support hints
 
 function OSRMEngine() {
+  var previousPoints, hintData;
+
   return {
     id: "osrm_car",
     creditline: '<a href="http://project-osrm.org/" target="_blank">OSRM</a>',
@@ -33,6 +35,13 @@ function OSRMEngine() {
 
       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 (hintData && hintData.checksum) {
+        url += "&checksum=" + hintData.checksum;
       }
 
       $.ajax({
@@ -42,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;