From acfadceb6d0686e809f914485a3cfa450fc56542 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 30 May 2025 16:25:50 +0300 Subject: [PATCH] Fix overpass query feature areas for bounds including antimeridian --- app/assets/javascripts/index/query.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index d6cfbbcbb..cf3f94a8d 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -224,15 +224,12 @@ OSM.Query = function (map) { }); } - function compareSize(feature1, feature2) { - const width1 = feature1.bounds.maxlon - feature1.bounds.minlon, - height1 = feature1.bounds.maxlat - feature1.bounds.minlat, - area1 = width1 * height1, - width2 = feature2.bounds.maxlat - feature2.bounds.minlat, - height2 = feature2.bounds.maxlat - feature2.bounds.minlat, - area2 = width2 * height2; - - return area1 - area2; + function featureArea({ bounds }) { + const height = bounds.maxlat - bounds.minlat; + let width = bounds.maxlon - bounds.minlon; + + if (width < 0) width += 360; + return width * height; } /* @@ -282,7 +279,7 @@ OSM.Query = function (map) { }).addTo(map); runQuery(latlng, radius, nearby, $("#query-nearby"), false); - runQuery(latlng, radius, isin, $("#query-isin"), true, compareSize); + runQuery(latlng, radius, isin, $("#query-isin"), true, (feature1, feature2) => featureArea(feature1) - featureArea(feature2)); } function clickHandler(e) { -- 2.39.5