// 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 }); }); 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 }); assert.deepEqual(await plan(-30, 40, 10), { parts: [], fallback: true }); }); 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 assert.deepEqual(await plan(7.5, 43.8, 12), { 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, }); }); it('does not take a tile covering several countries from their agencies', async () => { assert.deepEqual(await plan(2.35, 48.85, 6), { parts: [], fallback: true }); }); });