X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/2d22ab10f759828e27876f138b419ff4c0913b87..c5ef6404f5782c8305f9d1d25d2c99a545cdd9a1:/app/assets/javascripts/index/query.js diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index 333fce549..018aedf98 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -12,7 +12,7 @@ OSM.Query = function(map) { weight: 4, opacity: 1, fillOpacity: 0.5, - clickable: false + interactive: false }; queryButton.on("click", function (e) { @@ -161,7 +161,7 @@ OSM.Query = function(map) { return geometry; } - function runQuery(latlng, radius, query, $section, compare) { + function runQuery(latlng, radius, query, $section, merge, compare) { var $ul = $section.find("ul"); $ul.empty(); @@ -179,19 +179,34 @@ OSM.Query = function(map) { url: url, method: "POST", data: { - data: "[timeout:5][out:json];" + query, + data: "[timeout:10][out:json];" + query, }, success: function(results) { var elements; $section.find(".loader").stopTime("loading").hide(); - if (compare) { - elements = results.elements.sort(compare); + if (merge) { + elements = results.elements.reduce(function (hash, element) { + var key = element.type + element.id; + if ("geometry" in element) { + delete element.bounds; + } + hash[key] = $.extend({}, hash[key], element); + return hash; + }, {}); + + elements = Object.keys(elements).map(function (key) { + return elements[key]; + }); } else { elements = results.elements; } + if (compare) { + elements = elements.sort(compare); + } + for (var i = 0; i < elements.length; i++) { var element = elements[i]; @@ -211,6 +226,12 @@ OSM.Query = function(map) { } } + if (results.remark) { + $("
  • ") + .text(I18n.t("javascripts.query.error", { server: url, error: results.remark })) + .appendTo($ul); + } + if ($ul.find("li").length === 0) { $("
  • ") .text(I18n.t("javascripts.query.nothing_found")) @@ -268,7 +289,7 @@ OSM.Query = function(map) { ways = "way(" + around + ")", relations = "relation(" + around + ")", nearby = "(" + nodes + ";" + ways + ");out tags geom(" + bbox + ");" + relations + ";out geom(" + bbox + ");", - isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags geom(" + bbox + ");relation(pivot.a);out tags bb;"; + isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags bb;out ids geom(" + bbox + ");relation(pivot.a);out tags bb;"; $("#sidebar_content .query-intro") .hide(); @@ -287,8 +308,8 @@ OSM.Query = function(map) { } }, 10); - runQuery(latlng, radius, nearby, $("#query-nearby")); - runQuery(latlng, radius, isin, $("#query-isin"), compareSize); + runQuery(latlng, radius, nearby, $("#query-nearby"), false); + runQuery(latlng, radius, isin, $("#query-isin"), true, compareSize); } function clickHandler(e) {