From c267e58418f3c2a28bce0cb54c6eba3e05c725fb Mon Sep 17 00:00:00 2001 From: you Date: Sun, 22 Mar 2026 23:59:33 +0000 Subject: [PATCH] Fix: sort regional candidates by distance to IATA center MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without sender GPS (channel texts etc), the forward pass had no anchor and just took candidates[0] — random order. Now regional candidates are sorted by distKm to observer IATA center before disambiguation. Closest to region center = default pick. --- public/hop-resolver.js | 1 + public/index.html | 2 +- server.js | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/public/hop-resolver.js b/public/hop-resolver.js index 8cad87f0..8497a047 100644 --- a/public/hop-resolver.js +++ b/public/hop-resolver.js @@ -106,6 +106,7 @@ window.HopResolver = (function() { return { ...c, regional: r ? r.near : false, filterMethod: r ? r.method : 'none', distKm: r ? r.distKm : undefined }; }); const regional = checked.filter(c => c.regional); + regional.sort((a, b) => (a.distKm || 9999) - (b.distKm || 9999)); const candidates = regional.length > 0 ? regional : checked; const globalFallback = regional.length === 0 && checked.length > 0 && packetIata != null; diff --git a/public/index.html b/public/index.html index 1e1892b0..2e590ba4 100644 --- a/public/index.html +++ b/public/index.html @@ -82,7 +82,7 @@ - + diff --git a/server.js b/server.js index e5773075..d331b100 100644 --- a/server.js +++ b/server.js @@ -2097,6 +2097,8 @@ app.get('/api/resolve-hops', (req, res) => { return { ...c, regional: r.near, filterMethod: r.method, distKm: r.distKm }; }); const regional = checked.filter(c => c.regional); + // Sort by distance to region center — closest first + regional.sort((a, b) => (a.distKm || 9999) - (b.distKm || 9999)); const candidates = regional.length > 0 ? regional : checked; const globalFallback = regional.length === 0 && checked.length > 0;