]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions.js.erb
Avoid mixed content warnings when routing queries Nominatim
[rails.git] / app / assets / javascripts / index / directions.js.erb
index c3ad085ffeda4c20560d4b122cca6e87743f9fb7..faa9226358f6ca1471f98a7b8788dc386359defe 100644 (file)
@@ -1,5 +1,5 @@
 //= require_self
-//= require_tree ./directions_engines
+//= require_tree ./directions
 
 OSM.Directions = function (map) {
   var awaitingGeocode; // true if the user has requested a route, but we're waiting on a geocode result
@@ -55,12 +55,13 @@ OSM.Directions = function (map) {
       // make text the same in both text boxes
       var value = e.target.value;
       endpoint.setValue(value)
-      endpoint.getGeocode();
     });
 
     endpoint.setValue = function(value) {
       endpoint.value = value;
+      delete endpoint.latlng;
       input.val(value);
+      endpoint.getGeocode();
     }
 
     endpoint.getGeocode = function() {
@@ -72,7 +73,7 @@ OSM.Directions = function (map) {
 
       endpoint.awaitingGeocode = true;
 
-      $.getJSON('<%= NOMINATIM_URL %>search?q=' + encodeURIComponent(endpoint.value) + '&format=json', function (json) {
+      $.getJSON(document.location.protocol + '<%= NOMINATIM_URL %>search?q=' + encodeURIComponent(endpoint.value) + '&format=json', function (json) {
         endpoint.awaitingGeocode = false;
         endpoint.hasGeocode = true;
         if (json.length == 0) {
@@ -109,7 +110,7 @@ OSM.Directions = function (map) {
 
   $(".directions_form a.directions_close").on("click", function(e) {
     e.preventDefault();
-    var route_from = endpoint[0].value;
+    var route_from = endpoints[0].value;
     if (route_from) {
       OSM.router.route("/?query=" + encodeURIComponent(route_from) + OSM.formatHash(map));
     } else {
@@ -162,6 +163,7 @@ OSM.Directions = function (map) {
         d = endpoints[1].latlng;
 
     if (!o || !d) return;
+    $("header").addClass("closed");
 
     var precision = OSM.zoomPrecision(map.getZoom());
 
@@ -294,7 +296,6 @@ OSM.Directions = function (map) {
 
   $(".directions_form").on("submit", function(e) {
     e.preventDefault();
-    $("header").addClass("closed");
     getRoute();
   });
 
@@ -338,6 +339,10 @@ OSM.Directions = function (map) {
 
     if (params.from) {
       endpoints[0].setValue(params.from);
+      endpoints[1].setValue("");
+    } else {
+      endpoints[0].setValue("");
+      endpoints[1].setValue("");
     }
 
     var o = route[0] && L.latLng(route[0].split(',')),