mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-11-30 09:34:29 +00:00
use border tiles to cut patchwork precisely
This commit is contained in:
1 parent
657cf8786c
commit
4d4804203f
10 files changed
+282
-273
No files matched your search
@@ -1,7 +1,25 @@
|
||||
// Which imagery each tile of the open satellite basemap is made of.
|
||||
// Which imagery each tile of the open satellite basemap is made of, from saved tiles of the
|
||||
// tileset of the countries.
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { describe, it } from 'node:test';
|
||||
import { planTile } from './open-satellite';
|
||||
import { planTile, type CountryTiles } from './open-satellite';
|
||||
|
||||
const fixtures = new URL('../../../test/fixtures/satellite-countries/', import.meta.url);
|
||||
|
||||
/** The saved tiles, none where there is no file, and the ones that were asked for. */
|
||||
function savedTiles() {
|
||||
const asked: string[] = [];
|
||||
const tiles: CountryTiles = async (z, x, y) => {
|
||||
asked.push(`${z}/${x}/${y}`);
|
||||
try {
|
||||
return new Uint8Array(readFileSync(new URL(`${z}-${x}-${y}.mvt`, fixtures))).buffer;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return { asked, tiles };
|
||||
}
|
||||
|
||||
function tile(lon: number, lat: number, z: number): [number, number, number] {
|
||||
const n = 2 ** z;
|
||||
@@ -13,46 +31,68 @@ function tile(lon: number, lat: number, z: number): [number, number, number] {
|
||||
];
|
||||
}
|
||||
|
||||
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 };
|
||||
async function plan([z, x, y]: [number, number, number], tiles: CountryTiles) {
|
||||
const { parts, fallback } = await planTile(z, x, y, tiles);
|
||||
return { parts: parts.map((p) => `${p.source.id}:${p.relation}`).sort(), 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 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 });
|
||||
const { asked, tiles } = savedTiles();
|
||||
assert.deepEqual(await plan(tile(2.35, 48.85, 12), tiles), { parts: [], fallback: true });
|
||||
assert.deepEqual(asked, []);
|
||||
});
|
||||
|
||||
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, 13), { parts: [], fallback: true });
|
||||
it('takes a tile far from every country from the fallback, without asking for countries', async () => {
|
||||
const { asked, tiles } = savedTiles();
|
||||
// London, and the Atlantic
|
||||
assert.deepEqual(await plan(tile(-0.12, 51.5, 14), tiles), { parts: [], fallback: true });
|
||||
assert.deepEqual(await plan(tile(-30, 40, 13), tiles), { parts: [], fallback: true });
|
||||
assert.deepEqual(asked, []);
|
||||
});
|
||||
|
||||
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.78, 13), {
|
||||
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'],
|
||||
it('takes a tile inside a country from its agency alone', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
assert.deepEqual(await plan(tile(2.35, 48.85, 15), tiles), {
|
||||
parts: ['FR:full'],
|
||||
fallback: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('puts the countries of a border tile together, over the fallback where none is', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Basel: France, Switzerland and Germany, which is not in the patchwork
|
||||
assert.deepEqual(await plan([13, 4268, 2861], tiles), {
|
||||
parts: ['CH:partial', 'FR:partial'],
|
||||
fallback: true,
|
||||
});
|
||||
// only Germany
|
||||
assert.deepEqual(await plan([13, 4269, 2860], tiles), { parts: [], fallback: true });
|
||||
});
|
||||
|
||||
it('needs no fallback where the countries cover the tile between them', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Wattrelos: France and Belgium
|
||||
assert.deepEqual(await plan([13, 4166, 2750], tiles), {
|
||||
parts: ['BE:partial', 'FR:partial'],
|
||||
fallback: false,
|
||||
});
|
||||
// Baarle, with its enclaves of Belgium and the Netherlands
|
||||
assert.deepEqual(await plan([13, 4208, 2726], tiles), {
|
||||
parts: ['BE:partial', 'NL:partial'],
|
||||
fallback: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('asks for a tile of the countries once for all the tiles of imagery inside it', async () => {
|
||||
const { asked, tiles } = savedTiles();
|
||||
// around Lausanne, which no other test asks for
|
||||
const [, x, y] = tile(6.63, 46.52, 12);
|
||||
for (let dx = 0; dx < 4; dx++) {
|
||||
for (let dy = 0; dy < 4; dy++) {
|
||||
await planTile(14, x * 4 + dx, y * 4 + dy, tiles);
|
||||
}
|
||||
}
|
||||
assert.deepEqual(asked, [`12/${x}/${y}`]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user