Limit coordinate precision in drag listener
This commit is contained in:
parent
c5aa012dc2
commit
b4925d7b0d
2 changed files with 8 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue