mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
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.
This commit is contained in:
1 parent
10a788db78
commit
db80d82b8d
182 files changed
+15805
-44
No files matched your search
@@ -0,0 +1,135 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createLibraryTileLayer } from './layers.js';
|
||||
import { LIBRARY_ENTRIES, libraryEntry } from './catalog.js';
|
||||
import { libraryTileUrl } from './manifest.js';
|
||||
import { createLibrarySource } from './source.js';
|
||||
|
||||
/** A tiles entry without its border outline, so no network is touched. */
|
||||
function entryWithoutOutline(id) {
|
||||
const entry = libraryEntry(id);
|
||||
const { outline: _outline, ...display } = entry.display;
|
||||
return { ...entry, display };
|
||||
}
|
||||
|
||||
function globeViewer() {
|
||||
return {
|
||||
scene: { globe: { show: true } },
|
||||
imageryLayers: new Cesium.ImageryLayerCollection(),
|
||||
dataSources: { add: async () => {}, remove: () => {} },
|
||||
};
|
||||
}
|
||||
|
||||
const source = { tileTemplate: (entry) => entry.source.url };
|
||||
const tileProvider = (url) =>
|
||||
new Cesium.UrlTemplateImageryProvider({
|
||||
url,
|
||||
tilingScheme: new Cesium.WebMercatorTilingScheme(),
|
||||
});
|
||||
|
||||
test('aerial imagery drapes above every other imagery layer', async () => {
|
||||
const viewer = globeViewer();
|
||||
const collection = viewer.imageryLayers;
|
||||
const base = collection.addImageryProvider(
|
||||
tileProvider('https://base.example.org/{z}/{x}/{y}.png'),
|
||||
);
|
||||
const photos = createLibraryTileLayer(
|
||||
entryWithoutOutline('pdok-aerial-netherlands'),
|
||||
{ source, cesium: Cesium },
|
||||
);
|
||||
await photos.init(viewer);
|
||||
await photos.enable(viewer);
|
||||
const top = () => collection.get(collection.length - 1);
|
||||
assert.equal(collection.length, 2);
|
||||
assert.notEqual(top(), base);
|
||||
const pdok = top();
|
||||
|
||||
// A drape added later (weather, another library basemap) goes under it.
|
||||
const weather = collection.addImageryProvider(
|
||||
tileProvider('https://weather.example.org/{z}/{x}/{y}.png'),
|
||||
);
|
||||
assert.equal(top(), pdok);
|
||||
assert.equal(collection.indexOf(weather), 1);
|
||||
|
||||
// PDOK's white "no imagery here" fill is drawn transparent, and its tiles
|
||||
// are requested only inside the Netherlands bbox.
|
||||
assert.ok(pdok.colorToAlpha.equals(Cesium.Color.WHITE));
|
||||
assert.ok(
|
||||
pdok.colorToAlphaThreshold > 0 && pdok.colorToAlphaThreshold < 0.05,
|
||||
);
|
||||
const west = Cesium.Math.toDegrees(pdok.imageryProvider.rectangle.west);
|
||||
assert.ok(Math.abs(west - 3.2) < 1e-9);
|
||||
|
||||
// Off: the drape and its listener are gone, so later layers stay put.
|
||||
await photos.disable();
|
||||
assert.equal(collection.contains(pdok), false);
|
||||
const later = collection.addImageryProvider(
|
||||
tileProvider('https://later.example.org/{z}/{x}/{y}.png'),
|
||||
);
|
||||
assert.equal(top(), later);
|
||||
});
|
||||
|
||||
test('a non-aerial tile layer keeps its place and its own colours', async () => {
|
||||
const viewer = globeViewer();
|
||||
const collection = viewer.imageryLayers;
|
||||
const topo = createLibraryTileLayer(entryWithoutOutline('usgs-topo'), {
|
||||
source,
|
||||
cesium: Cesium,
|
||||
});
|
||||
await topo.init(viewer);
|
||||
await topo.enable(viewer);
|
||||
const drape = collection.get(0);
|
||||
collection.addImageryProvider(
|
||||
tileProvider('https://weather.example.org/{z}/{x}/{y}.png'),
|
||||
);
|
||||
assert.equal(collection.indexOf(drape), 0);
|
||||
assert.equal(drape.colorToAlpha, undefined);
|
||||
await topo.destroy();
|
||||
});
|
||||
|
||||
test('every shipped aerial photo entry is clipped to its coverage', () => {
|
||||
const aerial = LIBRARY_ENTRIES.filter((entry) => entry.display.aerial);
|
||||
assert.ok(aerial.length >= 60, 'the Open Imagery Register entries ship');
|
||||
for (const entry of aerial) {
|
||||
// Kept on top, an unclipped drape would cover the whole globe with the
|
||||
// provider's out-of-area fill.
|
||||
assert.equal(entry.source.bounded, true, entry.id);
|
||||
assert.ok(entry.imagery?.resolution, `${entry.id} names its resolution`);
|
||||
}
|
||||
});
|
||||
|
||||
test('bbox and TMS templates become the URLs Cesium and the proxy request', () => {
|
||||
const source = createLibrarySource({
|
||||
entries: [],
|
||||
base: '/api/library',
|
||||
storage: null,
|
||||
});
|
||||
const wms = {
|
||||
id: 'example-wms',
|
||||
source: {
|
||||
fetch: 'browser-direct',
|
||||
url: 'https://w.example.org/wms?bbox={bbox-epsg-3857}&width=256',
|
||||
},
|
||||
};
|
||||
assert.equal(
|
||||
source.tileTemplate(wms),
|
||||
'https://w.example.org/wms?bbox={westProjected},{southProjected},{eastProjected},{northProjected}&width=256',
|
||||
);
|
||||
assert.equal(
|
||||
source.tileTemplate({
|
||||
...wms,
|
||||
source: { ...wms.source, fetch: 'proxied' },
|
||||
}),
|
||||
'/api/library/tile/example-wms/{z}/{x}/{y}',
|
||||
);
|
||||
// The proxy fills the same tile's bounds in EPSG:3857 metres.
|
||||
assert.equal(
|
||||
libraryTileUrl(wms.source.url, 1, 1, 0),
|
||||
'https://w.example.org/wms?bbox=0.000,0.000,20037508.343,20037508.343&width=256',
|
||||
);
|
||||
assert.equal(
|
||||
libraryTileUrl('https://t.example.org/{z}/{x}/{reverseY}.png', 3, 2, 1),
|
||||
'https://t.example.org/3/2/6.png',
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user