From: Anton Khorev Date: Mon, 12 Aug 2024 02:19:22 +0000 (+0300) Subject: Limit coordinate precision in drag listener X-Git-Tag: live~299^2~2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/b4925d7b0dcb005cc501eeb90c72335e56468bf7?ds=sidebyside Limit coordinate precision in drag listener --- diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index 9ae7ce84f..87bd112ca 100644 --- a/app/assets/javascripts/index/directions-endpoint.js +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -31,7 +31,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch }; function markerDragListener(e) { - var latlng = e.target.getLatLng(); + var latlng = convertLatLngToZoomPrecision(e.target.getLatLng()); setLatLng(latlng); setInputValueFromLatLng(latlng); @@ -93,9 +93,13 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch } function setInputValueFromLatLng(latlng) { + input.val(latlng.lat + ", " + latlng.lng); + } + + function convertLatLngToZoomPrecision(latlng) { var precision = OSM.zoomPrecision(map.getZoom()); - input.val(latlng.lat.toFixed(precision) + ", " + latlng.lng.toFixed(precision)); + return L.latLng(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 7e8c18fb8..391c1f931 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -287,7 +287,8 @@ 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); - endpoints[type === "from" ? 0 : 1].setValue(value, ll); + var llWithPrecision = L.latLng(ll.lat.toFixed(precision), ll.lng.toFixed(precision)); + endpoints[type === "from" ? 0 : 1].setValue(value, llWithPrecision); }); endpoints[0].enable();