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

+6
View File
@@ -3466,6 +3466,7 @@
"src/layers/earthquakes/records.js",
"src/app/layers/perimeters.js",
"src/layers/perimeters/index.js",
"src/render/color.js",
"src/layers/perimeters/source.js",
"src/layers/perimeters/records.js",
"src/layers/perimeters/cards.js",
@@ -4235,6 +4236,7 @@
"src/layers/earthquakes/records.js",
"src/app/layers/perimeters.js",
"src/layers/perimeters/index.js",
"src/render/color.js",
"src/layers/perimeters/source.js",
"src/layers/perimeters/records.js",
"src/layers/perimeters/cards.js",
@@ -5335,6 +5337,10 @@
"exports": ["./layers/perimeters"],
"modules": [
"src/layers/perimeters/index.js",
"src/render/color.js",
"src/geo/ellipsoid.js",
"src/render/rendererOf.js",
"src/geo/vector.js",
"src/sources/httpBody.js",
"src/i18n/marker.js",
"src/layers/perimeters/source.js",
+83 -59
View File
@@ -1,4 +1,6 @@
import * as Cesium from 'cesium';
import { fromDegrees } from '../../geo/ellipsoid.js';
import { drawOf } from '../../render/rendererOf.js';
import { hexColor } from '../../render/color.js';
import {
PERIMETER_OVERLAY_SOURCE_ID,
perimeterAnchorDegrees,
@@ -17,13 +19,24 @@ export { createWfigsPerimeterSource } from './source.js';
export * from './cards.js';
export * from './inciweb.js';
/** Fill/line color for a perimeter by containment progress (same ramp as the card accent). */
/**
* Fill/line colour for a perimeter by containment progress (same ramp as the
* card accent), as a renderer colour `[r, g, b, a]`.
*/
export function containmentColor(containedPct) {
return Cesium.Color.fromCssColorString(containmentAccent(containedPct));
return hexColor(containmentAccent(containedPct));
}
const ringPositions = (ring) =>
ring.map(([lon, lat]) => Cesium.Cartesian3.fromDegrees(lon, lat));
const withAlpha = ([r, g, b], alpha) => [r, g, b, alpha];
const ringDegrees = (ring) => ring.map(([lon, lat]) => ({ lon, lat }));
/**
* The draw sets the perimeters are drawn in start with this; each layer has
* its own (`fire-perimeters:1:fills`, …), so several can share a renderer.
* Picks name them as `Hit.set`.
*/
export const PERIMETER_SET_PREFIX = 'fire-perimeters';
let instances = 0;
const PICK_PREFIX = 'fire-perimeter:';
const CARD_HOST_OPTIONS = Object.freeze({
@@ -36,7 +49,14 @@ const CARD_HOST_OPTIONS = Object.freeze({
// of near-identical bytes.
const INCIWEB_INDEX_TTL_MS = 6 * 3600000;
/** Own one fire-perimeter display, its refresh lifecycle, and click selection. */
/**
* Own one fire-perimeter display, its refresh lifecycle, and click selection.
*
* Each perimeter is a ground-clamped fill in one renderer draw set and its
* fire line a draped line in another (`drawOf(viewer)`), made at `init`.
* Given a Cesium viewer with no renderer bound, the
* caller loads the package's `./render/cesium/unbound` export first.
*/
export function createFirePerimetersLayer({
source,
overlayHost = null,
@@ -52,7 +72,9 @@ export function createFirePerimetersLayer({
let _request = null;
let _linkRequest = null;
let _snapshotSignature = null;
let _dataSource = null;
let _fills = null;
let _lines = null;
let _setIds = new Set();
let _count = 0;
let _lastUpdate = null;
// The proxy's last snapshot, served while WFIGS is unreachable.
@@ -155,7 +177,7 @@ export function createFirePerimetersLayer({
candidate && _linkVerdicts.get(candidate) === true ? candidate : null;
const card = {
...buildIncidentCard(row, Date.now(), { link: _selectedLink }),
position: Cesium.Cartesian3.fromDegrees(row.anchor.lon, row.anchor.lat),
position: fromDegrees(row.anchor.lon, row.anchor.lat),
};
if (!openExternal) card.interactive = false;
if (_selectedLink && openExternal) {
@@ -174,12 +196,15 @@ export function createFirePerimetersLayer({
);
}
/** Resolve a scene pick to one of this layer's incident ids, or null. */
function pickedIncidentId(picked) {
const pickId = picking.resolvePickId(picked);
if (typeof pickId !== 'string' || !pickId.startsWith(PICK_PREFIX))
/**
* The incident a click's draw hit (`Hit`, query.d.ts) belongs to: an item
* of this layer's own sets, for an incident drawn now; else null.
*/
function pickedIncidentId(hit) {
if (!hit || hit.surface || !_setIds.has(hit.set)) return null;
if (typeof hit.id !== 'string' || !hit.id.startsWith(PICK_PREFIX))
return null;
const incidentId = pickId.slice(PICK_PREFIX.length).split(':')[0];
const incidentId = hit.id.slice(PICK_PREFIX.length).split(':')[0];
return _rowById.has(incidentId) ? incidentId : null;
}
@@ -203,7 +228,7 @@ export function createFirePerimetersLayer({
return;
}
const picked = event.pick;
const incidentId = picked ? pickedIncidentId(picked) : null;
const incidentId = picked ? pickedIncidentId(event.drawHit) : null;
if (incidentId) {
abortLinkVerification();
_selectedId = incidentId;
@@ -250,10 +275,20 @@ export function createFirePerimetersLayer({
init(viewer) {
if (_viewer)
throw new Error('Fire perimeter layer is already initialized');
const draw = drawOf(viewer);
const prefix = `${PERIMETER_SET_PREFIX}:${++instances}`;
_fills = draw.shapes({
id: `${prefix}:fills`,
clampTo: 'both',
show: false,
});
_lines = draw.lines({
id: `${prefix}:lines`,
clampTo: 'both',
show: false,
});
_setIds = new Set([_fills.id, _lines.id]);
_viewer = viewer;
_dataSource = new Cesium.CustomDataSource('fire-perimeters');
_dataSource.show = false;
viewer.dataSources.add(_dataSource);
_count = 0;
_lastUpdate = null;
_lastError = null;
@@ -264,7 +299,7 @@ export function createFirePerimetersLayer({
enable() {
_enabled = true;
if (_dataSource) _dataSource.show = true;
if (_fills) _fills.show = _lines.show = true;
overlayHost?.setVisible?.(PERIMETER_OVERLAY_SOURCE_ID, true);
installClickHandler();
},
@@ -273,13 +308,13 @@ export function createFirePerimetersLayer({
_request?.abort();
_request = null;
_enabled = false;
if (_dataSource) _dataSource.show = false;
if (_fills) _fills.show = _lines.show = false;
removeClickHandler();
clearSelection();
},
async update() {
if (!_enabled || !_dataSource) return false;
if (!_enabled || !_fills) return false;
_request?.abort();
const request = new AbortController();
_request = request;
@@ -314,40 +349,29 @@ export function createFirePerimetersLayer({
return true;
}
abortLinkVerification();
const nextEntities = [];
const nextFills = [];
const nextLines = [];
_rowById.clear();
for (const row of rows) {
const color = containmentColor(row.containedPct);
for (const [index, rings] of row.polygons.entries()) {
const [outer, ...holes] = rings;
const outerPositions = ringPositions(outer);
nextEntities.push(
new Cesium.Entity({
id: `fire-perimeter:${row.stableId}:${index}`,
polygon: {
hierarchy: new Cesium.PolygonHierarchy(
outerPositions,
holes.map(
(hole) =>
new Cesium.PolygonHierarchy(ringPositions(hole)),
),
),
material: new Cesium.ColorMaterialProperty(
color.withAlpha(0.25),
),
},
// The fire line: ground-clamped outline (entity polygons cannot
// outline clamped geometry themselves).
polyline: {
positions: outerPositions,
clampToGround: true,
width: 2,
material: new Cesium.ColorMaterialProperty(
color.withAlpha(0.9),
),
},
}),
);
const id = `${PICK_PREFIX}${row.stableId}:${index}`;
// Each exterior keeps its own holes.
nextFills.push({
id,
geometry: { kind: 'polygon', rings: rings.map(ringDegrees) },
fill: withAlpha(color, 0.25),
height: 'clampGround',
});
// The fire line: the exterior ring draped on the ground (lines
// take ECEF, draw.d.ts `LineItem`).
nextLines.push({
id,
positions: rings[0].map(([lon, lat]) => fromDegrees(lon, lat)),
widthPx: 2,
mode: 'draped',
style: { kind: 'solid', color: withAlpha(color, 0.9) },
});
}
// Keep a geometry-free projection: the coordinate arrays would
// otherwise be retained for the layer's lifetime while only the
@@ -359,8 +383,8 @@ export function createFirePerimetersLayer({
});
}
_dataSource.entities.removeAll();
for (const entity of nextEntities) _dataSource.entities.add(entity);
_fills.set(nextFills);
_lines.set(nextLines);
_snapshotSignature = signature;
// Refresh (or drop) the selected incident's card against the new feed.
if (_selectedId) publishSelectedCard();
@@ -368,7 +392,7 @@ export function createFirePerimetersLayer({
_lastUpdate = updatedAt;
_lastError = null;
console.log(
`[Data:FirePerimeters] Updated: ${_count} incidents, ${nextEntities.length} polygons`,
`[Data:FirePerimeters] Updated: ${_count} incidents, ${nextFills.length} polygons`,
);
return true;
} catch (e) {
@@ -384,7 +408,7 @@ export function createFirePerimetersLayer({
}
},
destroy(viewer = _viewer) {
destroy() {
_request?.abort();
_request = null;
removeClickHandler();
@@ -396,10 +420,10 @@ export function createFirePerimetersLayer({
_linkVerdicts.clear();
_viewer = null;
_enabled = false;
if (_dataSource) {
viewer.dataSources.remove(_dataSource, true);
_dataSource = null;
}
_fills?.dispose();
_lines?.dispose();
_fills = _lines = null;
_setIds = new Set();
_count = 0;
_lastUpdate = null;
_lastError = null;
@@ -408,7 +432,7 @@ export function createFirePerimetersLayer({
/** Snapshot incident facts (with card-anchor coordinates) for the analyst query engine. */
getAnalystRecords(maxCount = 2000) {
if (!_dataSource || !_dataSource.show) return [];
if (!_fills || !_fills.show) return [];
const limit = Number.isFinite(maxCount)
? Math.max(1, Math.floor(maxCount))
: 2000;
+120 -65
View File
@@ -2,6 +2,16 @@ import assert from 'node:assert/strict';
import test from 'node:test';
import { createFirePerimetersLayer } from './index.js';
import { fakeInput } from '../../input/testDoubles.mjs';
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
// The fills set of the layer the last harness made: perimeter picks name it.
let fillsSetId = null;
/** A Cesium pick of a perimeter's fill, as the draw port makes it. */
const perimeterPick = (id) => ({ id: { set: fillsSetId, id } });
const liveSet = (draw, suffix) =>
[...draw.sets.values()].find(
(record) => !record.disposed && record.spec.id.endsWith(suffix),
);
function harness(
source,
@@ -15,21 +25,11 @@ function harness(
}),
} = {},
) {
const sources = [];
const overlay = { entries: new Map(), visible: null };
const owners = new Map();
const opened = [];
const viewer = {
scene: { pick },
dataSources: {
add(value) {
sources.push(value);
},
remove(value) {
sources.splice(sources.indexOf(value), 1);
},
},
};
const viewer = { scene: { pick } };
const { draw } = bindFakeDraw(viewer);
const input = fakeInput(viewer);
const clicks = {
handler: (click) => input.click(click.position),
@@ -53,7 +53,7 @@ function harness(
},
inputFor: () => input.input,
picking: {
resolvePickId: (picked) => picked?.id ?? null,
resolvePickId: (picked) => picked?.id?.id ?? picked?.id ?? null,
isOwnedByOtherLayer: (layerId, pickedId) =>
String(pickedId).startsWith('other-layer:'),
registerPickOwner: (layerId, predicate) => owners.set(layerId, predicate),
@@ -67,7 +67,18 @@ function harness(
});
layer.init(viewer);
layer.enable(viewer);
return { layer, viewer, sources, overlay, clicks, owners, opened };
fillsSetId = liveSet(draw, ':fills').spec.id;
return {
layer,
viewer,
draw,
fills: () => liveSet(draw, ':fills'),
lines: () => liveSet(draw, ':lines'),
overlay,
clicks,
owners,
opened,
};
}
const ring = [
@@ -95,22 +106,82 @@ const row = {
polygons: [[ring]],
};
test('each perimeter polygon renders as one filled entity with its fire line', async () => {
test('each perimeter polygon draws as one clamped fill with its draped fire line', async () => {
const hole = [
[-108.08, 35.22],
[-108.02, 35.22],
[-108.02, 35.25],
[-108.08, 35.22],
];
const h = harness({
getSnapshot: async () => [
row,
{ ...row, stableId: 'other', polygons: [[ring], [ring]] },
{ ...row, polygons: [[ring, hole]] },
{
...row,
stableId: 'other',
containedPct: 100,
polygons: [[ring], [ring]],
},
],
});
assert.equal(h.fills().show, true);
assert.equal(h.lines().show, true);
assert.equal(await h.layer.update(h.viewer), true);
const entities = h.sources[0].entities.values;
assert.equal(entities.length, 3);
assert.equal(entities[0].id, 'fire-perimeter:2026-NMGNF-000123:0');
assert.ok(entities[0].polygon, 'perimeter fill missing');
assert.ok(entities[0].polyline, 'fire line missing');
assert.equal(entities[1].id, 'fire-perimeter:other:0');
assert.equal(entities[2].id, 'fire-perimeter:other:1');
const ids = [
'fire-perimeter:2026-NMGNF-000123:0',
'fire-perimeter:other:0',
'fire-perimeter:other:1',
];
assert.deepEqual([...h.fills().items.keys()], ids);
assert.deepEqual([...h.lines().items.keys()], ids);
const fill = h.fills().items.get(ids[0]);
assert.equal(fill.height, 'clampGround');
assert.deepEqual(fill.fill, [1, 122 / 255, 0, 0.25]);
assert.equal(fill.geometry.kind, 'polygon');
assert.equal(fill.geometry.rings.length, 2, 'the hole stays');
assert.deepEqual(fill.geometry.rings[0][1], { lon: -108.0, lat: 35.2 });
const line = h.lines().items.get(ids[0]);
assert.equal(line.mode, 'draped');
assert.equal(line.widthPx, 2);
assert.deepEqual(line.style, {
kind: 'solid',
color: [1, 122 / 255, 0, 0.9],
});
assert.equal(line.positions.length, ring.length, 'the exterior ring only');
assert.ok(Number.isFinite(line.positions[0].x), 'lines take ECEF');
assert.deepEqual(h.fills().items.get(ids[1]).fill, [
139 / 255,
195 / 255,
74 / 255,
0.25,
]);
assert.equal(h.layer.getStats().count, 2);
h.layer.disable();
assert.equal(h.fills().show, false);
assert.equal(h.lines().show, false);
h.layer.destroy();
assert.equal(h.fills(), undefined, 'destroy disposes the sets');
assert.equal(h.lines(), undefined);
});
test("a pick selects only an item of the layer's own sets", async () => {
let pickResult = null;
const h = harness(
{ getSnapshot: async () => [row] },
{ pick: () => pickResult },
);
await h.layer.update(h.viewer);
pickResult = {
id: { set: 'someone-else', id: 'fire-perimeter:2026-NMGNF-000123:0' },
};
h.clicks.handler({ position: { x: 10, y: 10 } });
assert.equal(h.overlay.entries.get('fire-perimeters')?.length ?? 0, 0);
// The fire line picks as its perimeter, as the one entity used to.
pickResult = {
id: { set: h.lines().spec.id, id: 'fire-perimeter:2026-NMGNF-000123:0' },
};
h.clicks.handler({ position: { x: 10, y: 10 } });
assert.equal(h.overlay.entries.get('fire-perimeters').length, 1);
});
test('late refresh cannot publish after disable or destroy', async () => {
@@ -151,7 +222,7 @@ test('clicking a perimeter publishes its incident card; empty space clears it',
// overlay cards inert anywhere over a perimeter.
assert.equal(h.owners.size, 0);
pickResult = { id: 'fire-perimeter:2026-NMGNF-000123:0' };
pickResult = perimeterPick('fire-perimeter:2026-NMGNF-000123:0');
h.clicks.handler({ position: { x: 10, y: 10 } });
const entries = h.overlay.entries.get('fire-perimeters');
assert.equal(entries.length, 1);
@@ -175,7 +246,7 @@ test('clicking a perimeter publishes its incident card; empty space clears it',
test('disable removes the click handler, pick ownership, and any card', async () => {
const h = harness(
{ getSnapshot: async () => [row] },
{ pick: () => ({ id: 'fire-perimeter:2026-NMGNF-000123:0' }) },
{ pick: () => perimeterPick('fire-perimeter:2026-NMGNF-000123:0') },
);
await h.layer.update(h.viewer);
h.clicks.handler({ position: { x: 10, y: 10 } });
@@ -189,7 +260,7 @@ test('a refresh that drops the selected incident also drops its card', async ()
let rows = [row];
const h = harness(
{ getSnapshot: async () => rows },
{ pick: () => ({ id: 'fire-perimeter:2026-NMGNF-000123:0' }) },
{ pick: () => perimeterPick('fire-perimeter:2026-NMGNF-000123:0') },
);
await h.layer.update(h.viewer);
h.clicks.handler({ position: { x: 10, y: 10 } });
@@ -218,9 +289,8 @@ test('a matched incident card carries the InciWeb line and click-through', async
);
await h.layer.update(h.viewer);
// Select via a perimeter pick.
h.viewer.scene.pick = () => ({
id: 'fire-perimeter:2026-NMGNF-000123:0',
});
h.viewer.scene.pick = () =>
perimeterPick('fire-perimeter:2026-NMGNF-000123:0');
h.clicks.handler({ position: { x: 10, y: 10 } });
// The card publishes immediately; the link line lands once the
// publication's currency is validated.
@@ -246,7 +316,7 @@ test('an unmatched incident renders no InciWeb line and card clicks stay inert',
const h = harness(
{ getSnapshot: async () => [row] },
{
pick: () => ({ id: 'fire-perimeter:2026-NMGNF-000123:0' }),
pick: () => perimeterPick('fire-perimeter:2026-NMGNF-000123:0'),
inciwebIndex: [],
cardHit: () => cardHitResult,
},
@@ -269,7 +339,7 @@ test('a complex member resolves to its complex page from the catalog', async ()
const h = harness(
{ getSnapshot: async () => [row] },
{
pick: () => ({ id: 'fire-perimeter:2026-NMGNF-000123:0' }),
pick: () => perimeterPick('fire-perimeter:2026-NMGNF-000123:0'),
inciwebIndex: [
{
// Same state as the member fire: the state filter applies to
@@ -310,7 +380,7 @@ test('a stale or unverifiable publication yields no link', async () => {
const h = harness(
{ getSnapshot: async () => [row] },
{
pick: () => ({ id: 'fire-perimeter:2026-NMGNF-000123:0' }),
pick: () => perimeterPick('fire-perimeter:2026-NMGNF-000123:0'),
inciwebIndex,
publication,
},
@@ -335,14 +405,8 @@ test('a hanging InciWeb index fetch never blocks the perimeter refresh', async (
h.layer.destroy(h.viewer);
const hanging = harness({ getSnapshot: async () => [row] });
hanging.layer.destroy(hanging.viewer);
const sources = [];
const viewer = {
scene: { pick: () => null },
dataSources: {
add: (v) => sources.push(v),
remove: (v) => sources.splice(sources.indexOf(v), 1),
},
};
const viewer = { scene: { pick: () => null } };
bindFakeDraw(viewer);
const input = fakeInput(viewer);
t.after(() => input.destroy());
const layer = createFirePerimetersLayer({
@@ -405,10 +469,8 @@ test('an InciWeb outage never breaks the perimeter refresh', async (t) => {
},
openExternal: () => {},
});
const viewer = {
scene: { pick: () => null },
dataSources: { add() {}, remove() {} },
};
const viewer = { scene: { pick: () => null } };
bindFakeDraw(viewer);
const failingInput = fakeInput(viewer);
t.after(() => failingInput.destroy());
failing.init(viewer);
@@ -440,40 +502,33 @@ test('analyst records expose incident facts without geometry payloads', async ()
assert.equal('polygons' in records[0], false);
});
test('unchanged snapshots retain entity identity even if source ordering changes', async () => {
test('unchanged snapshots draw nothing again even if source ordering changes', async () => {
let rows = [row, { ...row, stableId: 'other' }];
const h = harness({ getSnapshot: async () => rows });
await h.layer.update();
const original = [...h.sources[0].entities.values];
let removals = 0;
const entities = h.sources[0].entities;
const removeAll = entities.removeAll.bind(entities);
entities.removeAll = () => {
removals++;
removeAll();
};
const writes = () => [h.fills().writes, h.lines().writes];
assert.deepEqual(writes(), [1, 1]);
rows = [...rows].reverse();
await h.layer.update();
assert.equal(removals, 0);
assert.equal(entities.values[0], original[0]);
assert.deepEqual(writes(), [1, 1]);
rows = rows.map((value) => ({
...value,
updatedTime: value.updatedTime + 1,
}));
await h.layer.update();
assert.equal(removals, 1);
assert.notEqual(entities.values[0], original[0]);
assert.deepEqual(writes(), [2, 2]);
rows = rows.map((value) => ({ ...value, containedPct: 100 }));
await h.layer.update();
assert.equal(
removals,
2,
assert.deepEqual(
writes(),
[3, 3],
'incident facts can change without a new polygon timestamp',
);
assert.equal(h.layer.getRowControls().legend[3].count, 2);
rows = [];
await h.layer.update();
assert.equal(entities.values.length, 0);
assert.equal(h.fills().items.size, 0);
assert.equal(h.lines().items.size, 0);
h.layer.destroy();
});
@@ -518,7 +573,7 @@ test('containment legend uses the existing thresholds, colours and incident coun
for (const action of ['disable', 'destroy', 'selection']) {
test(`incident-link verification aborts on ${action} and ignores late completion`, async () => {
let finish, signal;
let pick = { id: `fire-perimeter:${row.stableId}:0` };
let pickId = `fire-perimeter:${row.stableId}:0`;
const h = harness(
{
getSnapshot: async () => [
@@ -527,7 +582,7 @@ for (const action of ['disable', 'destroy', 'selection']) {
],
},
{
pick: () => pick,
pick: () => perimeterPick(pickId),
inciwebIndex: [
{ incident_id: '123', incident_title: row.name, tau: 'nm' },
],
@@ -543,7 +598,7 @@ for (const action of ['disable', 'destroy', 'selection']) {
h.clicks.handler({ position: { x: 1, y: 1 } });
assert.equal(signal.aborted, false);
if (action === 'selection') {
pick = { id: 'fire-perimeter:other:0' };
pickId = 'fire-perimeter:other:0';
h.clicks.handler({ position: { x: 1, y: 1 } });
} else h.layer[action]();
assert.equal(signal.aborted, true);
+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'));