From: Tom Hughes Date: Wed, 14 Aug 2024 18:12:59 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/5072' X-Git-Tag: live~1129 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/953d8b4b59e8b194bf83b094ecfd9f5e368a04b8?hp=257ecde90d81a23b9cfcd2376ee39374b8fa2e7b Merge remote-tracking branch 'upstream/pull/5072' --- diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index 0f53e77d9..14c91a4fb 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(); + + setLatLng(latlng); + setInputValueFromLatLng(latlng); + endpoint.value = input.val(); dragCallback(e.type === "drag"); }); @@ -36,7 +40,8 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge input.val(value); if (latlng) { - endpoint.setLatLng(latlng); + setLatLng(latlng); + setInputValueFromLatLng(latlng); } else { endpoint.getGeocode(); } @@ -62,7 +67,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge return; } - endpoint.setLatLng(L.latLng(json[0])); + setLatLng(L.latLng(json[0])); input.val(json[0].display_name); @@ -70,15 +75,19 @@ 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)); + function setLatLng(ll) { endpoint.hasGeocode = true; endpoint.latlng = ll; endpoint.marker .setLatLng(ll) .addTo(map); - }; + } + + function setInputValueFromLatLng(latlng) { + var precision = OSM.zoomPrecision(map.getZoom()); + + input.val(latlng.lat.toFixed(precision) + ", " + latlng.lng.toFixed(precision)); + } return endpoint; }; diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index ccd4a68c2..974a40e85 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -300,7 +300,9 @@ OSM.Directions = function (map) { var pt = L.DomEvent.getMousePosition(oe, map.getContainer()); // co-ordinates of the mouse pointer at present pt.y += 20; var ll = map.containerPointToLatLng(pt); - endpoints[type === "from" ? 0 : 1].setLatLng(ll); + var precision = OSM.zoomPrecision(map.getZoom()); + var value = ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision); + endpoints[type === "from" ? 0 : 1].setValue(value, ll); getRoute(true, true); });