From 7a933cf928cfca83e5448c699fa84d1e209ba0a7 Mon Sep 17 00:00:00 2001 From: J Guthrie Date: Fri, 1 Dec 2017 01:38:23 +0000 Subject: [PATCH] Added 'Reverse Directions' link Added a text link that reverses the directions of the planned route --- app/assets/javascripts/index/directions.js | 16 ++++++++++++++++ app/assets/stylesheets/common.scss | 5 +++++ app/views/layouts/_search.html.erb | 3 +++ config/locales/en.yml | 1 + 4 files changed, 25 insertions(+) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index bb835f2fb..03e023bc1 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -32,6 +32,8 @@ OSM.Directions = function (map) { function Endpoint(input, iconUrl) { var endpoint = {}; + endpoint.input = input; + endpoint.marker = L.marker([0, 0], { icon: L.icon({ iconUrl: iconUrl, @@ -111,6 +113,20 @@ OSM.Directions = function (map) { return endpoint; } + $(".directions_form .reverse_directions").on("click", function() { + var input_from = endpoints[0].input.val(); + var input_to = endpoints[1].input.val(); + var latlng_from = endpoints[0].latlng; + var latlng_to = endpoints[1].latlng; + + endpoints[0].setLatLng(latlng_to); + endpoints[1].setLatLng(latlng_from); + endpoints[0].input.val(input_to); + endpoints[1].input.val(input_from); + + getRoute(); + }); + $(".directions_form .close").on("click", function(e) { e.preventDefault(); var route_from = endpoints[0].value; diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 6b99662a4..2f1215b5d 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -1002,6 +1002,11 @@ header .search_forms, vertical-align: middle; } } + + a.reverse_directions { + cursor: pointer; + margin: 0px 0px 5px 25px; + } } /* Rules for the map key which appears in the popout sidebar */ diff --git a/app/views/layouts/_search.html.erb b/app/views/layouts/_search.html.erb index 2637d28b2..98b3c6c54 100644 --- a/app/views/layouts/_search.html.erb +++ b/app/views/layouts/_search.html.erb @@ -23,6 +23,9 @@ <%= submit_tag t('site.search.submit_text'), :class => "routing_go", :data => { disable_with: false } %> +
+ <%= t('site.search.reverse_directions_text') %> +
<%= image_tag "searching.gif" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 062fd95d4..70b67a24e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1424,6 +1424,7 @@ en: where_am_i: "Where is this?" where_am_i_title: Describe the current location using the search engine submit_text: "Go" + reverse_directions_text: "Reverse Directions" key: table: entry: -- 2.43.2