mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
Keep a lookup's places when one tile fails, and ship every tile as its own file
- A tile that cannot be read is left out of placesNear's answer instead of failing it; without the pack's index the cities are still the answer. - The build no longer inlines the small tiles into one chunk that loaded with the first lookup: all 732 are their own files. - A row at latitude 90 or longitude 180 is tiled where the lookups read it. - --min-population 0 is taken as 0, not as the default. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
2a01269b87
commit
88919f760f
6 files changed
+40
-9
No files matched your search
@@ -251,7 +251,9 @@ async function readPlaceTiles(latitude, longitude, radiusKm, fetchImpl) {
|
||||
const keys = tileKeysAround(latitude, longitude, radiusKm).filter(
|
||||
(key) => index.tiles[key],
|
||||
);
|
||||
return Promise.all(
|
||||
// A tile that cannot be read is left out: the places of the others,
|
||||
// and the cities, are still the answer.
|
||||
const settled = await Promise.allSettled(
|
||||
keys.map((key) => {
|
||||
let load = tiles.get(key);
|
||||
if (load) tiles.delete(key);
|
||||
@@ -267,6 +269,9 @@ async function readPlaceTiles(latitude, longitude, radiusKm, fetchImpl) {
|
||||
return load();
|
||||
}),
|
||||
);
|
||||
return settled
|
||||
.filter((result) => result.status === 'fulfilled')
|
||||
.map((result) => result.value);
|
||||
}
|
||||
|
||||
async function readPlacePack(url, fetchImpl) {
|
||||
@@ -292,7 +297,8 @@ export async function placesNear(
|
||||
const radius = Math.min(radiusKm, Math.PI * EARTH_KM);
|
||||
const [{ cells }, detail] = await Promise.all([
|
||||
loadCities(fetchImpl),
|
||||
readPlaceTiles(latitude, longitude, radius, fetchImpl),
|
||||
// Without the pack's index there are still the cities.
|
||||
readPlaceTiles(latitude, longitude, radius, fetchImpl).catch(() => []),
|
||||
]);
|
||||
// A smaller place that has the name of a city within TWIN_KM in the same
|
||||
// country is the same place listed twice (a town and its municipality):
|
||||
|
||||
@@ -217,3 +217,18 @@ test('the detail tile cache keeps the 64 most recently used tiles', async () =>
|
||||
await placesNear(around(keys[0]), fetchPack);
|
||||
assert.equal(tileReads().length, 66);
|
||||
});
|
||||
|
||||
test('a tile that cannot be read leaves the other places and the cities', async () => {
|
||||
const { placesNear } = await import('./wikidataCities.js?failing');
|
||||
const fetchPack = async (url) =>
|
||||
/_-100\.json$/.test(url.pathname)
|
||||
? new Response('', { status: 503 })
|
||||
: new Response(await readFile(url));
|
||||
// Around Austin, on the corner of the 30_-100 and 30_-95 tiles.
|
||||
const near = await placesNear(
|
||||
{ latitude: 30.27, longitude: -97.74, radiusKm: 300, limit: Infinity },
|
||||
fetchPack,
|
||||
);
|
||||
assert.ok(near.some((place) => place.name === 'Austin'));
|
||||
assert.ok(near.some((place) => place.longitude > -95));
|
||||
});
|
||||
Reference in new issue
Block a user