Don't set input value from endpoint.setLatLng()

This input value computed from coordinates is not always used. endpoint.getGeocode() overwrites it immediately.
This commit is contained in:
Anton Khorev 2024-08-11 05:29:33 +03:00
parent e0df084e57
commit f65593651f

View file

@ -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;
};