[openstreetmap/openstreetmap-website] Added 'Reverse Directions' link (#1693)

Jamie Guthrie notifications at github.com
Sun Dec 17 01:35:32 UTC 2017


jguthrie100 commented on this pull request.



> @@ -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);
+
+    $(".directions_form .routing_go").trigger("click");
+  });

I've recommitted with some changes.

The OSM.router.route method fails to work in the example given in the linked Issue (I think its because the latlng values of each marker don't get set when linking straight from the URL, rather than after clicking the "Go" button)

Instead of making things too complicated, I've made a simple call to getRoute(), which handles the setting of all latlng values and includes a call to OSM.router.route.

It now works with the example in the linked Issue as well as normal situations when clicking the "Go" button

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/1693#discussion_r157355644
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20171217/53858925/attachment.html>


More information about the rails-dev mailing list