]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions.js
Go through the router when reversing directions
[rails.git] / app / assets / javascripts / index / directions.js
index bb835f2fb277f21d6db8ea946590f760782deeac..093afe30a9148836ac63a39cd985ee2b3538ae47 100644 (file)
@@ -76,7 +76,7 @@ OSM.Directions = function (map) {
 
       endpoint.awaitingGeocode = true;
 
-      $.getJSON(document.location.protocol + OSM.NOMINATIM_URL + 'search?q=' + encodeURIComponent(endpoint.value) + '&format=json', function (json) {
+      $.getJSON(OSM.NOMINATIM_URL + 'search?q=' + encodeURIComponent(endpoint.value) + '&format=json', function (json) {
         endpoint.awaitingGeocode = false;
         endpoint.hasGeocode = true;
         if (json.length === 0) {
@@ -111,6 +111,17 @@ OSM.Directions = function (map) {
     return endpoint;
   }
 
+  $(".directions_form .reverse_directions").on("click", function() {
+    var from = endpoints[0].latlng,
+        to = endpoints[1].latlng;
+
+    OSM.router.route("/directions?" + querystring.stringify({
+      from: $("#route_to").val(),
+      to: $("#route_from").val(),
+      route: from.lat + "," + from.lng + ";" + to.lat + "," + to.lng
+    }));
+  });
+
   $(".directions_form .close").on("click", function(e) {
     e.preventDefault();
     var route_from = endpoints[0].value;