Draw the weather and wind imagery through the renderer's globe port

Radar, satellite clouds and lightning frames are imagery layers of the
globe port instead of Cesium providers in the viewer's collection. A frame
stages as a transparent layer on the globe's surface and counts its tiles
through the layer's admit hook; the global infrared mosaic draws each tile
of the geographic grid from the decoded canvas, the regional infrared
transfer runs as the layer's tile transform on the upright tile, and
throttled tiles are fetched again by the renderer. Readiness reads the
port's imagery settling, the camera port gives the view and its move end,
and the frame's credit, which a refreshed manifest can still change in
place, is owed through the credits port while the layer is shown.
Without a host the shown frame is hidden rather than detached.

Wind's colour field is a port layer too, so the draw order is a zOrder per
product (wind, infrared, radar, lightning), above the port's other
imagery, and the raise-to-top helper goes. The Cesium port keeps a tile
transform's bitmaps in straight alpha and closes the copies it spends,
and a provider that fails to build is told as an error of its root tile.

The weather rendering and raster tile modules no longer reach Cesium and
leave the allow-list; the 3D Tiles shell still does.
This commit is contained in:
Sameh Khamis committed 2026-11-06 20:06:33 -08:00
1 parent 9e1f9a1c3d
commit 76880f6eae
15 files changed
+735 -721

No files matched your search

+41 -76
View File
@@ -1,11 +1,11 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import { GeographicTilingScheme } from 'cesium';
import { createWeatherLayer } from './index.js';
import { createWeatherRendering } from './rendering.js';
import { weatherDisplay, insideExtent, escapeCreditText } from './display.js';
import { createShellCesium, createShellScene } from './shellFixture.mjs';
import { weatherDisplay, insideExtent } from './display.js';
import { createShellScene } from './shellFixture.mjs';
import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs';
import { formatScaleLabel } from '../../ui/unitLabels.js';
import { bindFakeCesiumCamera } from '../../testSupport/fakeCameraPort.mjs';
@@ -581,10 +581,6 @@ test('display validation bounds text, legend shape, colours and extents', () =>
assert.equal(insideExtent(wrap.extent, -100, 10), true);
assert.equal(insideExtent(wrap.extent, 50, 10), false);
assert.equal(insideExtent(wrap.extent, -100, 81), false);
assert.equal(
escapeCreditText(`<b>"A" & 'B'</b>`),
'&lt;b&gt;&quot;A&quot; &amp; &#39;B&#39;&lt;/b&gt;',
);
});
function mockCanvas() {
@@ -598,35 +594,11 @@ function mockCanvas() {
return canvas;
}
/** A globe viewer whose imagery collection records providers. */
/** A globe viewer whose globe port records the layers added. */
function globeViewer() {
const providers = [];
const layers = [];
const collection = {
addImageryProvider(provider) {
providers.push(provider);
const layer = { imageryProvider: provider, alpha: 1, show: true };
layers.push(layer);
return layer;
},
contains: (layer) => layers.includes(layer),
remove(layer) {
layers.splice(layers.indexOf(layer), 1);
return true;
},
get length() {
return layers.length;
},
get: (index) => layers[index],
indexOf: (layer) => layers.indexOf(layer),
lower() {},
raise() {},
raiseToTop() {},
isDestroyed: () => false,
};
const listeners = new Set();
const viewer = {
imageryLayers: collection,
imageryLayers: {},
camera: {
moveEnd: { addEventListener: () => () => {} },
flyTo() {},
@@ -644,26 +616,20 @@ function globeViewer() {
},
};
bindFakeCesiumCamera(viewer);
class Provider {
constructor(options) {
this.options = options;
this.tilingScheme = new GeographicTilingScheme();
this.errorEvent = new Cesium.Event();
}
requestImage() {
return undefined;
}
}
const cesium = {
...createShellCesium(),
UrlTemplateImageryProvider: Provider,
GeographicTilingScheme,
Event: Cesium.Event,
Credit: Cesium.Credit,
Rectangle: Cesium.Rectangle,
const globe = fakeGlobePort();
const owed = [];
const credits = {
addStatic(credit) {
const entry = { ...credit };
owed.push(entry);
return () => owed.splice(owed.indexOf(entry), 1);
},
};
const options = {
cesium,
globeOf: () => globe,
creditsOf: () => credits,
cameraOf: () => null,
toBitmap: (canvas) => canvas,
fetchImpl: async () => ({
ok: true,
headers: new Headers(),
@@ -677,7 +643,7 @@ function globeViewer() {
for (let i = 0; i < 2; i++) for (const fn of [...listeners]) fn();
await flush();
};
return { viewer, providers, options, settle };
return { viewer, providers: globe.added, owed, options, settle };
}
/** Show a frame of `manifest` and return the rendering and its globe. */
@@ -693,7 +659,8 @@ async function shownFrame(manifest) {
return { ...globe, rendering };
}
const creditOf = (providers) => providers.at(-1).credit.html;
/** The credit the shown frame owes. */
const creditOf = (h) => h.owed.at(-1)?.text;
test('the imagery credit uses the source credit as plain text, else the built-in one', async () => {
for (const product of ['radar', 'lightning', 'clouds-regional', 'clouds']) {
@@ -703,7 +670,7 @@ test('the imagery credit uses the source credit as plain text, else the built-in
product,
...(display ? { display } : {}),
});
assert.equal(creditOf(h.providers), BUILT_IN[product].credit, product);
assert.equal(creditOf(h), BUILT_IN[product].credit, product);
h.rendering.clear();
}
const h = await shownFrame({
@@ -712,8 +679,9 @@ test('the imagery credit uses the source credit as plain text, else the built-in
display: { credit: 'Example <network> & partners' },
});
assert.equal(
creditOf(h.providers),
'Example &lt;network&gt; &amp; partners',
creditOf(h),
'Example <network> & partners',
'plain text: the credits port escapes it',
);
h.rendering.clear();
}
@@ -726,7 +694,7 @@ test('a refreshed manifest updates the credit of the frame already shown', async
product,
display: { credit: 'First credit' },
});
assert.equal(creditOf(h.providers), 'First credit');
assert.equal(creditOf(h), 'First credit');
const again = (display) =>
h.rendering.setFrame(
{ ...base, product, ...(display ? { display } : {}) },
@@ -734,22 +702,22 @@ test('a refreshed manifest updates the credit of the frame already shown', async
);
assert.equal(await again({ credit: 'Second credit' }), true);
assert.equal(h.providers.length, 1, 'the frame is not restaged');
assert.equal(creditOf(h.providers), 'Second credit');
assert.equal(creditOf(h), 'Second credit');
assert.equal(await again(), true);
assert.equal(creditOf(h.providers), BUILT_IN[product].credit);
assert.equal(creditOf(h), BUILT_IN[product].credit);
h.rendering.updateSnapshot({
...base,
product,
display: { credit: 'Third credit' },
});
assert.equal(creditOf(h.providers), 'Third credit');
assert.equal(creditOf(h), 'Third credit');
// Another product's manifest leaves this frame alone.
h.rendering.updateSnapshot({
...base,
product: 'radar',
display: { credit: 'Other' },
});
assert.equal(creditOf(h.providers), 'Third credit');
assert.equal(creditOf(h), 'Third credit');
h.rendering.clear();
}
});
@@ -790,7 +758,7 @@ test('a refreshed manifest leaves the shown snapshot for a host switch to restag
display: { credit: 'Second credit' },
};
rendering.updateSnapshot(refreshed);
assert.equal(creditOf(globe.providers), 'Second credit');
assert.equal(creditOf(globe), 'Second credit');
host = { collection: {}, kind: 'tileset' };
assert.equal(rendering.rehome(), true);
await flush();
@@ -799,15 +767,12 @@ test('a refreshed manifest leaves the shown snapshot for a host switch to restag
assert.equal(rendering.rehome(), true);
await globe.settle();
assert.equal(globe.providers.length, 2);
const { west, south, east, north } = first.bounds;
assert.ok(
Cesium.Rectangle.equals(
globe.providers.at(-1).options.rectangle,
Cesium.Rectangle.fromDegrees(west, south, east, north),
),
assert.deepEqual(
globe.providers.at(-1).spec.rectangle,
first.bounds,
'the restaged frame keeps the bounds it was staged from',
);
assert.equal(creditOf(globe.providers), 'Second credit');
assert.equal(creditOf(globe), 'Second credit');
rendering.clear();
});
@@ -847,7 +812,7 @@ test('a refresh during a host-switch restage keeps the newest credit', async ()
rendering.updateSnapshot({ ...first, display: { credit: 'Third credit' } });
await globe.settle();
assert.equal(globe.providers.length, 2);
assert.equal(creditOf(globe.providers), 'Third credit');
assert.equal(creditOf(globe), 'Third credit');
rendering.clear();
});
@@ -879,7 +844,7 @@ test('a refresh while a frame loads survives a later host switch', async () => {
rendering.updateSnapshot({ ...first, display: { credit: 'Second credit' } });
await globe.settle();
assert.equal(await shown, true);
assert.equal(creditOf(globe.providers), 'Second credit');
assert.equal(creditOf(globe), 'Second credit');
host = { collection: {}, kind: 'tileset' };
assert.equal(rendering.rehome(), true);
await flush();
@@ -887,7 +852,7 @@ test('a refresh while a frame loads survives a later host switch', async () => {
assert.equal(rendering.rehome(), true);
await globe.settle();
assert.equal(globe.providers.length, 2);
assert.equal(creditOf(globe.providers), 'Second credit');
assert.equal(creditOf(globe), 'Second credit');
rendering.clear();
});
@@ -906,7 +871,7 @@ test('a refresh before a frame is installed gives it the newest credit', async (
});
await globe.settle();
assert.equal(await shown, true);
assert.equal(creditOf(globe.providers), 'Second credit', product);
assert.equal(creditOf(globe), 'Second credit', product);
rendering.clear();
}
});
@@ -933,13 +898,13 @@ test('a layer refresh with the same latest frame updates the imagery credit', as
const first = layer.update();
await globe.settle();
await first;
assert.equal(creditOf(globe.providers), 'First credit');
assert.equal(creditOf(globe), 'First credit');
manifest = { ...manifest, display: { credit: 'Second credit' } };
await layer.update();
assert.equal(globe.providers.length, 1, 'the frame is not restaged');
assert.equal(creditOf(globe.providers), 'Second credit');
assert.equal(creditOf(globe), 'Second credit');
manifest = { ...base, product: 'lightning' };
await layer.update();
assert.equal(creditOf(globe.providers), BUILT_IN.lightning.credit);
assert.equal(creditOf(globe), BUILT_IN.lightning.credit);
layer.destroy();
});