]> git.openstreetmap.org Git - rails.git/commitdiff
Save lat/lon to input data attributes
authorAnton Khorev <tony29@yandex.ru>
Mon, 12 Aug 2024 02:39:58 +0000 (05:39 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 20 Aug 2024 11:55:29 +0000 (14:55 +0300)
app/assets/javascripts/index/directions-endpoint.js

index 87bd112ca8fa97e74a734205d18239d5b34a4728..3ffb9b498723f06363cfe1f94c246e39ec864ca9 100644 (file)
@@ -51,7 +51,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
 
   endpoint.setValue = function (value, latlng) {
     endpoint.value = value;
-    delete endpoint.latlng;
+    removeLatLng();
     input.removeClass("is-invalid");
     input.val(value);
 
@@ -86,12 +86,22 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
   }
 
   function setLatLng(ll) {
+    input
+      .attr("data-lat", ll.lat)
+      .attr("data-lon", ll.lng);
     endpoint.latlng = ll;
     endpoint.marker
       .setLatLng(ll)
       .addTo(map);
   }
 
+  function removeLatLng() {
+    input
+      .removeAttr("data-lat")
+      .removeAttr("data-lon");
+    delete endpoint.latlng;
+  }
+
   function setInputValueFromLatLng(latlng) {
     input.val(latlng.lat + ", " + latlng.lng);
   }