From: Tom Hughes Date: Sun, 6 Mar 2016 20:42:04 +0000 (+0000) Subject: Fix query tool to get correct bounds for enclosing ways X-Git-Tag: live~3900 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/0ff7a928e4359b177a43b7d2e8e1e0e468c2be53?hp=9f9ba18baabc00fb3be582c6e86513dcbcb4f3f7;ds=sidebyside Fix query tool to get correct bounds for enclosing ways The bounding box returned by overpass for geom output is only the bounds for the clipped geometry, so fetch the geometry and the bounding box separately and merge them client side. Fixes #1156 --- diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index 333fce549..1e1dc2ed1 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -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(); @@ -186,12 +186,24 @@ OSM.Query = function(map) { $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; + 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]; @@ -268,7 +280,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 +299,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) {