]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions/osrm.js
Fix missing semicolon warnings
[rails.git] / app / assets / javascripts / index / directions / osrm.js
index 69b78c25ee2f7be16b635ba3fbcf46ec53505d98..b53fecb81921131aac57a0d6e908393425682521 100644 (file)
@@ -12,26 +12,26 @@ function OSRMEngine() {
     getRoute: function (points, callback) {
       var TURN_INSTRUCTIONS = [
         "",
-        I18n.t('javascripts.directions.instructions.continue_on'),      // 1
-        I18n.t('javascripts.directions.instructions.slight_right'),     // 2
-        I18n.t('javascripts.directions.instructions.turn_right'),       // 3
-        I18n.t('javascripts.directions.instructions.sharp_right'),      // 4
-        I18n.t('javascripts.directions.instructions.uturn'),            // 5
-        I18n.t('javascripts.directions.instructions.sharp_left'),       // 6
-        I18n.t('javascripts.directions.instructions.turn_left'),        // 7
-        I18n.t('javascripts.directions.instructions.slight_left'),      // 8
-        I18n.t('javascripts.directions.instructions.via_point'),        // 9
-        I18n.t('javascripts.directions.instructions.follow'),           // 10
-        I18n.t('javascripts.directions.instructions.roundabout'),       // 11
-        I18n.t('javascripts.directions.instructions.leave_roundabout'), // 12
-        I18n.t('javascripts.directions.instructions.stay_roundabout'),  // 13
-        I18n.t('javascripts.directions.instructions.start'),            // 14
-        I18n.t('javascripts.directions.instructions.destination'),      // 15
-        I18n.t('javascripts.directions.instructions.against_oneway'),   // 16
-        I18n.t('javascripts.directions.instructions.end_oneway')        // 17
+        'javascripts.directions.instructions.continue',         // 1
+        'javascripts.directions.instructions.slight_right',     // 2
+        'javascripts.directions.instructions.turn_right',       // 3
+        'javascripts.directions.instructions.sharp_right',      // 4
+        'javascripts.directions.instructions.uturn',            // 5
+        'javascripts.directions.instructions.sharp_left',       // 6
+        'javascripts.directions.instructions.turn_left',        // 7
+        'javascripts.directions.instructions.slight_left',      // 8
+        'javascripts.directions.instructions.via_point',        // 9
+        'javascripts.directions.instructions.follow',           // 10
+        'javascripts.directions.instructions.roundabout',       // 11
+        'javascripts.directions.instructions.leave_roundabout', // 12
+        'javascripts.directions.instructions.stay_roundabout',  // 13
+        'javascripts.directions.instructions.start',            // 14
+        'javascripts.directions.instructions.destination',      // 15
+        'javascripts.directions.instructions.against_oneway',   // 16
+        '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;
@@ -44,21 +44,19 @@ function OSRMEngine() {
         url += "&checksum=" + hintData.checksum;
       }
 
-      $.ajax({
+      return $.ajax({
         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++) {
@@ -66,12 +64,11 @@ function OSRMEngine() {
             var linesegend;
             var instCodes = s[0].split('-');
             var instText = "<b>" + (i + 1) + ".</b> ";
-            instText += TURN_INSTRUCTIONS[instCodes[0]];
-            if (instCodes[1]) {
-              instText += "exit " + instCodes[1] + " ";
-            }
-            if (instCodes[0] != 15) {
-              instText += s[1] ? "<b>" + s[1] + "</b>" : I18n.t('javascripts.directions.instructions.unnamed');
+            var name = s[1] ? "<b>" + s[1] + "</b>" : I18n.t('javascripts.directions.instructions.unnamed');
+            if (instCodes[0] === "11" && instCodes[1]) {
+              instText += I18n.t(TURN_INSTRUCTIONS[instCodes[0]] + '_with_exit', { exit: instCodes[1], name: name } );
+            } else {
+              instText += I18n.t(TURN_INSTRUCTIONS[instCodes[0]] + '_without_exit', { name: name });
             }
             if ((i + 1) < data.route_instructions.length) {
               linesegend = data.route_instructions[i + 1][3] + 1;
@@ -93,4 +90,4 @@ function OSRMEngine() {
   };
 }
 
-OSM.Directions.addEngine(OSRMEngine(), false);
+OSM.Directions.addEngine(new OSRMEngine(), true);