X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/a47c0a4411825f48e447641094678b15df3b2f74..c70e919b472732fd3cf0ae340af28f2624278f6d:/app/assets/javascripts/index/directions.js diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 71eedaa83..5f9027ec6 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -1,7 +1,10 @@ //= require_self //= require_tree ./directions +//= require querystring OSM.Directions = function (map) { + var querystring = require("querystring-component"); + var awaitingGeocode; // true if the user has requested a route, but we're waiting on a geocode result var awaitingRoute; // true if we've asked the engine for a route and are waiting to hear back var chosenEngine; @@ -102,7 +105,9 @@ OSM.Directions = function (map) { endpoint.awaitingGeocode = true; - $.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json", function (json) { + var viewbox = map.getBounds().toBBoxString(); // ,,, + + $.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox, function (json) { endpoint.awaitingGeocode = false; endpoint.hasGeocode = true; if (json.length === 0) { @@ -136,13 +141,21 @@ OSM.Directions = function (map) { } $(".directions_form .reverse_directions").on("click", function () { - var from = endpoints[0].latlng, - to = endpoints[1].latlng; + var coordFrom = endpoints[0].latlng, + coordTo = endpoints[1].latlng, + routeFrom = "", + routeTo = ""; + if (coordFrom) { + routeFrom = coordFrom.lat + "," + coordFrom.lng; + } + if (coordTo) { + routeTo = coordTo.lat + "," + coordTo.lng; + } - OSM.router.route("/directions?" + qs.stringify({ + OSM.router.route("/directions?" + querystring.stringify({ from: $("#route_to").val(), to: $("#route_from").val(), - route: to.lat + "," + to.lng + ";" + from.lat + "," + from.lng + route: routeTo + ";" + routeFrom })); }); @@ -210,7 +223,7 @@ OSM.Directions = function (map) { var precision = OSM.zoomPrecision(map.getZoom()); - OSM.router.replace("/directions?" + qs.stringify({ + OSM.router.replace("/directions?" + querystring.stringify({ engine: chosenEngine.id, route: o.lat.toFixed(precision) + "," + o.lng.toFixed(precision) + ";" + d.lat.toFixed(precision) + "," + d.lng.toFixed(precision) @@ -367,7 +380,7 @@ OSM.Directions = function (map) { getRoute(true, true); }); - var params = qs.parse(location.search.substring(1)), + var params = querystring.parse(location.search.substring(1)), route = (params.route || "").split(";"), from = route[0] && L.latLng(route[0].split(",")), to = route[1] && L.latLng(route[1].split(","));