Drape recent imagery through the renderer's globe port

The two recent imagery slots now add their GIBS layers through the
globe port and share their six-request budget through its admission
hook. The port moves the layers between the globe and the base tileset,
which the renderer now marks as a base when it is the host.

The renderer stays the layer's Cesium side: it still loads the camera
factory, and now the globe factory too. The weather and wind entries
load the globe factory as well, and the factory check counts callers
that take findGlobe as a default.
This commit is contained in:
Sameh Khamis committed 2026-11-06 20:06:40 -08:00
1 parent 76880f6eae
commit b1733fa41a
9 files changed
+243 -250

No files matched your search

+3
View File
@@ -3832,6 +3832,8 @@
"src/data/bhoteKoshiLocator.js",
"src/render/cesium/camera.js",
"src/render/cesium/draw.js",
"src/render/cesium/imagery.js",
"src/maps/google3d.js",
"src/render/cesium/cameraControls.js",
"src/render/cesium/follow.js",
"src/data/bhoteKoshiIncidentPlaces.js",
@@ -4322,6 +4324,7 @@
"src/layers/recentImagery/model.js",
"src/layers/recentImagery/catalog.js",
"src/layers/recentImagery/rendering.js",
"src/render/cesium/globe.js",
"src/layers/recentImagery/thumbnails.js",
"src/maps/imageryHost.js",
"src/layers/streetLevel/index.js",
+10 -3
View File
@@ -34,7 +34,7 @@ import {
} from './model.js';
import { msg, t } from '../../i18n/index.js';
import { READOUT_WORDS, displayDay, displayMetres } from './display.js';
import { findCamera } from '../../render/rendererOf.js';
import { findCamera, findGlobe } from '../../render/rendererOf.js';
/**
* Quiet time after the last arrow key before the focused day previews, so a
@@ -103,13 +103,14 @@ const modeFrom = (value) =>
/**
* Create the layer.
* @param {{ catalog?: { searchHls: Function }, renderer: object, thumbnails: object, host?: Function, now?: () => Date, days?: number, setTimeoutImpl?: Function, clearTimeoutImpl?: Function }} options
* @param {{ catalog?: { searchHls: Function }, renderer: object, thumbnails: object, host?: Function, globeOf?: Function, now?: () => Date, days?: number, setTimeoutImpl?: Function, clearTimeoutImpl?: Function }} options
*/
export function createRecentImageryLayer({
catalog = { searchHls },
renderer,
thumbnails,
host = resolveImageryHost,
globeOf = findGlobe,
now = () => new Date(),
days = CATALOG_DAYS,
setTimeoutImpl = (fn, ms) => globalThis.setTimeout(fn, ms),
@@ -380,7 +381,13 @@ export function createRecentImageryLayer({
const changed =
next.collection !== _hostInfo.collection || next.kind !== _hostInfo.kind;
_hostInfo = next;
renderer.rebind(next);
// The layers drape through the viewer's globe port, on the tileset too
// when that is the host.
renderer.rebind({
...next,
globe: next.kind === 'none' ? null : globeOf(_viewer),
tileset: next.kind === 'tileset' ? _tileset : null,
});
return changed;
}
+28
View File
@@ -114,6 +114,7 @@ function fixture({
hostKind = 'globe',
controller = fakeController(),
viirs = true,
globeOf,
} = {}) {
const renderer = fakeRenderer();
const thumbnails = fakeThumbnails();
@@ -129,6 +130,7 @@ function fixture({
collection: collections[hostState.kind],
kind: hostState.kind,
}),
...(globeOf && { globeOf }),
now: () => NOW,
setTimeoutImpl: timers.setTimeoutImpl,
clearTimeoutImpl: timers.clearTimeoutImpl,
@@ -829,6 +831,32 @@ test('without a host the drapes hide and say so; the stats poll rebinds when no
assert.equal(f.owned().a.kind, 'tileset');
});
test("the renderer is bound with the viewer's globe port, and the attached tileset while that is the host", async () => {
const globe = { name: 'globe port' };
const asked = [];
const f = fixture({
globeOf: (viewer) => {
asked.push(viewer);
return globe;
},
});
await f.ready();
const last = () => f.renderer.hosts.at(-1);
assert.equal(last().globe, globe);
assert.equal(last().tileset, null, 'a globe host carries no tileset');
assert.ok(asked.every((viewer) => viewer === f.viewer));
const tileset = { name: 'photoreal' };
f.hostState.kind = 'tileset';
f.layer.attachTileset(tileset);
assert.equal(last().kind, 'tileset');
assert.equal(last().globe, globe);
assert.equal(last().tileset, tileset);
f.hostState.kind = 'none';
f.layer.getStats();
assert.equal(last().globe, null, 'no host, no port');
f.layer.destroy();
});
test('a controller subscription moves the drape to the new host on every settled switch', async () => {
const listeners = new Set();
const controller = {
+81 -115
View File
@@ -1,26 +1,26 @@
/**
* Draped-imagery renderer for the Recent Imagery layer: at most two GIBS
* imagery layers (slot `a`, left of a swipe; slot `b`, right) on whichever
* host the map stack offers. Against the basemap slot `a` splits left and
* slot `b` stays empty. Every layer is removed from the collection that owns it, so a
* host switch or a replaced image never strands one. Tile requests pass a
* small semaphore of our own; Cesium's global request limits stay untouched.
* imagery layers (slot `a`, left of a swipe; slot `b`, right) through the
* renderer's globe port, draped on whichever surface the map stack draws.
* Against the basemap slot `a` splits left and slot `b` stays empty. Tile
* requests pass a small semaphore of our own, shared by both slots, through
* each layer's admission hook; the renderer's own request limits stay
* untouched.
*/
import * as Cesium from 'cesium';
import { withTileRequestHook } from '../../render/cesium/tileRequests.js';
// The layer is Cesium-free and flies through `cameraOf`; its Cesium renderer
// brings the factory a viewer with no renderer bound gets a camera from.
// The layer flies through `cameraOf` and drapes through `findGlobe`; this
// renderer is its Cesium side, so it brings the factories a viewer with no
// renderer bound gets those ports from, and marks a tileset host as a base
// the globe port drapes on.
import '../../render/cesium/camera.js';
import { markBaseTileset } from '../../render/cesium/globe.js';
import { PRODUCTS, gibsTemplate } from './model.js';
const SLOT_IDS = ['a', 'b'];
const SPLIT_ENUM = { left: 'LEFT', right: 'RIGHT', none: 'NONE' };
const NO_HOST = Object.freeze({ collection: null, kind: 'none' });
const SPLITS = new Set(['left', 'right', 'none']);
const NO_HOST = Object.freeze({ collection: null, kind: 'none', globe: null });
/** Render reason for a deferred or settled tile request. */
/** Render reason for a settled tile request. */
export const TILE_RENDER_REASON = 'recent-imagery-tiles';
/** Delay before the one frame that retries tiles Cesium itself deferred. */
export const TILE_RETRY_DELAY_MS = 250;
function clampAlpha(value) {
const alpha = Number(value);
@@ -31,129 +31,90 @@ const boxKey = (box) =>
[box.west, box.south, box.east, box.north].map(Number).join(',');
/**
* Gate a provider's tile requests through the semaphore. Returning
* `undefined` tells Cesium to retry on a later frame, but under
* `requestRenderMode` there is no later frame unless something asks — and a
* deferral must never ask for one itself: the retried tile would defer again
* and ask again, keeping the scene rendering every frame. So a request that
* finds our semaphore full asks for nothing (the request holding the slot
* asks for one frame when it settles), and a request the provider itself
* deferred goes through the one coalesced delayed retry.
* Admit a tile request while the semaphore has room. A request that finds
* it full is deferred and asks for no frame itself: the request holding the
* slot asks for one as it settles. One the renderer itself defers frees its
* slot at once, and the renderer asks again on a later frame.
*/
function admitTileRequests(provider, admission, requestRender, retry) {
return withTileRequestHook(provider, {
requestImage: (_tile, issue) => {
if (admission.inFlight >= admission.limit) return undefined;
admission.inFlight += 1;
const release = () => {
admission.inFlight -= 1;
};
let promise;
try {
promise = issue();
} catch (error) {
release();
throw error;
}
if (!promise) {
release();
retry.schedule();
return undefined;
}
return Promise.resolve(promise).finally(() => {
release();
requestRender(TILE_RENDER_REASON);
});
},
});
function admitTileRequests(admission, requestRender) {
return (_tile, issue) => {
if (admission.inFlight >= admission.limit) return undefined;
admission.inFlight += 1;
const release = () => {
admission.inFlight -= 1;
};
let promise;
try {
promise = issue();
} catch (error) {
release();
throw error;
}
if (!promise) {
release();
return undefined;
}
return Promise.resolve(promise).finally(() => {
release();
requestRender(TILE_RENDER_REASON);
});
};
}
/**
* Create the renderer.
* @param {{ cesium?: object, maxTileRequests?: number, requestRender?: (reason: string) => void, setTimeoutImpl?: Function, clearTimeoutImpl?: Function }} [options]
* Create the renderer. The host it is bound to (`rebind`) carries the
* viewer's globe port.
* @param {{ tileTemplate?: Function, credit?: string, maxTileRequests?: number, requestRender?: (reason: string) => void }} [options]
*/
export function createRecentImageryRenderer({
cesium = Cesium,
tileTemplate = gibsTemplate,
credit = 'NASA GIBS',
maxTileRequests = 6,
requestRender = () => {},
setTimeoutImpl = (fn, ms) => globalThis.setTimeout(fn, ms),
clearTimeoutImpl = (id) => globalThis.clearTimeout(id),
} = {}) {
let host = NO_HOST;
let destroyed = false;
const admission = { limit: maxTileRequests, inFlight: 0 };
/** @type {Record<'a'|'b', null | { layer: object, collection: object, candidate: object, box: object, alpha: number, split: string }>} */
/** @type {Record<'a'|'b', null | { layer: object, globe: object, candidate: object, box: object, alpha: number, split: string }>} */
const owned = { a: null, b: null };
const admit = admitTileRequests(admission, requestRender);
// One timer for both slots: any number of upstream deferrals while it is
// armed share the same single retry frame.
let retryTimer = null;
const retry = {
schedule() {
if (retryTimer !== null) return;
retryTimer = setTimeoutImpl(() => {
retryTimer = null;
if (!destroyed) requestRender(TILE_RENDER_REASON);
}, TILE_RETRY_DELAY_MS);
},
cancel() {
if (retryTimer !== null) clearTimeoutImpl(retryTimer);
retryTimer = null;
},
};
function createProvider(candidate, box) {
const spec = PRODUCTS[candidate.product];
const provider = new cesium.UrlTemplateImageryProvider({
function specFor(candidate, box) {
const product = PRODUCTS[candidate.product];
return {
kind: 'xyz',
url: tileTemplate(candidate.product, candidate.day),
subdomains: ['a', 'b', 'c'],
minimumLevel: 0,
maximumLevel: spec.maxLevel,
tilingScheme: new cesium.WebMercatorTilingScheme(),
rectangle: cesium.Rectangle.fromDegrees(
box.west,
box.south,
box.east,
box.north,
),
credit,
hasAlphaChannel: spec.format === 'png',
});
return admitTileRequests(provider, admission, requestRender, retry);
tiling: 'webMercator',
minLevel: 0,
maxLevel: product.maxLevel,
rectangle: {
west: box.west,
south: box.south,
east: box.east,
north: box.north,
},
credit: { text: credit },
admit,
};
}
function removeOwned(slotId) {
const record = owned[slotId];
if (!record) return false;
owned[slotId] = null;
try {
record.collection.remove(record.layer, true);
} catch {
/* the collection is already gone */
}
record.layer.remove();
return true;
}
function applyLook(record) {
record.layer.alpha = record.alpha;
record.layer.splitDirection =
cesium.SplitDirection?.[SPLIT_ENUM[record.split] || 'NONE'] ?? 0;
record.layer.split = SPLITS.has(record.split) ? record.split : 'none';
}
function mount(slotId, { candidate, box, alpha, split }) {
const layer = host.collection.addImageryProvider(
createProvider(candidate, box),
);
owned[slotId] = {
layer,
collection: host.collection,
candidate,
box,
alpha,
split,
};
const layer = host.globe.imagery.add(specFor(candidate, box));
owned[slotId] = { layer, globe: host.globe, candidate, box, alpha, split };
applyLook(owned[slotId]);
}
@@ -174,7 +135,7 @@ export function createRecentImageryRenderer({
{ alpha = 1, splitDirection = 'none' } = {},
) {
if (destroyed || !candidate?.key || !box) return false;
if (!host.collection) {
if (!host.globe) {
removeOwned(slotId);
return false;
}
@@ -182,7 +143,7 @@ export function createRecentImageryRenderer({
const look = { alpha: clampAlpha(alpha), split: splitDirection };
if (
current &&
current.collection === host.collection &&
current.globe === host.globe &&
current.candidate.key === candidate.key &&
boxKey(current.box) === boxKey(box)
) {
@@ -218,19 +179,25 @@ export function createRecentImageryRenderer({
},
/**
* Move every owned layer to a new host. Layers are rebuilt there, never
* re-parented, so the old collection is left as it was found.
* @param {{ collection: object | null, kind: string }} nextHost
* Follow the map stack's host. The globe port moves the owned layers
* between the globe and the 3D tiles itself; without a host they go,
* and a new globe port gets them rebuilt.
* @param {{ collection: object | null, kind: string, globe?: object | null, tileset?: object | null }} nextHost
*/
rebind(nextHost) {
host = nextHost || NO_HOST;
let changed = false;
const previous = host;
host =
nextHost && nextHost.kind !== 'none' && nextHost.globe
? nextHost
: NO_HOST;
if (host.kind === 'tileset') markBaseTileset(host.tileset);
let changed = host.kind !== previous.kind && Boolean(owned.a || owned.b);
for (const slotId of SLOT_IDS) {
const record = owned[slotId];
if (!record || record.collection === host.collection) continue;
if (!record || record.globe === host.globe) continue;
removeOwned(slotId);
changed = true;
if (host.collection && !destroyed) mount(slotId, record);
if (host.globe && !destroyed) mount(slotId, record);
}
if (changed) requestRender('recent-imagery-rebind');
},
@@ -261,7 +228,6 @@ export function createRecentImageryRenderer({
destroy() {
if (destroyed) return;
destroyed = true;
retry.cancel();
let changed = false;
for (const slotId of SLOT_IDS) changed = removeOwned(slotId) || changed;
host = NO_HOST;
+105 -129
View File
@@ -2,86 +2,51 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import {
TILE_RENDER_REASON,
TILE_RETRY_DELAY_MS,
createRecentImageryRenderer,
} from './rendering.js';
import { BOX, manualTimers } from './testDoubles.mjs';
/** A provider whose tile requests stay pending until the test settles them. */
class UrlTemplateImageryProvider {
constructor(options) {
this.options = options;
this.calls = [];
this.pending = [];
}
requestImage(x, y, level) {
this.calls.push([x, y, level]);
return new Promise((resolve) => this.pending.push(resolve));
}
}
function fakeCesium(requestImage) {
class Provider extends UrlTemplateImageryProvider {}
if (requestImage) Provider.prototype.requestImage = requestImage;
return {
UrlTemplateImageryProvider: Provider,
WebMercatorTilingScheme: class {},
Rectangle: {
fromDegrees: (west, south, east, north) => ({ west, south, east, north }),
},
SplitDirection: { LEFT: -1, NONE: 0, RIGHT: 1 },
};
}
function fakeCollection() {
const layers = [];
return {
layers,
addImageryProvider(provider) {
const layer = { provider, alpha: 1, splitDirection: 0 };
layers.push(layer);
return layer;
},
remove(layer, destroy) {
layers.splice(layers.indexOf(layer), 1);
layer.destroyed = destroy;
},
};
}
import { BOX } from './testDoubles.mjs';
import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs';
const S30 = { key: 'S30:2026-09-18', product: 'S30', day: '2026-09-18' };
const L30 = { key: 'L30:2026-09-16', product: 'L30', day: '2026-09-16' };
const VIIRS = { key: 'VIIRS:2026-09-20', product: 'VIIRS', day: '2026-09-20' };
function fixture({ requestImage, maxTileRequests, ...options } = {}) {
const renders = [];
const timers = manualTimers();
const renderer = createRecentImageryRenderer({
...options,
cesium: fakeCesium(requestImage),
maxTileRequests,
requestRender: (reason) => renders.push(reason),
setTimeoutImpl: timers.setTimeoutImpl,
clearTimeoutImpl: timers.clearTimeoutImpl,
});
const globe = fakeCollection();
renderer.rebind({ collection: globe, kind: 'globe' });
const tileFrames = () =>
renders.filter((reason) => reason === TILE_RENDER_REASON).length;
return { renderer, globe, renders, timers, tileFrames };
/** A tile fetch that stays pending until the test settles it. */
function pendingFetches() {
const pending = [];
const fetch = () => new Promise((resolve) => pending.push(resolve));
return { pending, fetch };
}
test('a slot drapes one GIBS provider bounded to the box; the same day only restyles it', () => {
function fixture({ maxTileRequests, ...options } = {}) {
const renders = [];
const renderer = createRecentImageryRenderer({
...options,
maxTileRequests,
requestRender: (reason) => renders.push(reason),
});
const globe = fakeGlobePort();
renderer.rebind({ collection: {}, kind: 'globe', globe });
const tileFrames = () =>
renders.filter((reason) => reason === TILE_RENDER_REASON).length;
return { renderer, globe, renders, tileFrames };
}
const tile = (x, level = 1) => ({ x, y: 0, level });
test('a slot drapes one GIBS layer bounded to the box; the same day only restyles it', () => {
const { renderer, globe, renders } = fixture();
assert.equal(renderer.showSlot('a', S30, BOX, { alpha: 0.8 }), true);
const [layer] = globe.layers;
assert.match(
layer.provider.options.url,
layer.spec.url,
/^https:\/\/gibs-\{s\}\.earthdata\.nasa\.gov\/.*HLS_S30.*\/2026-09-18\/GoogleMapsCompatible_Level12\/\{z\}\/\{y\}\/\{x\}\.png$/,
);
assert.deepEqual(layer.provider.options.subdomains, ['a', 'b', 'c']);
assert.equal(layer.provider.options.credit, 'NASA GIBS');
assert.deepEqual(layer.provider.options.rectangle, BOX);
assert.equal(layer.spec.kind, 'xyz');
assert.equal(layer.spec.tiling, 'webMercator');
assert.deepEqual(layer.spec.subdomains, ['a', 'b', 'c']);
assert.deepEqual(layer.spec.credit, { text: 'NASA GIBS' });
assert.deepEqual(layer.spec.rectangle, BOX);
assert.equal(layer.alpha, 0.8);
assert.deepEqual(renders, ['recent-imagery-show']);
assert.deepEqual(renderer.getOwned().a, {
@@ -92,16 +57,15 @@ test('a slot drapes one GIBS provider bounded to the box; the same day only rest
});
renderer.showSlot('a', S30, BOX, { alpha: 0.5, splitDirection: 'left' });
assert.deepEqual(globe.layers, [layer], 'the layer is reused');
assert.equal(layer.splitDirection, -1);
// A different day replaces the layer in its own collection.
assert.equal(layer.split, 'left');
// A different day replaces the layer.
renderer.showSlot('a', L30, BOX);
assert.equal(layer.destroyed, true);
assert.equal(layer.removed, true);
assert.equal(globe.layers.length, 1);
// VIIRS is a level-9 JPEG overview with no alpha channel.
// VIIRS is a level-9 overview.
renderer.showSlot('b', VIIRS, BOX, { splitDirection: 'right' });
assert.equal(globe.layers[1].provider.options.maximumLevel, 9);
assert.equal(globe.layers[1].provider.options.hasAlphaChannel, false);
assert.equal(globe.layers[1].splitDirection, 1);
assert.equal(globe.layers[1].spec.maxLevel, 9);
assert.equal(globe.layers[1].split, 'right');
renderer.setAlpha('b', 7);
assert.equal(globe.layers[1].alpha, 1, 'alpha clamps to 0–1');
});
@@ -120,80 +84,92 @@ test('rapid replacement never owns more than two layers', () => {
assert.equal(globe.layers.length, 0);
});
test('rebind rebuilds the owned layers on the new host and leaves the old one empty', () => {
const { renderer, globe } = fixture();
test('the renderer leaves the surface to the globe port; no host removes the layers; a new port rebuilds them', () => {
const { renderer, globe, renders } = fixture();
renderer.showSlot('a', S30, BOX, { alpha: 0.6, splitDirection: 'left' });
renderer.showSlot('b', L30, BOX, { splitDirection: 'right' });
const tileset = fakeCollection();
renderer.rebind({ collection: tileset, kind: 'tileset' });
assert.equal(globe.layers.length, 0);
assert.deepEqual(
tileset.layers.map((layer) => [layer.alpha, layer.splitDirection]),
[
[0.6, -1],
[1, 1],
],
const layers = [...globe.layers];
renders.length = 0;
renderer.rebind({ collection: {}, kind: 'tileset', globe, tileset: {} });
assert.deepEqual(globe.layers, layers, 'the port drapes them on the tiles');
assert.ok(
layers.every((layer) => layer.drapeOn === 'all'),
'the renderer never narrows where they drape',
);
assert.equal(renderer.getOwned().a.kind, 'tileset');
renderer.rebind({ collection: null, kind: 'none' });
assert.equal(tileset.layers.length, 0);
assert.deepEqual(renders, ['recent-imagery-rebind'], 'the move gets a frame');
renderer.rebind({ collection: {}, kind: 'globe', globe: null });
assert.equal(
globe.layers.length,
0,
'a host with no globe port drapes nothing',
);
assert.equal(renderer.showSlot('a', S30, BOX), false);
renderer.rebind({ collection: globe, kind: 'globe' });
renderer.showSlot('a', S30, BOX);
renderer.destroy();
renderer.rebind({ collection: {}, kind: 'globe', globe });
renderer.rebind({ collection: null, kind: 'none', globe });
assert.equal(globe.layers.length, 0);
assert.equal(renderer.showSlot('a', S30, BOX), false);
const other = fakeGlobePort();
renderer.rebind({ collection: {}, kind: 'globe', globe });
renderer.showSlot('a', S30, BOX, { alpha: 0.6, splitDirection: 'left' });
renderer.showSlot('b', L30, BOX, { splitDirection: 'right' });
renderer.rebind({ collection: {}, kind: 'globe', globe: other });
assert.equal(globe.layers.length, 0);
assert.deepEqual(
other.layers.map((layer) => [layer.alpha, layer.split]),
[
[0.6, 'left'],
[1, 'right'],
],
);
renderer.destroy();
assert.equal(other.layers.length, 0);
assert.equal(renderer.showSlot('a', S30, BOX), false, 'destroyed');
});
test('above the tile limit a request defers silently; its settlement asks for exactly one frame', async () => {
const { renderer, globe, timers, tileFrames } = fixture({
maxTileRequests: 1,
});
const { renderer, globe, tileFrames } = fixture({ maxTileRequests: 1 });
renderer.showSlot('a', S30, BOX);
const { provider } = globe.layers[0];
const first = provider.requestImage(0, 0, 1);
const [layer] = globe.layers;
const { pending, fetch } = pendingFetches();
const first = layer.request(tile(0), fetch);
assert.ok(first instanceof Promise);
for (let i = 1; i <= 120; i += 1)
assert.equal(provider.requestImage(i, 0, 1), undefined);
assert.equal(provider.calls.length, 1, 'deferred requests never go out');
assert.equal(layer.request(tile(i), fetch), undefined);
assert.equal(pending.length, 1, 'deferred requests never go out');
assert.equal(tileFrames(), 0, 'a deferral asks for no frame');
assert.equal(timers.armed(), 0);
provider.pending[0]('tile');
pending[0]('tile');
await first;
assert.equal(tileFrames(), 1, 'the settlement asks for the retry frame');
assert.ok(provider.requestImage(200, 0, 1) instanceof Promise);
assert.ok(layer.request(tile(200), fetch) instanceof Promise);
});
test('upstream deferrals from both slots share one delayed retry frame; destroy disarms it', () => {
let throwNext = false;
const { renderer, globe, timers, tileFrames } = fixture({
maxTileRequests: 1,
requestImage() {
if (throwNext) throw new Error('boom');
return undefined;
},
});
test('both slots share the budget; a renderer deferral or throw frees its slot', async () => {
const { renderer, globe, tileFrames } = fixture({ maxTileRequests: 1 });
renderer.showSlot('a', S30, BOX);
renderer.showSlot('b', L30, BOX);
for (const { provider } of globe.layers)
for (let i = 0; i < 40; i += 1)
assert.equal(provider.requestImage(i, 0, 0), undefined);
// Every deferral released its slot (the limit is one), and none asked
// for a frame of its own: one timer holds the single retry.
assert.equal(tileFrames(), 0);
assert.equal(timers.armed(), 1);
assert.equal([...timers.pending.values()][0].ms, TILE_RETRY_DELAY_MS);
timers.flush();
const [a, b] = globe.layers;
const { pending, fetch } = pendingFetches();
const held = a.request(tile(0), fetch);
assert.equal(b.request(tile(0), fetch), undefined, 'the other slot waits');
pending[0]('tile');
await held;
// The renderer itself defers: the slot is free at once.
for (let i = 0; i < 40; i += 1)
assert.equal(
b.request(tile(i), () => undefined),
undefined,
);
assert.throws(
() =>
a.request(tile(0), () => {
throw new Error('boom');
}),
/boom/,
);
assert.ok(b.request(tile(1), fetch) instanceof Promise, 'still room');
assert.equal(tileFrames(), 1);
// A throwing provider releases its slot too.
throwNext = true;
assert.throws(() => globe.layers[0].provider.requestImage(0, 0, 0), /boom/);
throwNext = false;
globe.layers[0].provider.requestImage(0, 0, 0);
assert.equal(timers.armed(), 1, 'the next deferral arms a fresh timer');
renderer.destroy();
assert.equal(timers.armed(), 0, 'destroy disarms the retry');
assert.equal(tileFrames(), 1);
});
test('against the basemap slot a splits left with no second layer, and leaving the swipe only restyles it', () => {
@@ -201,12 +177,12 @@ test('against the basemap slot a splits left with no second layer, and leaving t
renderer.showSlot('a', S30, BOX, { splitDirection: 'left' });
renderer.hideSlot('b');
assert.equal(globe.layers.length, 1, 'the basemap is the right side');
assert.equal(globe.layers[0].splitDirection, -1);
assert.equal(globe.layers[0].split, 'left');
assert.equal(renderer.getOwned().b, null);
const [layer] = globe.layers;
renderer.showSlot('a', S30, BOX, { splitDirection: 'none' });
assert.deepEqual(globe.layers, [layer], 'no rebuild for a new look');
assert.equal(layer.splitDirection, 0);
assert.equal(layer.split, 'none');
assert.deepEqual(renders, ['recent-imagery-show', 'recent-imagery-look']);
});
@@ -219,11 +195,11 @@ test('replacement imagery uses source-owned tile URLs and credit and tears down
assert.equal(renderer.showSlot('a', S30, BOX), true);
const layer = globe.layers[0];
assert.equal(
layer.provider.options.url,
layer.spec.url,
'https://tiles.example/S30/2026-09-18/{z}/{x}/{y}',
);
assert.equal(layer.provider.options.credit, 'Example imagery');
assert.deepEqual(layer.spec.credit, { text: 'Example imagery' });
renderer.destroy();
assert.equal(globe.layers.length, 0);
assert.equal(layer.destroyed, true);
assert.equal(layer.removed, true);
});
+4
View File
@@ -214,10 +214,14 @@ export function fakeRenderer() {
const owned = { a: null, b: null };
let host = { kind: 'none' };
let peak = 0;
/** Every host the renderer was bound to, as given. */
const hosts = [];
return {
calls,
hosts,
rebind(next) {
calls.push(['rebind', next.kind]);
hosts.push(next);
host = next;
for (const slot of ['a', 'b'])
if (owned[slot]) owned[slot] = { ...owned[slot], kind: next.kind };
+3
View File
@@ -12,6 +12,9 @@ import {
import { formatUtcDayMonth, t, msg } from '../../i18n/index.js';
import { formatScaleLabel } from '../../ui/unitLabels.js';
import { cameraOf } from '../../render/cesium/camera.js';
// The renderer drapes through `findGlobe`; a viewer with no renderer bound
// gets its globe port from the factory this module provides.
import '../../render/cesium/globe.js';
/**
* A stored (English) failure in the language. HTTP failures from source.js
+3
View File
@@ -1,5 +1,8 @@
import * as Cesium from 'cesium';
import { createWindRendering } from './rendering.js';
// The renderer drapes through `findGlobe`; a viewer with no renderer bound
// gets its globe port from the factory this module provides.
import '../../render/cesium/globe.js';
import { WIND_FIELDS } from './fields.js';
import {
formatWindReading,
+6 -3
View File
@@ -196,7 +196,9 @@ function checkLookupFactory(lookup, factory, { reached = true } = {}) {
const calls = (file) =>
!file.startsWith('src/render/') &&
/\.(m?js|vue)$/.test(file) &&
readFileSync(path.join(root, file), 'utf8').includes(`${lookup}(`);
new RegExp(`\\b${lookup}\\b`).test(
readFileSync(path.join(root, file), 'utf8'),
);
for (const [key, declaration] of Object.entries(pkg.exports)) {
const target = browserTarget(declaration);
if (typeof target !== 'string' || !target.startsWith('./src/')) continue;
@@ -221,8 +223,9 @@ test('every public entry that reaches a findEffects caller loads the unbound eff
});
test('every public entry that reaches a findGlobe caller loads the unbound globe factory', () => {
// Only the application reaches one today, through no public entry.
checkLookupFactory('findGlobe', GLOBE_FACTORY, { reached: false });
// A caller may take `findGlobe` as a default rather than call it, so any
// use of the name counts.
checkLookupFactory('findGlobe', GLOBE_FACTORY);
});
test('the unbound export brings every unbound factory', () => {