X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/e206dd527ef7c6d1829f131533d722e536e4bfb5..5ca24de0d04bef18353d3f0ecdd069d0bca34ce2:/app/assets/javascripts/index/query.js diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index 5c8ee8876..3673da5db 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -115,17 +115,16 @@ OSM.Query = function (map) { } } - if (tags.name) { - return tags.name; - } else if (tags.ref) { - return tags.ref; - } else if (tags["addr:housename"]) { - return tags["addr:housename"]; - } else if (tags["addr:housenumber"] && tags["addr:street"]) { + for (const key of ["name", "ref", "addr:housename"]) { + if (tags[key]) { + return tags[key]; + } + } + + if (tags["addr:housenumber"] && tags["addr:street"]) { return tags["addr:housenumber"] + " " + tags["addr:street"]; - } else { - return "#" + feature.id; } + return "#" + feature.id; } function featureGeometry(feature) { @@ -158,16 +157,17 @@ OSM.Query = function (map) { $section.data("ajax").abort(); } - $section.data("ajax", $.ajax({ - url: url, + $section.data("ajax", new AbortController()); + fetch(url, { method: "POST", - data: { + body: new URLSearchParams({ data: "[timeout:10][out:json];" + query - }, - xhrFields: { - withCredentials: credentials - }, - success: function (results) { + }), + credentials: credentials ? "include" : "same-origin", + signal: $section.data("ajax").signal + }) + .then(response => response.json()) + .then(function (results) { var elements; $section.find(".loader").hide(); @@ -222,16 +222,17 @@ OSM.Query = function (map) { .text(I18n.t("javascripts.query.nothing_found")) .appendTo($ul); } - }, - error: function (xhr, status, error) { + }) + .catch(function (error) { + if (error.name === "AbortError") return; + $section.find(".loader").hide(); $("
  • ") .addClass("list-group-item") - .text(I18n.t("javascripts.query." + status, { server: url, error: error })) + .text(I18n.t("javascripts.query.error", { server: url, error: error.message })) .appendTo($ul); - } - })); + }); } function compareSize(feature1, feature2) { @@ -285,10 +286,11 @@ OSM.Query = function (map) { .hide(); if (marker) map.removeLayer(marker); - marker = L.circle(latlng, Object.assign({ + marker = L.circle(latlng, { radius: radius, - className: "query-marker" - }, featureStyle)).addTo(map); + className: "query-marker", + ...featureStyle + }).addTo(map); runQuery(latlng, radius, nearby, $("#query-nearby"), false); runQuery(latlng, radius, isin, $("#query-isin"), true, compareSize);