Files
gods-eye-view/src/library/outlines.test.mjs
T
Said Turksever db80d82b8d Add the Data Library: live regional datasets, tiles and packs
DATA LAYERS keeps its curated core layers; regional and niche sources
live in the Data Library, opened from Browse data library at the foot
of the panel. Each entry is a JSON manifest in src/library/entries/
pointing at a live upstream (query API, provider-hosted file or tile
endpoint), so nothing is bundled and a self-hosted instance hosts no
data. Sources without CORS go through one allowlisted /api/library
route. Kinds: dataset (GeoJSON, CSV, JSON records, ArcGIS, partitioned
GeoParquet), tiles (XYZ, WMS/ArcGIS bbox export, terrarium relief) and
pack. Selections persist and travel in share links as lib=, separate
from the core layer tokens. Library rows get Zoom and Remove icon
chips that work while the layer is off, rendered through RailChips.
Strings are translated in every locale.
2026-11-12 12:26:45 +00:00

67 lines
2.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { outlineRings } from './outlines.js';
import { libraryEntry } from './catalog.js';
const square = (lon, lat, size = 1) => [
[lon, lat],
[lon + size, lat],
[lon + size, lat + size],
[lon, lat + size],
[lon, lat],
];
const country = (code, polygons, iso = code) => ({
properties: { ISO_A2_EH: code, ISO_A2: iso },
geometry: {
type: 'MultiPolygon',
coordinates: polygons.map((ring) => [ring]),
},
});
const features = [
// Netherlands: the European part and a Caribbean island.
country('NL', [square(4, 52), square(-68.3, 12.1, 0.3)]),
// Natural Earth writes France's ISO_A2 as -99; ISO_A2_EH carries FR.
country('FR', [square(2, 46), square(-53, 4)], '-99'),
country('BE', [square(4, 50.5)]),
];
test('coverage outlines keep only the parts inside the declared area', () => {
const rings = outlineRings(features, libraryEntry('pdok-aerial-netherlands'));
assert.equal(rings.length, 1);
assert.equal(rings[0][0][0], 4);
});
test('country outlines keep every part and read the ISO_A2_EH code', () => {
const everyPart = {
coverage: { countries: ['FR'] },
display: { outline: 'countries' },
};
assert.equal(
outlineRings(features, everyPart).length,
2,
'metropolitan France and French Guiana',
);
// IGN is clipped to metropolitan France, so its outline is too.
const ign = outlineRings(features, libraryEntry('ign-orthophotos-france'));
assert.equal(ign.length, 1);
assert.equal(ign[0][0][0], 2);
assert.deepEqual(
outlineRings(features, libraryEntry('nasa-black-marble')),
[],
);
});
test('a bbox outline is the coverage rectangle, with no border file needed', () => {
const rings = outlineRings([], libraryEntry('lawrence-ks'));
const [west, south, east, north] = libraryEntry('lawrence-ks').coverage.bbox;
assert.deepEqual(rings, [
[
[west, south],
[east, south],
[east, north],
[west, north],
[west, south],
],
]);
});