From: Anton Khorev Date: Sun, 11 Aug 2024 02:29:33 +0000 (+0300) Subject: Don't set input value from endpoint.setLatLng() X-Git-Tag: live~276^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/f65593651f17f1bb2caa6a757ca377c094ea7a02?ds=sidebyside Don't set input value from endpoint.setLatLng() This input value computed from coordinates is not always used. endpoint.getGeocode() overwrites it immediately. --- diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index 0f53e77d9..b9a4ff9a2 100644 --- a/app/assets/javascripts/index/directions-endpoint.js +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -15,7 +15,11 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge }); endpoint.marker.on("drag dragend", function (e) { - endpoint.setLatLng(e.target.getLatLng()); + var latlng = e.target.getLatLng(); + + endpoint.setLatLng(latlng); + setInputValueFromLatLng(latlng); + endpoint.value = input.val(); dragCallback(e.type === "drag"); }); @@ -37,6 +41,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge if (latlng) { endpoint.setLatLng(latlng); + setInputValueFromLatLng(latlng); } else { endpoint.getGeocode(); } @@ -71,8 +76,6 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge }; endpoint.setLatLng = function (ll) { - var precision = OSM.zoomPrecision(map.getZoom()); - input.val(ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision)); endpoint.hasGeocode = true; endpoint.latlng = ll; endpoint.marker @@ -80,5 +83,11 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge .addTo(map); }; + function setInputValueFromLatLng(latlng) { + var precision = OSM.zoomPrecision(map.getZoom()); + + input.val(latlng.lat.toFixed(precision) + ", " + latlng.lng.toFixed(precision)); + } + return endpoint; };