]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions.js
Drop ch.disable from graphhopper parameters
[rails.git] / app / assets / javascripts / index / directions.js
index 4f79ca4719bf014f6d9dc745d31a4487a1bd6011..5f9027ec6b9bc85edd0f5c20739da3be2e09fa7c 100644 (file)
@@ -105,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(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
+
+      $.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) {
@@ -139,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?" + querystring.stringify({
       from: $("#route_to").val(),
       to: $("#route_from").val(),
-      route: to.lat + "," + to.lng + ";" + from.lat + "," + from.lng
+      route: routeTo + ";" + routeFrom
     }));
   });