Files
gpx.studio/website/src/lib/components/map/open-satellite.test.ts
T

58 lines
2.5 KiB
TypeScript
Raw Normal View History

2026-11-29 12:52:41 +01:00
// Which imagery each tile of the open satellite basemap is made of.
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { planTile } from './open-satellite';
function tile(lon: number, lat: number, z: number): [number, number, number] {
const n = 2 ** z;
const sin = Math.sin((lat * Math.PI) / 180);
return [
z,
Math.floor(((lon + 180) / 360) * n),
Math.floor((0.5 - Math.log((1 + sin) / (1 - sin)) / (4 * Math.PI)) * n),
];
}
async function plan(lon: number, lat: number, z: number) {
const { parts, fallback } = await planTile(...tile(lon, lat, z));
return { parts: parts.map((p) => `${p.source.id}:${p.relation}`), fallback };
}
describe('planTile', () => {
it('takes a tile inside a country from its agency alone', async () => {
assert.deepEqual(await plan(2.35, 48.85, 15), { parts: ['fr:full'], fallback: false });
assert.deepEqual(await plan(6.63, 46.52, 15), { parts: ['ch:full'], fallback: false });
assert.deepEqual(await plan(4.35, 50.85, 16), { parts: ['be:full'], fallback: false });
assert.deepEqual(await plan(21.01, 52.23, 16), { parts: ['pl:full'], fallback: false });
});
2026-11-29 13:09:26 +01:00
it('takes every tile up to zoom 12 from the imagery of the whole world', async () => {
assert.deepEqual(await plan(2.35, 48.85, 12), { parts: [], fallback: true });
assert.deepEqual(await plan(7.589, 47.5895, 12), { parts: [], fallback: true });
});
2026-11-29 12:52:41 +01:00
it('takes a tile outside every country from the fallback', async () => {
assert.deepEqual(await plan(-0.12, 51.5, 14), { parts: [], fallback: true });
// Germany, which is not in the patchwork
assert.deepEqual(await plan(9.73, 52.37, 14), { parts: [], fallback: true });
2026-11-29 13:09:26 +01:00
assert.deepEqual(await plan(-30, 40, 13), { parts: [], fallback: true });
2026-11-29 12:52:41 +01:00
});
it('puts the countries of a border tile together, over the fallback where none is', async () => {
// Menton: France and Italy, which is not in the patchwork
2026-11-29 13:09:26 +01:00
assert.deepEqual(await plan(7.5, 43.78, 13), {
2026-11-29 12:52:41 +01:00
parts: ['fr:partial'],
fallback: true,
});
// Basel: Switzerland, France and Germany
assert.deepEqual(await plan(7.589, 47.5895, 14), {
parts: ['ch:partial', 'fr:partial'],
fallback: true,
});
// Somport: France and Spain, between them the whole tile
assert.deepEqual(await plan(-0.52, 42.8, 13), {
parts: ['fr:partial', 'es:partial'],
fallback: false,
});
});
});