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

This commit is contained in:
Tom Hughes 2024-08-18 12:16:22 +01:00
commit 41b81bd393
2 changed files with 4 additions and 24 deletions

View file

@ -43,25 +43,18 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
setLatLng(latlng);
setInputValueFromLatLng(latlng);
changeCallback();
} else {
endpoint.getGeocode();
} else if (endpoint.value) {
getGeocode();
}
};
endpoint.getGeocode = function () {
// if no one has entered a value yet, then we can't geocode, so don't
// even try.
if (!endpoint.value) {
return;
}
function getGeocode() {
endpoint.awaitingGeocode = true;
var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
$.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox, function (json) {
endpoint.awaitingGeocode = false;
endpoint.hasGeocode = true;
if (json.length === 0) {
input.addClass("is-invalid");
alert(I18n.t("javascripts.directions.errors.no_place", { place: endpoint.value }));
@ -74,10 +67,9 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
changeCallback();
});
};
}
function setLatLng(ll) {
endpoint.hasGeocode = true;
endpoint.latlng = ll;
endpoint.marker
.setLatLng(ll)

View file

@ -115,18 +115,6 @@ OSM.Directions = function (map) {
// Cancel any route that is already in progress
if (routeRequest) routeRequest.abort();
// go fetch geocodes for any endpoints which have not already
// been geocoded.
for (var ep_i = 0; ep_i < 2; ++ep_i) {
var endpoint = endpoints[ep_i];
if (!endpoint.hasGeocode && !endpoint.awaitingGeocode) {
endpoint.getGeocode();
}
}
if (endpoints[0].awaitingGeocode || endpoints[1].awaitingGeocode) {
return;
}
var o = endpoints[0].latlng,
d = endpoints[1].latlng;