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

Tom Hughes notifications at github.com
Sun Dec 3 19:31:54 UTC 2017


tomhughes 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");
+  });

What about if you include a `route` parameter in the URL with the actual lat/lon values? I think in that case it will use those rather than rerunning the geocode? So something like:

```
OSM.router.route("/directions?" + querystring.stringify({
  from: $("#route_to").val(),
  to: $("#route_from").val(),
  route: from_lat + "," + from_lon + ";" + to_lat + "," + to_lon
}));
```

although I haven't looked at how to get hold of the lat/lon values yet.


-- 
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_r154533979
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20171203/f813079b/attachment-0001.html>


More information about the rails-dev mailing list