fix(atlas): assign border places by polygon, not just bounding box (#1331)

getCountryFromCoords picked the country with the smallest bounding box containing the point, so a place just across a border (e.g. Strasbourg, which sits inside both the FR and DE boxes) landed in the wrong, smaller-box country. When more than one country box matches, it now disambiguates with the real admin0 polygon via point-in-polygon, smallest-box-first; a micro-territory with no admin0 polygon (HK, MO, SM, VA, ...) keeps the smallest-box win, and an unmatched point falls back to the old behaviour. The common single-candidate case is unchanged.
This commit is contained in:
Maurice
2026-06-27 16:15:53 +02:00
committed by Maurice
parent f3b54166fb
commit 4cb9b18cc6
2 changed files with 83 additions and 11 deletions
@@ -171,6 +171,23 @@ describe('getCountryFromCoords', () => {
const code = getCountryFromCoords(0.0, 0.0);
expect(code).toBeNull();
});
it('ATLAS-SVC-005b: #1331 a point inside France near the German border resolves to FR, not the smaller overlapping box', () => {
// Strasbourg (48.573, 7.752) sits inside BOTH the FR and DE bounding boxes; the old
// smallest-box rule mis-picked DE (its box is smaller). Point-in-polygon picks FR.
expect(getCountryFromCoords(48.5734, 7.7521)).toBe('FR');
});
it('ATLAS-SVC-005c: #1331 a point inside Germany near the French border resolves to DE', () => {
// Kehl (48.575, 7.815) — the German side of the same border.
expect(getCountryFromCoords(48.5750, 7.8150)).toBe('DE');
});
it('ATLAS-SVC-005d: #1331 a micro-territory without an admin0 polygon keeps the smallest-box win (Hong Kong)', () => {
// HK is not a separate admin0 polygon (it falls inside CN there), so the smallest
// bounding box still wins for it.
expect(getCountryFromCoords(22.30, 114.17)).toBe('HK');
});
});
// ── getCountryFromAddress ───────────────────────────────────────────────────