]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions/osrm.js
Improve error handling for routing engines
[rails.git] / app / assets / javascripts / index / directions / osrm.js
index b53fecb81921131aac57a0d6e908393425682521..4a42d5dc96ea1e8d138c353afbd28824dc7bbdba 100644 (file)
@@ -31,22 +31,28 @@ function OSRMEngine() {
         'javascripts.directions.instructions.end_oneway'        // 17
       ];
 
-      var url = document.location.protocol + "//router.project-osrm.org/viaroute?z=14&output=json&instructions=true";
+      var params = [
+        { name: "z", value: "14" },
+        { name: "output", value: "json" },
+        { name: "instructions", value: true }
+      ];
 
       for (var i = 0; i < points.length; i++) {
-        url += "&loc=" + points[i].lat + ',' + points[i].lng;
+        params.push({ name: "loc", value: points[i].lat + "," + points[i].lng });
+
         if (hintData && previousPoints && previousPoints[i].equals(points[i])) {
-          url += "&hint=" + hintData.locations[i];
+          params.push({ name: "hint", value: hintData.locations[i] });
         }
       }
 
       if (hintData && hintData.checksum) {
-        url += "&checksum=" + hintData.checksum;
+        params.push({ name: "checksum", value: hintData.checksum });
       }
 
       return $.ajax({
-        url: url,
-        dataType: 'json',
+        url: document.location.protocol + "//router.project-osrm.org/viaroute",
+        data: params,
+        dataType: "json",
         success: function (data) {
           if (data.status === 207)
             return callback(true);
@@ -78,12 +84,15 @@ function OSRMEngine() {
             steps.push([line[s[3]], s[0].split('-')[0], instText, s[2], line.slice(s[3], linesegend)]);
           }
 
-          callback(null, {
+          callback(false, {
             line: line,
             steps: steps,
             distance: data.route_summary.total_distance,
             time: data.route_summary.total_time
           });
+        },
+        error: function () {
+          callback(true);
         }
       });
     }