X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/6e5240e1987a429e29d230e811af9176772a8228..673b58f96f3acfd0281c62a2a7f080825b6fb28b:/app/assets/javascripts/index/directions.js diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index bb835f2fb..ce8ac9c1c 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -60,11 +60,16 @@ OSM.Directions = function (map) { endpoint.setValue(value); }); - endpoint.setValue = function(value) { + endpoint.setValue = function(value, latlng) { endpoint.value = value; delete endpoint.latlng; input.val(value); - endpoint.getGeocode(); + + if (latlng) { + endpoint.setLatLng(latlng); + } else { + endpoint.getGeocode(); + } }; endpoint.getGeocode = function() { @@ -76,7 +81,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 +116,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; @@ -348,22 +364,18 @@ OSM.Directions = function (map) { }); var params = querystring.parse(location.search.substring(1)), - route = (params.route || '').split(';'); + route = (params.route || '').split(';'), + from = route[0] && L.latLng(route[0].split(',')), + to = route[1] && L.latLng(route[1].split(',')); if (params.engine) { setEngine(params.engine); } - endpoints[0].setValue(params.from || ""); - endpoints[1].setValue(params.to || ""); - - var o = route[0] && L.latLng(route[0].split(',')), - d = route[1] && L.latLng(route[1].split(',')); - - if (o) endpoints[0].setLatLng(o); - if (d) endpoints[1].setLatLng(d); + endpoints[0].setValue(params.from || "", from); + endpoints[1].setValue(params.to || "", to); - map.setSidebarOverlaid(!o || !d); + map.setSidebarOverlaid(!from || !to); getRoute(); };