fix(places): a small place in view comes before a far bigger namesake

findPlace looked at the detail tiles only when no city had the typed name,
so a village called Paris in view lost to Paris, France. With
includeSmallPlaces it now reads the places near the view as well and takes
the nearest place of the name there, city or not. With none near, the
largest city of the name still wins.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 22:34:59 -08:00
1 parent ec1fc6bc09
commit f414df97eb
5 files changed
+89 -24

No files matched your search

+49
View File
@@ -96,6 +96,55 @@ test('findPlace takes a country qualifier and prefers a namesake in view', async
);
});
test('a small place in view comes before a far bigger city of its name', async () => {
const module = await import(`./wikidataCities.js?small-${Date.now()}`);
// A village called Paris near Austin, in the 30_-100 detail tile.
const village = ['Paris', 30.4, -97.6, 1200, 'US', 'Q-village'];
const fetchImpl = async (url) => {
const file = url.pathname.split('/').at(-1);
const body =
file === 'cities.json'
? { meta: {}, rows: PARIS }
: file === 'index.json'
? { tiles: { '30_-100': 1 } }
: { rows: file === '30_-100.json' ? [village] : [] };
return { ok: true, json: async () => body };
};
const find = (name, near) =>
module.findPlace(name, { near, includeSmallPlaces: true }, fetchImpl);
const austin = { latitude: 30.27, longitude: -97.74 };
assert.equal((await find('Paris', austin)).wikidata, 'Q-village');
assert.ok((await find('Paris', austin)).distanceKm < 20);
// Only when small places are asked for.
assert.equal(
(await module.findPlace('Paris', { near: austin }, fetchImpl)).wikidata,
'Q90',
);
// A qualifier still decides.
assert.equal((await find('Paris, France', austin)).wikidata, 'Q90');
// Nowhere near the village: the largest city of the name.
assert.equal(
(await find('Paris', { latitude: 0, longitude: 0 })).wikidata,
'Q90',
);
assert.equal(
(await module.findPlace('Paris', {}, fetchImpl)).wikidata,
'Q90',
);
// Paris, Texas is nearer a view over it than the village is.
const texas = { latitude: 33.6, longitude: -95.6 };
assert.equal(
(
await module.findPlace(
'Paris',
{ near: texas, radiusKm: 600, includeSmallPlaces: true },
fetchImpl,
)
).wikidata,
'Q830149',
);
});
test('a circle that reaches a pole spans every longitude', () => {
assert.equal(lonHalfSpan(89, 150), 180);
assert.ok(lonHalfSpan(60, 150) < 3);