]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions/osrm.js
GraphHopper directions updates
[rails.git] / app / assets / javascripts / index / directions / osrm.js
index 69b78c25ee2f7be16b635ba3fbcf46ec53505d98..842909eabc47cb5e4dc2d920b0013846f4ccae93 100644 (file)
@@ -31,7 +31,7 @@ function OSRMEngine() {
         I18n.t('javascripts.directions.instructions.end_oneway')        // 17
       ];
 
-      var url = "http://router.project-osrm.org/viaroute?z=14&output=json&instructions=true";
+      var url = document.location.protocol + "//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;
@@ -48,17 +48,15 @@ function OSRMEngine() {
         url: url,
         dataType: 'json',
         success: function (data) {
-          if (data.status == 207)
+          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;
-            line[i].lng /= 10;
-          }
+          var line = L.PolylineUtil.decode(data.route_geometry, {
+            precision: 6
+          });
 
           var steps = [];
           for (i = 0; i < data.route_instructions.length; i++) {
@@ -70,7 +68,7 @@ function OSRMEngine() {
             if (instCodes[1]) {
               instText += "exit " + instCodes[1] + " ";
             }
-            if (instCodes[0] != 15) {
+            if (instCodes[0] !== 15) {
               instText += s[1] ? "<b>" + s[1] + "</b>" : I18n.t('javascripts.directions.instructions.unnamed');
             }
             if ((i + 1) < data.route_instructions.length) {
@@ -93,4 +91,4 @@ function OSRMEngine() {
   };
 }
 
-OSM.Directions.addEngine(OSRMEngine(), false);
+OSM.Directions.addEngine(new OSRMEngine(), true);