From 8d34cecc92476486a089e04bf3d52d18aa95fcd5 Mon Sep 17 00:00:00 2001 From: Marwin Hochfelsner <50826859+hlfan@users.noreply.github.com> Date: Sun, 15 Jun 2025 11:28:36 +0200 Subject: [PATCH] Ensure Overpass bounds compatibility --- app/assets/javascripts/index/query.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index 79d2b18d4..4b5e81d62 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -157,6 +157,13 @@ OSM.Query = function (map) { $section.find(".loader").hide(); + // Make Overpass-specific bounds to Leaflet compatible + for (const element of elements) { + if (!element.bounds) continue; + if (element.bounds.maxlon > element.bounds.minlon) continue; + element.bounds.maxlon += 360; + } + if (merge) { elements = Object.values(elements.reduce(function (hash, element) { const key = element.type + element.id; @@ -211,12 +218,8 @@ OSM.Query = function (map) { .appendTo($ul); } - function featureArea({ bounds }) { - const height = bounds.maxlat - bounds.minlat; - let width = bounds.maxlon - bounds.minlon; - - if (width < 0) width += 360; - return width * height; + function size({ maxlon, minlon, maxlat, minlat }) { + return (maxlon - minlon) * (maxlat - minlat); } /* @@ -263,7 +266,7 @@ OSM.Query = function (map) { }).addTo(map); runQuery(nearby, $("#query-nearby"), false); - runQuery(isin, $("#query-isin"), true, (feature1, feature2) => featureArea(feature1) - featureArea(feature2)); + runQuery(isin, $("#query-isin"), true, (feature1, feature2) => size(feature1.bounds) - size(feature2.bounds)); } function clickHandler(e) { -- 2.39.5