Draw tropical cyclones through the renderer's draw port

The cyclone layer no longer imports Cesium. Its advisories are three draw
sets per rendering (points, lines, cones) taken from drawOf(viewer): the
centers and forecast points are clamped dots culled past the horizon, the
tracks and cone outlines are draped lines, and the cones are clamped
polygons that keep their holes. Flights go through cameraOf, and the focus
sphere comes from a port of BoundingSphere.fromPoints in src/geo/sphere.js.

Clicks read the new ClickEvent.drawHit: the dispatcher's pick as the
contract's Hit when it is a draw-set item. The Cesium port's query uses the
same conversion, now in render/cesium/drawHit.js. pickStorm takes that hit
and accepts only current items of the layer's own sets.

Every advisory commit redraws the points, so an empty advisory clears them;
an unchanged selection draws nothing. Far-side tracks and cones are left
to the globe's depth instead of a per-frame occluder. Both cyclone files
leave the Cesium allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-06 19:15:09 -08:00
1 parent bb3106991e
commit bd5a688144
14 files changed
+818 -783

No files matched your search

+89
View File
@@ -359,3 +359,92 @@ test('the earthquakes layer draws its discs as ground fills on a viewer of its o
layer.destroy();
assert.equal(scene.added.length, 0);
});
test('the cyclones layer draws clamped dots, draped tracks and holed cones on a viewer of its own', async () => {
const { createCycloneRendering } =
await import('../../layers/cyclones/rendering.js');
const { scene, frame } = drawOver();
const rendering = createCycloneRendering({
viewer: { scene },
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
});
const storm = (id, lon) => ({
id,
name: id,
advisoryNumber: '1',
geometryAdvisoryNumber: '1',
geometryStatus: 'current',
position: { longitude: lon, latitude: 0 },
forecastPoints: [
{ position: { longitude: lon, latitude: 1 }, tauHours: 12 },
],
track: {
type: 'LineString',
coordinates: [
[lon, 0],
[lon, 1],
],
},
cone: {
type: 'Polygon',
coordinates: [
[
[lon - 2, -2],
[lon + 2, -2],
[lon + 2, 2],
[lon - 2, 2],
[lon - 2, -2],
],
[
[lon - 1, -1],
[lon + 1, -1],
[lon + 1, 1],
[lon - 1, -1],
],
],
},
});
await rendering.setSnapshot({
storms: [storm('near', 0), storm('far', 180)],
});
const all = (host, out = []) => {
out.push(host);
if (host instanceof Cesium.PrimitiveCollection)
for (let i = 0; i < host.length; i++) all(host.get(i), out);
return out;
};
const primitives = scene.added.flatMap((host) => all(host));
const of = (type) => primitives.filter((p) => p instanceof type);
const [dots] = of(Cesium.BillboardCollection);
assert.equal(dots.length, 4, 'two centers, two forecast points');
for (let i = 0; i < dots.length; i++) {
const dot = dots.get(i);
assert.equal(dot.heightReference, Cesium.HeightReference.CLAMP_TO_GROUND);
assert.equal(dot.disableDepthTestDistance, Infinity);
}
const [tracks] = of(Cesium.GroundPolylinePrimitive);
assert.equal(tracks.classificationType, Cesium.ClassificationType.BOTH);
assert.equal(tracks.geometryInstances.length, 6, 'tracks and ring outlines');
const cones = of(Cesium.GroundPrimitive);
const instances = cones.flatMap((cone) => cone.geometryInstances);
assert.deepEqual(instances.map((instance) => instance.id.id).sort(), [
'cyclone:far:cone:0',
'cyclone:near:cone:0',
]);
for (const { geometry } of instances)
assert.equal(geometry._polygonHierarchy.holes.length, 1, 'the hole stays');
// Past the horizon the dots go; their storms' shapes are the globe's to hide.
frame();
const shown = [];
for (let i = 0; i < dots.length; i++)
shown.push([dots.get(i).id.id, dots.get(i).show]);
assert.deepEqual(shown.sort(), [
['cyclone:far:center', false],
['cyclone:far:forecast:0', false],
['cyclone:near:center', true],
['cyclone:near:forecast:0', true],
]);
rendering.destroy();
assert.equal(scene.added.length, 0);
});
+27
View File
@@ -0,0 +1,27 @@
/**
* @module render/cesium/drawHit
* @description A Cesium pick of a draw-set item, as the contract's `Hit`.
* No imports, so the click dispatcher can use it without the draw port.
*/
/**
* A Cesium pick as the contract's `Hit` (`query.d.ts`), when what it picked
* is a draw-set item (its pick id is `{set, id, meta, lodGroup}`); else
* null. For code that reads a pick Cesium already made (the click
* dispatcher's); `query.pick` makes its own, and also leaves out items of
* hidden or unpickable sets. It does not check that the set or item is
* still drawn (a ground swap can pick a retiring primitive), so a caller
* matches the hit against its own current sets and item ids.
* @param {object|null|undefined} picked
*/
export function drawHitOf(picked) {
const id = picked?.id;
if (!id || typeof id.set !== 'string' || typeof id.id !== 'string')
return null;
return {
set: id.set,
id: id.id,
...(id.meta === undefined ? {} : { meta: id.meta }),
...(id.lodGroup === undefined ? {} : { lodGroup: id.lodGroup }),
surface: false,
};
}
+2 -9
View File
@@ -18,6 +18,7 @@ import { createCesiumCamera } from './camera.js';
import { listenerList, toCartesian, uncaught } from './common.js';
import { createCesiumCredits } from './credits.js';
import { createCesiumDraw } from './draw.js';
import { drawHitOf } from './drawHit.js';
import { createCesiumEffects } from './effects.js';
import { createCesiumGlobe } from './globe.js';
import { createCesiumQuality } from './quality.js';
@@ -412,15 +413,7 @@ export function createCesiumPorts(widget, { capabilities, credentials = {} }) {
item.show !== false &&
item.pickable !== false;
function hitOf({ id }) {
return {
set: id.set,
id: id.id,
...(id.meta === undefined ? {} : { meta: id.meta }),
...(id.lodGroup === undefined ? {} : { lodGroup: id.lodGroup }),
surface: false,
};
}
const hitOf = ({ id }) => drawHitOf({ id });
/** The globe (or ellipsoid) under a pixel, as a surface hit. */
function surfaceHit(x, y) {