mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02:21 +00:00
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:
1 parent
ec1fc6bc09
commit
f414df97eb
5 files changed
+89
-24
No files matched your search
+24
-20
@@ -339,12 +339,13 @@ export async function placesNear(
|
||||
const TWIN_KM = 3;
|
||||
|
||||
/**
|
||||
* The city with this name, or null. A qualifier after a comma that names a
|
||||
* country ("Paris, France", "Paris, US") keeps only cities there, and finds
|
||||
* The place with this name, or null. A qualifier after a comma that names a
|
||||
* country ("Paris, France", "Paris, US") keeps only places there, and finds
|
||||
* nothing when none is; one that names no country ("Paris, Texas") is
|
||||
* ignored. A city of that name within `radiusKm` of `near` (the view) wins,
|
||||
* the nearest first, else the largest city of that name anywhere. Omnibar
|
||||
* can also ask for a smaller place nearby when the cities pack has no match.
|
||||
* ignored. A place of that name within `radiusKm` of `near` (the view) wins,
|
||||
* the nearest first, else the largest city of that name anywhere. With
|
||||
* `includeSmallPlaces`, the smaller places of the detail tiles near the view
|
||||
* count too: a village in view comes before a far bigger city of its name.
|
||||
*/
|
||||
export async function findPlace(
|
||||
name,
|
||||
@@ -360,20 +361,6 @@ export async function findPlace(
|
||||
const cities = (names.get(wanted) || []).filter(
|
||||
(row) => !country || row[4] === country,
|
||||
);
|
||||
if (!cities.length) {
|
||||
if (!includeSmallPlaces || !near) return null;
|
||||
const nearby = await placesNear(
|
||||
{ ...near, radiusKm, limit: Infinity },
|
||||
fetchImpl,
|
||||
);
|
||||
return (
|
||||
nearby.find(
|
||||
(place) =>
|
||||
foldName(place.name) === wanted &&
|
||||
(!country || place.country === country),
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
if (Number.isFinite(near?.latitude) && Number.isFinite(near?.longitude)) {
|
||||
let best = null;
|
||||
for (const row of cities) {
|
||||
@@ -381,7 +368,24 @@ export async function findPlace(
|
||||
if (km <= radiusKm && (!best || km < best.distanceKm))
|
||||
best = toCity(row, km);
|
||||
}
|
||||
if (includeSmallPlaces) {
|
||||
const nearby = await placesNear(
|
||||
{
|
||||
latitude: near.latitude,
|
||||
longitude: near.longitude,
|
||||
radiusKm,
|
||||
limit: Infinity,
|
||||
},
|
||||
fetchImpl,
|
||||
);
|
||||
const small = nearby.find(
|
||||
(place) =>
|
||||
foldName(place.name) === wanted &&
|
||||
(!country || place.country === country),
|
||||
);
|
||||
if (small && (!best || small.distanceKm < best.distanceKm)) best = small;
|
||||
}
|
||||
if (best) return best;
|
||||
}
|
||||
return toCity(cities[0], 0);
|
||||
return cities.length ? toCity(cities[0], 0) : null;
|
||||
}
|
||||
Reference in new issue
Block a user