Draw the context rim through the renderer's draw port

The Contacts layer's 250 km rim is now an outline-only ellipse in a draw
set of its own, taken from drawOf(viewer) when it is first drawn: the
same colour, height and radius, moved only after the subject travels 250
m, cleared with the subject and disposed with the layer. A rim drawn on
another viewer is redrawn on the current one. The Cesium draw port draws
the outlines of ellipses it does not clamp as the entities did, with an
outline geometry.

The layer's positions are plain ECEF from src/geo rather than Cesium
objects, the compass reads the camera through its port's pose, and its
flights go through cameraOf from the renderer bridge. Its four files
leave the Cesium allow-list; a caller handing the layer a viewer of its
own loads ./render/cesium/unbound first, as for earthquakes.
This commit is contained in:
Sameh Khamis committed 2026-11-06 20:39:36 -08:00
1 parent 6e23d2aac9
commit df1143485a
14 files changed
+272 -154

No files matched your search

+45 -11
View File
@@ -706,17 +706,23 @@ export function createCesiumDraw({ scene, report }) {
ring: outer,
};
}
case 'ellipse':
return {
fill: new Cesium.EllipseGeometry({
center: toCartesian(g.center),
semiMajorAxis: g.semiMajor,
semiMinorAxis: g.semiMinor,
rotation: g.rotation ?? 0,
height: heightOf(g.center),
extrudedHeight,
}),
case 'ellipse': {
const ellipse = {
center: toCartesian(g.center),
semiMajorAxis: g.semiMajor,
semiMinorAxis: g.semiMinor,
rotation: g.rotation ?? 0,
height: heightOf(g.center),
extrudedHeight,
};
return {
fill: new Cesium.EllipseGeometry(ellipse),
// Its outline is an outline geometry, as the entities' ellipses draw it.
outline: item.outline
? new Cesium.EllipseOutlineGeometry(ellipse)
: undefined,
};
}
case 'rectangle':
return {
fill: new Cesium.RectangleGeometry({
@@ -878,7 +884,35 @@ export function createCesiumDraw({ scene, report }) {
}),
);
}
if (item.outline && shape.ring)
if (item.outline && shape.outline) {
const color = toColor(item.outline);
host.add(
new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: shape.outline,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(color),
},
id,
}),
appearance: new Cesium.PerInstanceColorAppearance({
flat: true,
translucent: color.alpha < 1,
renderState: {
// Clamped to what the context draws, as entities do.
lineWidth:
typeof scene.clampLineWidth === 'function'
? scene.clampLineWidth(item.outlineWidth ?? 1)
: Math.min(
item.outlineWidth ?? 1,
scene.maximumAliasedLineWidth ?? 1,
),
},
}),
asynchronous: false,
}),
);
} else if (item.outline && shape.ring)
outlines.add({
positions: [...shape.ring, shape.ring[0]],
width: item.outlineWidth ?? 1,
+68
View File
@@ -931,3 +931,71 @@ test('the fires layer draws its heat cells as ground fills through the Cesium dr
layer.destroy(viewer);
assert.equal(grounds().length, 0);
});
test('the context layer draws its rim as an outlined ellipse on a viewer of its own', async () => {
const { createRendering } =
await import('../../layers/awareness/rendering.js');
const { createState } = await import('../../layers/awareness/state.js');
const { scene } = drawOver();
const state = createState({ services: {} });
state.viewer = { scene };
const rendering = createRendering({
state,
services: {
geometry: {},
render: { governorRequestRender() {} },
},
parts: {},
});
const subject = (lon) => ({
layerId: 'military',
id: 'a',
position: Cesium.Cartesian3.fromDegrees(lon, 0, 9000),
});
rendering.renderVisual(subject(0));
const outlineOf = () => {
const [host] = scene.added;
const primitives = [];
for (let i = 0; i < host.length; i++) primitives.push(host.get(i));
const outline = primitives.find(
(p) =>
p instanceof Cesium.Primitive &&
p.geometryInstances.geometry instanceof Cesium.EllipseOutlineGeometry,
);
assert.ok(outline, 'an outline geometry, as the entity drew');
assert.ok(
!primitives.some(
(p) =>
p instanceof Cesium.Primitive &&
p.geometryInstances.geometry instanceof Cesium.EllipseGeometry,
),
'and no fill',
);
return outline;
};
const outline = outlineOf();
const { geometry, attributes } = outline.geometryInstances;
assert.equal(geometry._semiMajorAxis, 250_000);
assert.equal(geometry._height, 2_500);
const center = Cesium.Cartographic.fromCartesian(geometry._center);
assert.ok(Math.abs(center.longitude) < 1e-9);
assert.deepEqual(
[...attributes.color.value],
[0x62, 0xb5, 0xff, Math.round(0.72 * 255)],
);
// Small moves keep the ring; one past 250 m moves it.
rendering.renderVisual(subject(0.001));
assert.equal(outlineOf(), outline);
rendering.renderVisual(subject(0.01));
assert.notEqual(outlineOf(), outline);
// Re-initialized on another viewer, the same subject's rim moves there.
const other = drawOver().scene;
state.viewer = { scene: other };
rendering.renderVisual(subject(0.01));
assert.equal(scene.added.length, 0, 'gone from the old viewer');
assert.equal(other.added.length, 1, 'drawn on the new one');
rendering.clearVisual();
assert.equal(other.added[0].length, 1, 'only the empty polyline collection');
rendering.disposeVisual();
assert.equal(other.added.length, 0);
});
-4
View File
@@ -45,10 +45,6 @@
"src/layers/alpr/overlay.js",
"src/layers/alpr/presentation.js",
"src/layers/alpr/visuals.js",
"src/layers/awareness/focus.js",
"src/layers/awareness/rendering.js",
"src/layers/awareness/state.js",
"src/layers/awareness/subject.js",
"src/layers/cctv/cards.js",
"src/layers/cctv/geometry.js",
"src/layers/cctv/geometryQueue.js",
+1
View File
@@ -69,6 +69,7 @@ const DRAW_FROM_CALLER = new Set([
'./layers/bikeshare',
'./layers/gnss',
'./layers/perimeters',
'./layers/awareness',
]);
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));