]> git.openstreetmap.org Git - rails.git/commitdiff
Remove latlng parameter from endpoint.setValue
authorAnton Khorev <tony29@yandex.ru>
Sun, 11 Aug 2024 03:18:26 +0000 (06:18 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 8 Sep 2024 07:31:10 +0000 (10:31 +0300)
app/assets/javascripts/index/directions-endpoint.js
app/assets/javascripts/index/directions.js

index 59f0b929d497a14bb2e790d80c2ba5f0aa1d3924..b475b9a05e728904b14b1b50bd03e6fe60a15cf8 100644 (file)
@@ -55,7 +55,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
     endpoint.setValue(value);
   }
 
-  endpoint.setValue = function (value, latlng) {
+  endpoint.setValue = function (value) {
     endpoint.value = value;
     removeLatLng();
     input.removeClass("is-invalid");
@@ -64,6 +64,9 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
     if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort();
     delete endpoint.geocodeRequest;
 
+    var coordinatesMatch = value.match(/^\s*([+-]?\d+(?:\.\d*)?)(?:\s+|\s*[/,]\s*)([+-]?\d+(?:\.\d*)?)\s*$/);
+    var latlng = coordinatesMatch && L.latLng(coordinatesMatch[1], coordinatesMatch[2]);
+
     if (latlng) {
       setLatLng(latlng);
       setInputValueFromLatLng(latlng);
index 391c1f9315c7fe945d822d49380f9578729e79c0..18f5b0b943238636d170d2a357b839b0000e2c99 100644 (file)
@@ -287,17 +287,14 @@ OSM.Directions = function (map) {
       var ll = map.containerPointToLatLng(pt);
       var precision = OSM.zoomPrecision(map.getZoom());
       var value = ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision);
-      var llWithPrecision = L.latLng(ll.lat.toFixed(precision), ll.lng.toFixed(precision));
-      endpoints[type === "from" ? 0 : 1].setValue(value, llWithPrecision);
+      endpoints[type === "from" ? 0 : 1].setValue(value);
     });
 
     endpoints[0].enable();
     endpoints[1].enable();
 
     var params = Qs.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(","));
+        route = (params.route || "").split(";");
 
     if (params.engine) {
       var engineIndex = findEngine(params.engine);
@@ -307,10 +304,10 @@ OSM.Directions = function (map) {
       }
     }
 
-    endpoints[0].setValue(params.from || "", from);
-    endpoints[1].setValue(params.to || "", to);
+    endpoints[0].setValue(params.from || route[0] || "");
+    endpoints[1].setValue(params.to || route[1] || "");
 
-    map.setSidebarOverlaid(!from || !to);
+    map.setSidebarOverlaid(!endpoints[0].latlng || !endpoints[1].latlng);
   };
 
   page.load = function () {