+ }
+ }
+
+ function getReverseGeocode() {
+ const latlng = endpoint.latlng.clone(),
+ { lat, lng } = latlng,
+ reverseGeocodeUrl = OSM.NOMINATIM_URL + "reverse?" + new URLSearchParams({ lat, lon: lng, format: "json" });
+
+ endpoint.geocodeRequest = new AbortController();
+ fetch(reverseGeocodeUrl, { signal: endpoint.geocodeRequest.signal })
+ .then(r => r.json())
+ .then(success)
+ .catch(() => {});
+
+ function success(json) {
+ delete endpoint.geocodeRequest;
+ if (!json || !json.display_name) {
+ endpoint.cachedReverseGeocode = { latlng: latlng, notFound: true };
+ return;
+ }
+
+ endpoint.value = json.display_name;
+ input.val(json.display_name);
+ endpoint.cachedReverseGeocode = { latlng: latlng, value: endpoint.value };
+ }