Take the camera layer's policy, state, model and ground off Cesium

The layer's colours are renderer colours; the parts that still draw with
Cesium (icons, coverage lines, the monitor plane) turn them into Cesium
colours with the adapter's own conversion. The screen and matrix scratches
are plain objects, which is all the projections that fill them write.

The model part converts angles with geo/vector, reads where the eye is
from the camera port's pose, and builds the monitor plane's orientation
with geo/quaternion from the same axes; the projection part hands the
entity a Cesium quaternion of it. The photoreal tileset readiness check,
which looks through the scene's primitives, moves to the geometry part.
The ground pass moves a camera icon by writing geo/ellipsoid's position
into the record's own position object. The test plane's plain material
comes from the projection part, and the selection part only lost an
unused import.

All give the same numbers as the Cesium calls they replace. Policy,
state, selection, testing, model and ground leave the allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-06 23:47:08 -08:00
1 parent 2592289612
commit 7d760d32fc
13 files changed
+147 -127

No files matched your search

+7 -3
View File
@@ -365,9 +365,13 @@ test('camera icons are violet for video feeds, cyan for stills, amber when activ
const color = (record) => icons.color(icons.row(record.camera.id));
const bytes = (c) =>
[c.red, c.green, c.blue, c.alpha].map(Cesium.Color.floatToByte);
assert.deepEqual(bytes(color(idleVideo)), bytes(LIVE_CAMERA_COLOR));
assert.deepEqual(bytes(color(idleStill)), bytes(IDLE_CAMERA_COLOR));
assert.deepEqual(bytes(color(activeVideo)), bytes(ACTIVE_CAMERA_COLOR));
const policyBytes = (rgba) => rgba.map(Cesium.Color.floatToByte);
assert.deepEqual(bytes(color(idleVideo)), policyBytes(LIVE_CAMERA_COLOR));
assert.deepEqual(bytes(color(idleStill)), policyBytes(IDLE_CAMERA_COLOR));
assert.deepEqual(
bytes(color(activeVideo)),
policyBytes(ACTIVE_CAMERA_COLOR),
);
assert.equal(icons.scale(icons.row(activeVideo.camera.id)), 1.25);
assert.equal(icons.scale(icons.row(idleVideo.camera.id)), 1);
} finally {
+45 -1
View File
@@ -7,7 +7,7 @@ import {
PROBE_CLEARANCE_M,
COVERAGE_NEIGHBOR_RADIUS_KM,
COVERAGE_NEIGHBOR_LIMIT,
IDLE_COVERAGE_COLOR,
IDLE_COVERAGE_COLOR as IDLE_COVERAGE_RGBA,
PLANE_FOOTPRINT_LIFT_CAP_M,
} from './policy.js';
@@ -17,6 +17,9 @@ import {
requiredPlaneLift,
} from '../../data/cctvFootprint.js';
import { cctvPicks } from './pickState.js';
import { toColor } from '../../render/cesium/draw.js';
const IDLE_COVERAGE_COLOR = toColor(IDLE_COVERAGE_RGBA);
export function createGeometry({ state: layerState, services, parts, source }) {
const { warmGroundFloor, cachedGroundFloor } = services.ground;
@@ -262,6 +265,46 @@ export function createGeometry({ state: layerState, services, parts, source }) {
return Math.max(PROBE_MIN_RANGE_M, hitDistance - PROBE_CLEARANCE_M);
}
/**
* Reports whether the active Google Photorealistic 3D Tileset (if any) has
* finished loading the tiles in view. Shared mesh-floor sampling is gated on
* this so a one-shot cell never bakes in a miss from still-streaming tiles.
* Discovers + caches the tileset lazily from scene
* primitives (the CCTV module holds only a `_viewer` reference). When no
* tileset is present (OSM fallback) this returns true so ground sampling is
* not permanently blocked.
*
* Task 5 (review correction, spec §2): a HIDDEN tileset (`show === false`,
* i.e. a globe stack is active) must NOT report ready — Cesium 1.138's
* the shared sampler can only inspect *visible* 3D tilesets, so a sample taken
* against the hidden Google tileset would silently miss.
*
* @returns {boolean} True when tiles are loaded AND visible (or no tileset
* exists to wait on).
*/
function projectionTilesReady() {
if (
!layerState._activeTileset ||
layerState._activeTileset.isDestroyed?.()
) {
layerState._activeTileset = null;
const primitives = layerState._viewer?.scene?.primitives;
if (primitives && typeof primitives.get === 'function') {
for (let i = 0; i < primitives.length; i++) {
const p = primitives.get(i);
if (p instanceof Cesium.Cesium3DTileset && !p.isDestroyed?.()) {
layerState._activeTileset = p;
break;
}
}
}
}
if (!layerState._activeTileset) return true;
if (layerState._activeTileset.show === false) return false;
return layerState._activeTileset.tilesLoaded === true;
}
/**
* Converts a computeFrustumGeometry result into the Cartesian3 positions the
* entities consume. Fresh objects per call (geometry updates are rare —
@@ -836,6 +879,7 @@ export function createGeometry({ state: layerState, services, parts, source }) {
activationProbeClampRange,
frustumCartesians,
frustumFrameEcef,
projectionTilesReady,
applyFrustumGeometry,
updateRecordGeometry,
buildCoverageVisibleSet,
+6 -4
View File
@@ -1,4 +1,4 @@
import * as Cesium from 'cesium';
import { fromDegrees } from '../../geo/ellipsoid.js';
import {
SUPPORT_KEYS,
planeSupportPoints,
@@ -231,13 +231,15 @@ export function createGround({ state: layerState, services, parts, source }) {
// stall a large one.
if (!record.frustumGeometry) {
if (record.position) {
Cesium.Cartesian3.fromDegrees(
// In place: the record keeps its position object.
const { x, y, z } = fromDegrees(
record.camera.lon,
record.camera.lat,
record.camera.absoluteHeightM,
undefined,
record.position,
);
record.position.x = x;
record.position.y = y;
record.position.z = z;
parts.rendering.moveCameraIcon(record);
moved += 1;
}
+22 -63
View File
@@ -1,4 +1,6 @@
import * as Cesium from 'cesium';
import { cross, negate, toDegrees, toRadians } from '../../geo/vector.js';
import { fromAxes } from '../../geo/quaternion.js';
import { findCamera } from '../../render/rendererOf.js';
import { greatCircleKm } from '../../geoDistance.js';
import { staticFrameRefreshMs } from '../../data/cctvLod.js';
import { frameFetchDue, cardFetchPolicy } from '../../data/cctvCards.js';
@@ -14,7 +16,7 @@ export function createModel({ state: layerState, services, parts, source }) {
*/
function toRad(deg) {
return Cesium.Math.toRadians(deg);
return toRadians(deg);
}
/**
@@ -295,8 +297,8 @@ export function createModel({ state: layerState, services, parts, source }) {
const lon2 = lon1 + Math.atan2(y, x);
return {
lat: Cesium.Math.toDegrees(lat2),
lon: Cesium.Math.toDegrees(lon2),
lat: toDegrees(lat2),
lon: toDegrees(lon2),
};
}
@@ -333,11 +335,11 @@ export function createModel({ state: layerState, services, parts, source }) {
*/
function currentViewContext() {
const carto = layerState._viewer?.camera?.positionCartographic;
if (!carto) return 'none';
const lat = Cesium.Math.toDegrees(carto.latitude);
const lon = Cesium.Math.toDegrees(carto.longitude);
const alt = carto.height || 0;
const pose = findCamera(layerState._viewer)?.pose();
// An eye at the earth's centre has no geographic position.
if (!pose || !Number.isFinite(pose.lat)) return 'none';
const { lat, lon } = pose;
const alt = pose.height || 0;
const zoomBucket =
alt < 1500
? 'street'
@@ -358,43 +360,13 @@ export function createModel({ state: layerState, services, parts, source }) {
}
/**
* Reports whether the active Google Photorealistic 3D Tileset (if any) has
* finished loading the tiles in view. Shared mesh-floor sampling is gated on
* this so a one-shot cell never bakes in a miss from still-streaming tiles.
* Discovers + caches the tileset lazily from scene
* primitives (the CCTV module holds only a `_viewer` reference). When no
* tileset is present (OSM fallback) this returns true so ground sampling is
* not permanently blocked.
*
* Task 5 (review correction, spec §2): a HIDDEN tileset (`show === false`,
* i.e. a globe stack is active) must NOT report ready — Cesium 1.138's
* the shared sampler can only inspect *visible* 3D tilesets, so a sample taken
* against the hidden Google tileset would silently miss.
*
* @returns {boolean} True when tiles are loaded AND visible (or no tileset
* exists to wait on).
* Whether the photoreal tiles in view have finished loading; the geometry
* part, which reads the scene, answers.
* @returns {boolean}
*/
function projectionTilesReady() {
if (
!layerState._activeTileset ||
layerState._activeTileset.isDestroyed?.()
) {
layerState._activeTileset = null;
const primitives = layerState._viewer?.scene?.primitives;
if (primitives && typeof primitives.get === 'function') {
for (let i = 0; i < primitives.length; i++) {
const p = primitives.get(i);
if (p instanceof Cesium.Cesium3DTileset && !p.isDestroyed?.()) {
layerState._activeTileset = p;
break;
}
}
}
}
if (!layerState._activeTileset) return true;
if (layerState._activeTileset.show === false) return false;
return layerState._activeTileset.tilesLoaded === true;
return parts.geometry.projectionTilesReady();
}
/**
@@ -405,30 +377,17 @@ export function createModel({ state: layerState, services, parts, source }) {
* frame-up, so the 16:9 texture maps upright and unmirrored. Static geometry —
* computed only on slider/save/activation, never per frame (§2b).
* @param {Object} camera - Camera pose.
* @param {Cesium.Cartesian3} capCenterPos - Plane center in ECEF.
* @returns {Cesium.Quaternion}
* @param {{x: number, y: number, z: number}} capCenterPos - Plane center in ECEF.
* @returns {{x: number, y: number, z: number, w: number}} The quaternion.
*/
function planeOrientationFor(camera, capCenterPos) {
const frame = parts.geometry.frustumFrameEcef(camera, capCenterPos);
const right = Cesium.Cartesian3.cross(
frame.dir,
frame.up,
new Cesium.Cartesian3(),
);
const normal = Cesium.Cartesian3.negate(frame.dir, new Cesium.Cartesian3());
const m = new Cesium.Matrix3(
right.x,
frame.up.x,
normal.x,
right.y,
frame.up.y,
normal.y,
right.z,
frame.up.z,
normal.z,
);
return Cesium.Quaternion.fromRotationMatrix(m);
return fromAxes({
x: cross(frame.dir, frame.up),
y: frame.up,
z: negate(frame.dir),
});
}
/**
+13 -24
View File
@@ -1,7 +1,7 @@
export { ACTIVE_FRAME_REFRESH_MS } from './sourcePolicy.js';
import * as Cesium from 'cesium';
import { CCTV_CARD_FETCH_BURST_SPACING_MS } from '../../data/cctvCards.js';
import { CCTV_AMBIENT_CARD_MAX } from '../../data/cctvLod.js';
import { hexColor } from '../../render/color.js';
// ---------------------------------------------------------------------------
// API endpoints
@@ -434,44 +434,33 @@ export const CAMERA_SEEDS = [
];
// ---------------------------------------------------------------------------
// Visual style constants
// Visual style constants: renderer colours, [r, g, b, a] in 0..1
// ---------------------------------------------------------------------------
export const IDLE_CAMERA_COLOR =
Cesium.Color.fromCssColorString('#6be8ff').withAlpha(0.88);
export const IDLE_CAMERA_COLOR = hexColor('#6be8ff', 0.88);
export const ACTIVE_CAMERA_COLOR =
Cesium.Color.fromCssColorString('#ffd97a').withAlpha(0.95);
export const ACTIVE_CAMERA_COLOR = hexColor('#ffd97a', 0.95);
export const LIVE_CAMERA_COLOR =
Cesium.Color.fromCssColorString('#b48cff').withAlpha(0.88);
export const LIVE_CAMERA_COLOR = hexColor('#b48cff', 0.88);
export const IDLE_COVERAGE_COLOR =
Cesium.Color.fromCssColorString('#2fe0ff').withAlpha(0.24);
export const IDLE_COVERAGE_COLOR = hexColor('#2fe0ff', 0.24);
export const IDLE_COVERAGE_CENTER_MUTED =
Cesium.Color.fromCssColorString('#2fe0ff').withAlpha(0.2);
export const IDLE_COVERAGE_CENTER_MUTED = hexColor('#2fe0ff', 0.2);
export const IDLE_COVERAGE_EDGE_MUTED =
Cesium.Color.fromCssColorString('#2fe0ff').withAlpha(0.18);
export const IDLE_COVERAGE_EDGE_MUTED = hexColor('#2fe0ff', 0.18);
export const ACTIVE_COVERAGE_EDGE =
Cesium.Color.fromCssColorString('#8dff87').withAlpha(0.58);
export const ACTIVE_COVERAGE_EDGE = hexColor('#8dff87', 0.58);
export const ACTIVE_COVERAGE_CENTER =
Cesium.Color.fromCssColorString('#d7ff8d').withAlpha(0.82);
export const ACTIVE_COVERAGE_CENTER = hexColor('#d7ff8d', 0.82);
// H6: dimmer depth-fail materials let the active frustum wireframe read
// through buildings while in monitor fallback mode.
export const ACTIVE_COVERAGE_EDGE_DEPTHFAIL =
Cesium.Color.fromCssColorString('#8dff87').withAlpha(0.18);
export const ACTIVE_COVERAGE_EDGE_DEPTHFAIL = hexColor('#8dff87', 0.18);
export const ACTIVE_COVERAGE_CENTER_DEPTHFAIL =
Cesium.Color.fromCssColorString('#d7ff8d').withAlpha(0.26);
export const ACTIVE_COVERAGE_CENTER_DEPTHFAIL = hexColor('#d7ff8d', 0.26);
export const PLANE_OUTLINE_COLOR =
Cesium.Color.fromCssColorString('#6be8ff').withAlpha(0.55);
export const PLANE_OUTLINE_COLOR = hexColor('#6be8ff', 0.55);
/**
* Card budget while the staggered geometry drain is running — the raised
+18 -6
View File
@@ -3,11 +3,14 @@ import * as Cesium from 'cesium';
import {
CCTV_PROJECTION_OVERLAY_SOURCE_ID,
CCTV_PROJECTION_OVERLAY_SOURCE_OPTIONS,
PLANE_OUTLINE_COLOR,
PLANE_OUTLINE_COLOR as PLANE_OUTLINE_RGBA,
PROJECTION_CANVAS_WIDTH,
PROJECTION_CANVAS_HEIGHT,
} from './policy.js';
import { cctvPicks } from './pickState.js';
import { toColor } from '../../render/cesium/draw.js';
const PLANE_OUTLINE_COLOR = toColor(PLANE_OUTLINE_RGBA);
export function createProjection({
state: layerState,
@@ -17,6 +20,12 @@ export function createProjection({
}) {
const { holdContinuousRender, releaseContinuousRender } = services.render;
/** The monitor plane's orientation, as the Cesium quaternion its entity takes. */
function planeOrientation(camera, capCenter) {
const q = parts.model.planeOrientationFor(camera, capCenter);
return new Cesium.Quaternion(q.x, q.y, q.z, q.w);
}
/**
* Build the protected label associated with one active monitor plane.
* @param {{cameraId: string, name: string, position: Cesium.Cartesian3|Function}} input
@@ -67,7 +76,7 @@ export function createProjection({
const positions =
record.frustumPositions || parts.geometry.frustumCartesians(geometry);
runtime.planeEntity.position = positions.capCenter;
runtime.planeEntity.orientation = parts.model.planeOrientationFor(
runtime.planeEntity.orientation = planeOrientation(
record.camera,
positions.capCenter,
);
@@ -122,6 +131,11 @@ export function createProjection({
}
}
/** A plain white plane material, for a plane with no media (tests). */
function plainPlaneMaterial() {
return new Cesium.ColorMaterialProperty(Cesium.Color.WHITE);
}
/** Create the native monitor plane plus its cached host-label presentation. */
function createProjectionPlane(record, runtime, geometry, positions) {
@@ -137,10 +151,7 @@ export function createProjection({
id: `cctv-${record.camera.id}-plane`,
show: false,
position: positions.capCenter,
orientation: parts.model.planeOrientationFor(
record.camera,
positions.capCenter,
),
orientation: planeOrientation(record.camera, positions.capCenter),
plane: {
plane: new Cesium.Plane(Cesium.Cartesian3.UNIT_Z, 0.0),
dimensions: new Cesium.Cartesian2(
@@ -428,6 +439,7 @@ export function createProjection({
updatePlanePlacement,
clearProjectionOverlay,
setPlaneVisible,
plainPlaneMaterial,
createProjectionPlane,
createProjectionRuntime,
ensureProjectionRuntime,
+25 -9
View File
@@ -1,16 +1,16 @@
import * as Cesium from 'cesium';
import { isHeadingEstimated } from './headingConfidence.js';
import {
ACTIVE_CAMERA_COLOR,
ACTIVE_CAMERA_COLOR as ACTIVE_CAMERA_RGBA,
CAMERA_ICON,
IDLE_CAMERA_COLOR,
LIVE_CAMERA_COLOR,
ACTIVE_COVERAGE_CENTER,
IDLE_COVERAGE_CENTER_MUTED,
ACTIVE_COVERAGE_CENTER_DEPTHFAIL,
ACTIVE_COVERAGE_EDGE,
IDLE_COVERAGE_EDGE_MUTED,
ACTIVE_COVERAGE_EDGE_DEPTHFAIL,
IDLE_CAMERA_COLOR as IDLE_CAMERA_RGBA,
LIVE_CAMERA_COLOR as LIVE_CAMERA_RGBA,
ACTIVE_COVERAGE_CENTER as ACTIVE_COVERAGE_CENTER_RGBA,
IDLE_COVERAGE_CENTER_MUTED as IDLE_COVERAGE_CENTER_MUTED_RGBA,
ACTIVE_COVERAGE_CENTER_DEPTHFAIL as ACTIVE_COVERAGE_CENTER_DEPTHFAIL_RGBA,
ACTIVE_COVERAGE_EDGE as ACTIVE_COVERAGE_EDGE_RGBA,
IDLE_COVERAGE_EDGE_MUTED as IDLE_COVERAGE_EDGE_MUTED_RGBA,
ACTIVE_COVERAGE_EDGE_DEPTHFAIL as ACTIVE_COVERAGE_EDGE_DEPTHFAIL_RGBA,
VIEW_CELL_PX,
VIEW_ICON_MARGIN,
VIEW_MIN_CELL_M,
@@ -19,6 +19,22 @@ import { createIconSet } from '../../data/iconSet.js';
import { writeHoldSegment } from '../../data/iconSegment.js';
import { IconSetPrimitive } from '../../data/iconSetPrimitive.js';
import { iconAtlas } from '../../data/iconAtlas.js';
import { toColor } from '../../render/cesium/draw.js';
// The policy's renderer colours as the Cesium colours the icons and lines take.
const ACTIVE_CAMERA_COLOR = toColor(ACTIVE_CAMERA_RGBA);
const IDLE_CAMERA_COLOR = toColor(IDLE_CAMERA_RGBA);
const LIVE_CAMERA_COLOR = toColor(LIVE_CAMERA_RGBA);
const ACTIVE_COVERAGE_CENTER = toColor(ACTIVE_COVERAGE_CENTER_RGBA);
const IDLE_COVERAGE_CENTER_MUTED = toColor(IDLE_COVERAGE_CENTER_MUTED_RGBA);
const ACTIVE_COVERAGE_CENTER_DEPTHFAIL = toColor(
ACTIVE_COVERAGE_CENTER_DEPTHFAIL_RGBA,
);
const ACTIVE_COVERAGE_EDGE = toColor(ACTIVE_COVERAGE_EDGE_RGBA);
const IDLE_COVERAGE_EDGE_MUTED = toColor(IDLE_COVERAGE_EDGE_MUTED_RGBA);
const ACTIVE_COVERAGE_EDGE_DEPTHFAIL = toColor(
ACTIVE_COVERAGE_EDGE_DEPTHFAIL_RGBA,
);
/** The camera icon's drawn size (px). */
const CAMERA_ICON_PX = 24;
+1 -1
View File
@@ -24,7 +24,7 @@ function assertKeepsColor(icons, id, base, label) {
[actual.red, actual.green, actual.blue, actual.alpha].map(
Cesium.Color.floatToByte,
),
[base.red, base.green, base.blue, base.alpha].map(Cesium.Color.floatToByte),
base.map(Cesium.Color.floatToByte),
`${label}: base color kept`,
);
assert.equal(icons.focus(row), FOCUS_FACTOR, `${label}: focus`);
+1 -2
View File
@@ -1,5 +1,4 @@
import { isTrackingClickGesture } from '../../data/trackingClickGesture.js';
import * as Cesium from 'cesium';
import { cctvPicks } from './pickState.js';
export function createSelection({
@@ -199,7 +198,7 @@ export function createSelection({
}
/**
* Extracts a camera ID from a Cesium pick result by checking icon row IDs,
* Extracts a camera ID from a scene pick result by checking icon row IDs,
* primitive IDs, and the camera ids the layer keeps for its coverage entities.
* @param {Object|null} picked - Result from scene.pick().
* @returns {string|null} Camera ID, or null if the pick is not a CCTV entity.
+5 -5
View File
@@ -1,5 +1,3 @@
import * as Cesium from 'cesium';
export function createState({ services }) {
const {
clearOverlaySource,
@@ -76,11 +74,13 @@ export function createState({ services }) {
layerState._activeFocusStyleCount = 0;
layerState._scratchFocusScreen = new Cesium.Cartesian2();
// Screen-point scratches: the projections that fill them write only x and y.
layerState._scratchFocusScreen = { x: 0, y: 0 };
layerState._scratchViewScreen = new Cesium.Cartesian2();
layerState._scratchViewScreen = { x: 0, y: 0 };
layerState._scratchViewProjection = new Cesium.Matrix4();
/** The view pass's view-projection matrix, column-major. */
layerState._scratchViewProjection = new Float64Array(16);
// Counts view passes; a record shown by the latest pass carries its number.
+3 -3
View File
@@ -1,4 +1,3 @@
import * as Cesium from 'cesium';
import { createIconSet } from '../../data/iconSet.js';
export function createTesting({ state: layerState, services, parts, source }) {
@@ -41,9 +40,10 @@ export function createTesting({ state: layerState, services, parts, source }) {
const runtime = {
cameraId: String(record.camera.id),
planeEntity: null,
labelPosition: new Cesium.Cartesian3(),
// createProjectionPlane gives it its label position.
labelPosition: null,
overlayEntry: null,
planeMaterial: new Cesium.ColorMaterialProperty(Cesium.Color.WHITE),
planeMaterial: parts.projection.plainPlaneMaterial(),
};
parts.projection.createProjectionPlane(
record,
-6
View File
@@ -43,16 +43,10 @@
"src/layers/cctv/cards.js",
"src/layers/cctv/geometry.js",
"src/layers/cctv/geometryQueue.js",
"src/layers/cctv/ground.js",
"src/layers/cctv/lifecycle.js",
"src/layers/cctv/model.js",
"src/layers/cctv/navigation.js",
"src/layers/cctv/policy.js",
"src/layers/cctv/projection.js",
"src/layers/cctv/rendering.js",
"src/layers/cctv/selection.js",
"src/layers/cctv/state.js",
"src/layers/cctv/testing.js",
"src/layers/directions/index.js",
"src/layers/firms/rendering.js",
"src/layers/flights/controller.js",