Draw wildfire perimeters through the renderer's draw port

Perimeter fills are clamped polygon fills with their holes, and fire
lines are draped lines along each outer ring, in two draw sets per layer
(fire-perimeters:N:fills and :lines). Clicks read the draw hit and match
the layer's own set and item ids. Colours, alphas, widths and clamping
are unchanged. The layer no longer imports Cesium, so it leaves the
allow-list and joins the entries whose callers load the unbound draw
factory. Hex palette colours become renderer colours through a small
shared helper.
This commit is contained in:
Sameh Khamis committed 2026-11-06 20:30:20 -08:00
1 parent d30b89ac8e
commit 3f9089eccb
8 files changed
+282 -125

No files matched your search

+49
View File
@@ -751,3 +751,52 @@ test('a position object changed and sent again moves its point', () => {
assert.ok(Math.abs(Cesium.Math.toDegrees(at.longitude) - 90) < 1e-9);
set.dispose();
});
test('the fire perimeters layer draws holed ground fills and draped fire lines on a viewer of its own', async () => {
const { createFirePerimetersLayer } =
await import('../../layers/perimeters/index.js');
const scene = fakeScene();
const viewer = { scene };
const outer = [
[-108.1, 35.2],
[-108.0, 35.2],
[-108.0, 35.3],
[-108.1, 35.2],
];
const hole = [
[-108.08, 35.22],
[-108.02, 35.22],
[-108.02, 35.25],
[-108.08, 35.22],
];
const layer = createFirePerimetersLayer({
source: {
getSnapshot: async () => [
{ stableId: 'a', containedPct: 0, polygons: [[outer, hole]] },
],
},
});
layer.init(viewer);
layer.enable(viewer);
assert.equal(await layer.update(viewer), true);
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 [fill] = of(Cesium.GroundPrimitive);
assert.equal(fill.classificationType, Cesium.ClassificationType.BOTH);
const [instance] = fill.geometryInstances;
assert.equal(instance.id.id, 'fire-perimeter:a:0');
assert.equal(instance.geometry._polygonHierarchy.holes.length, 1);
const [line] = of(Cesium.GroundPolylinePrimitive);
assert.equal(line.classificationType, Cesium.ClassificationType.BOTH);
assert.equal(line.geometryInstances.length, 1, 'the exterior ring only');
assert.equal(line.geometryInstances[0].geometry.width, 2);
assert.equal(line.geometryInstances[0].id.id, 'fire-perimeter:a:0');
layer.destroy();
assert.equal(scene.added.length, 0);
});
-1
View File
@@ -117,7 +117,6 @@
"src/layers/military/state.js",
"src/layers/military/testing.js",
"src/layers/military/tracking.js",
"src/layers/perimeters/index.js",
"src/layers/radio/lifecycle.js",
"src/layers/radio/rendering.js",
"src/layers/recentImagery/rendering.js",
+15
View File
@@ -0,0 +1,15 @@
/**
* Renderer colours (`[r, g, b, a]`, 0..1) from the CSS-style colours layers
* keep in their palettes.
*/
/** A `#rrggbb` colour at `alpha`, as a renderer colour. */
export function hexColor(hex, alpha = 1) {
const n = Number.parseInt(hex.slice(1), 16);
return [
((n >> 16) & 255) / 255,
((n >> 8) & 255) / 255,
(n & 255) / 255,
alpha,
];
}
+8
View File
@@ -0,0 +1,8 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { hexColor } from './color.js';
test('hex colours become renderer colours at the given alpha', () => {
assert.deepEqual(hexColor('#ff8000'), [1, 128 / 255, 0, 1]);
assert.deepEqual(hexColor('#000000', 0.25), [0, 0, 0, 0.25]);
});
+1
View File
@@ -67,6 +67,7 @@ const FALLS_BACK = new Set(['src/data/followed.js']);
const DRAW_FROM_CALLER = new Set([
'./layers/earthquakes',
'./layers/bikeshare',
'./layers/perimeters',
]);
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));