Replace geocode request boolean property with request object
This commit is contained in:
parent
a8838b3727
commit
5a1e3e5c67
1 changed files with 6 additions and 4 deletions
|
@ -25,6 +25,8 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
|
||||||
input.off("keydown", inputKeydownListener);
|
input.off("keydown", inputKeydownListener);
|
||||||
input.off("change", inputChangeListener);
|
input.off("change", inputChangeListener);
|
||||||
|
|
||||||
|
if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort();
|
||||||
|
delete endpoint.geocodeRequest;
|
||||||
map.removeLayer(endpoint.marker);
|
map.removeLayer(endpoint.marker);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,12 +65,12 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
|
||||||
};
|
};
|
||||||
|
|
||||||
function getGeocode() {
|
function getGeocode() {
|
||||||
endpoint.awaitingGeocode = true;
|
|
||||||
|
|
||||||
var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
|
var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
|
||||||
|
var geocodeUrl = OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox;
|
||||||
|
|
||||||
$.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox, function (json) {
|
if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort();
|
||||||
endpoint.awaitingGeocode = false;
|
endpoint.geocodeRequest = $.getJSON(geocodeUrl, function (json) {
|
||||||
|
delete endpoint.geocodeRequest;
|
||||||
if (json.length === 0) {
|
if (json.length === 0) {
|
||||||
input.addClass("is-invalid");
|
input.addClass("is-invalid");
|
||||||
alert(I18n.t("javascripts.directions.errors.no_place", { place: endpoint.value }));
|
alert(I18n.t("javascripts.directions.errors.no_place", { place: endpoint.value }));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue