]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions/osrm.js
Merge pull request #1938 from jguthrie100/fix_no_trace_description_error
[rails.git] / app / assets / javascripts / index / directions / osrm.js
index 3d32f07e33a5b0582b9dc544c98f228dba4b15c7..2f9498d039d43cc15ab4a4514cb208655251e2b4 100644 (file)
@@ -32,6 +32,8 @@ function OSRMEngine() {
         'turn slight left': 'javascripts.directions.instructions.slight_left',
         'roundabout': 'javascripts.directions.instructions.roundabout',
         'rotary': 'javascripts.directions.instructions.roundabout',
+        'exit roundabout': 'javascripts.directions.instructions.exit_roundabout',
+        'exit rotary': 'javascripts.directions.instructions.exit_roundabout',
         'depart': 'javascripts.directions.instructions.start',
         'arrive': 'javascripts.directions.instructions.destination',
       };
@@ -57,9 +59,14 @@ function OSRMEngine() {
         'turn sharp left': 7,
         'roundabout': 10,
         'rotary': 10,
+        'exit roundabout': 10,
+        'exit rotary': 10,
         'depart': 8,
         'arrive': 14
       };
+      var numToWord = function(num) {
+        return ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"][num-1];
+      };
       var transformed_steps = input_steps.map(function(step, idx) {
         var maneuver_id;
 
@@ -76,6 +83,8 @@ function OSRMEngine() {
           case 'arrive':
           case 'roundabout':
           case 'rotary':
+          case 'exit roundabout':
+          case 'exit rotary':
             maneuver_id = step.maneuver.type;
             break;
           case 'roundabout turn':
@@ -95,8 +104,10 @@ function OSRMEngine() {
         Array.prototype.push.apply(line, step_geometry);
 
         var instText = "<b>" + (idx + 1) + ".</b> ";
-        
+        var destinations = "<b>" + step.destinations + "</b>";
+        var namedRoad = true;
         var name;
+
         if (step.name && step.ref) {
           name = "<b>" + step.name + " (" + step.ref + ")</b>";
         } else if (step.name) {
@@ -105,10 +116,30 @@ function OSRMEngine() {
           name = "<b>" + step.ref + "</b>";
         } else {
           name = I18n.t('javascripts.directions.instructions.unnamed');
+          namedRoad = false;
         }
-        
-        if (step.maneuver.type.match(/rotary|roundabout/)) {
-          instText += I18n.t(template + '_with_exit', { exit: step.maneuver.exit, name: name } );
+
+        if (step.maneuver.type.match(/^exit (rotary|roundabout)$/)) {
+          instText += I18n.t(template, { name: name });
+        } else if (step.maneuver.type.match(/^(rotary|roundabout)$/)) {
+          if (step.maneuver.exit) {
+            if (step.maneuver.exit <= 10) {
+              instText += I18n.t(template + '_with_exit_ordinal', { exit: I18n.t('javascripts.directions.instructions.exit_counts.' + numToWord(step.maneuver.exit)), name: name });
+            } else {
+              instText += I18n.t(template + '_with_exit', { exit: step.maneuver.exit, name: name });
+            }
+          } else {
+            instText += I18n.t(template + '_without_exit', { name: name });
+          }
+        } else if (step.maneuver.type.match(/^(on ramp|off ramp)$/)) {
+          var params = {};
+          if (step.exits && step.maneuver.type.match(/^off ramp$/)) params.exit = step.exits;
+          if (step.destinations) params.directions = destinations;
+          if (namedRoad) params.directions = name;
+          if (Object.keys(params).length > 0) {
+            template = template + "_with_" + Object.keys(params).join("_");
+          }
+          instText += I18n.t(template, params);
         } else {
           instText += I18n.t(template + '_without_exit', { name: name });
         }