Merge remote-tracking branch 'upstream/pull/5072'

This commit is contained in:
Tom Hughes 2024-08-14 19:12:59 +01:00
commit 953d8b4b59
2 changed files with 19 additions and 8 deletions

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();
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;
};

View file

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