From 161ce947c3b753f68f5c6b27fea369d2e2b8c7ea Mon Sep 17 00:00:00 2001 From: Jamie Guthrie Date: Tue, 13 Feb 2018 17:28:09 +0000 Subject: [PATCH] Improve OSRM directions for on and off ramps Try and show both the name of the road being turned on to and the destination depending on what is available. Closes #1740 --- .../javascripts/index/directions/osrm.js | 21 +++++++++++++++++-- config/locales/en.yml | 12 +++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/index/directions/osrm.js b/app/assets/javascripts/index/directions/osrm.js index 3d32f07e3..5c29f6c4d 100644 --- a/app/assets/javascripts/index/directions/osrm.js +++ b/app/assets/javascripts/index/directions/osrm.js @@ -95,8 +95,10 @@ function OSRMEngine() { Array.prototype.push.apply(line, step_geometry); var instText = "" + (idx + 1) + ". "; - + var destinations = "" + step.destinations + ""; + var namedRoad = true; var name; + if (step.name && step.ref) { name = "" + step.name + " (" + step.ref + ")"; } else if (step.name) { @@ -105,10 +107,25 @@ function OSRMEngine() { name = "" + step.ref + ""; } 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 } ); + } else if (step.maneuver.type.match(/on ramp|off ramp/)) { + if (step.destinations) { + if (namedRoad) { + instText += I18n.t(template + '_with_name_and_directions', { name: name, directions: destinations } ); + } else { + instText += I18n.t(template + '_with_directions', { directions: destinations } ); + } + } else { + if (namedRoad) { + instText += I18n.t(template + '_without_exit', { name: name }); + } else { + instText += I18n.t(template + '_without_directions'); + } + } } else { instText += I18n.t(template + '_without_exit', { name: name }); } diff --git a/config/locales/en.yml b/config/locales/en.yml index 036f8de35..69e9041d4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2331,7 +2331,13 @@ en: continue_without_exit: Continue on %{name} slight_right_without_exit: Slight right onto %{name} offramp_right_without_exit: Take the ramp on the right onto %{name} + offramp_right_with_directions: Take the ramp on the right towards %{directions} + offramp_right_with_name_and_directions: Take the ramp on the right onto %{name}, towards %{directions} + offramp_right_without_directions: Take the ramp on the right onramp_right_without_exit: Turn right on the ramp onto %{name} + onramp_right_with_directions: Turn right onto the ramp towards %{directions} + onramp_right_with_name_and_directions: Turn right on the ramp onto %{name}, towards %{directions} + onramp_right_without_directions: Turn right onto the ramp endofroad_right_without_exit: At the end of the road turn right onto %{name} merge_right_without_exit: Merge right onto %{name} fork_right_without_exit: At the fork turn right onto %{name} @@ -2341,7 +2347,13 @@ en: sharp_left_without_exit: Sharp left onto %{name} turn_left_without_exit: Turn left onto %{name} offramp_left_without_exit: Take the ramp on the left onto %{name} + offramp_left_with_directions: Take the ramp on the left towards %{directions} + offramp_left_with_name_and_directions: Take the ramp on the left onto %{name}, towards %{directions} + offramp_left_without_directions: Take the ramp on the left onramp_left_without_exit: Turn left on the ramp onto %{name} + onramp_left_with_directions: Turn left onto the ramp towards %{directions} + onramp_left_with_name_and_directions: Turn left on the ramp onto %{name}, towards %{directions} + onramp_left_without_directions: Turn left onto the ramp endofroad_left_without_exit: At the end of the road turn left onto %{name} merge_left_without_exit: Merge left onto %{name} fork_left_without_exit: At the fork turn left onto %{name} -- 2.43.2