Draw the traffic dots through the draw port and read the road surface through renderer ports

The traffic layer's vehicle dots are now a points set on the draw port,
moved, added to and taken from in place each frame, instead of a Cesium
point collection. Road surface heights and readiness read the query,
camera, frame and globe ports and the heights service instead of the
scene; the surface identity and "any tileset drawn" checks, which the
contract cannot answer, move to rendering.js with the heat lines.

animation.js, style.js and surface.js leave the Cesium allow-list.

The Cesium draw port compares a moved point's look without allocating:
colours by index, and a frozen colour or curve of plain data by identity,
so a thousand dots moved every frame cost about what direct writes did.
The traffic QA scripts read the dots' draw items.
This commit is contained in:
Sameh Khamis committed 2026-11-07 23:16:11 -08:00
1 parent d9db5199ed
commit bbd6049e21
24 files changed
+872 -467

No files matched your search

+20 -14
View File
@@ -1,6 +1,6 @@
// src/layers/traffic/style.test.mjs — the traffic layer keeps its dot
// colours as renderer colours and paints them onto the points as the colours
// they always were.
// colours as renderer colours and paints them onto the points' items as the
// colours they always were.
import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
@@ -13,6 +13,9 @@ import {
import { presetDotRgba } from '../../data/trafficPresetStyle.js';
import { createState } from './state.js';
/** A renderer colour (`[r, g, b, a]`) as Cesium draws it. */
const asColor = (rgba) => new Cesium.Color(...rgba);
function style(preset = 'normal') {
const state = createState({ services: {} });
state._stylePreset = preset;
@@ -32,11 +35,14 @@ test('bucket colours are the shipped palette, painted as before', () => {
};
for (const bucket of ['free', 'slow', 'jam'])
assert.ok(
Cesium.Color.equals(s.dotColor(bucket), expected[bucket]),
Cesium.Color.equals(asColor(s.dotColor(bucket)), expected[bucket]),
bucket,
);
assert.ok(
Cesium.Color.equals(s.dotColor(null), Cesium.Color.WHITE.withAlpha(0.85)),
Cesium.Color.equals(
asColor(s.dotColor(null)),
Cesium.Color.WHITE.withAlpha(0.85),
),
);
assert.deepEqual(SIM_DOT_COLOR, [1, 1, 1, 0.85]);
assert.equal(s.dotColor('jam'), s.dotColor('jam'), 'one colour per bucket');
@@ -51,12 +57,12 @@ test('a dot is painted, shown and emphasised on its point', () => {
s.showDot(dot, false);
assert.equal(dot.point.show, false);
s.emphasizeJamDot(dot);
assert.ok(
Cesium.NearFarScalar.equals(
dot.point.scaleByDistance,
new Cesium.NearFarScalar(100, 1.5, 9000, JAM_DOT_FAR_SCALE),
),
);
assert.deepEqual(dot.point.scaleByDistance, {
near: 100,
nearValue: 1.5,
far: 9000,
farValue: JAM_DOT_FAR_SCALE,
});
});
test('a styled preset recolours the buckets', () => {
@@ -67,7 +73,7 @@ test('a styled preset recolours the buckets', () => {
const [r, g, b, a] = presetDotRgba('surveillance', 'jam');
assert.ok(
Cesium.Color.equals(
s.dotColor('jam'),
asColor(s.dotColor('jam')),
new Cesium.Color(r / 255, g / 255, b / 255, a),
),
);
@@ -84,9 +90,9 @@ test('switching presets and back repaints dots with the shipped colours', () =>
state._dots = [dot];
const shipped = Cesium.Color.fromCssColorString('#2ecc71').withAlpha(0.9);
parts.style.setStylePreset('surveillance');
assert.ok(!Cesium.Color.equals(dot.point.color, shipped));
assert.ok(Cesium.Color.equals(dot.point.color, parts.style.dotColor('free')));
assert.ok(!Cesium.Color.equals(asColor(dot.point.color), shipped));
assert.equal(dot.point.color, parts.style.dotColor('free'));
parts.style.setStylePreset('normal');
assert.ok(Cesium.Color.equals(dot.point.color, shipped));
assert.ok(Cesium.Color.equals(asColor(dot.point.color), shipped));
assert.deepEqual(state._activeBucketColors.free, FLOW_BUCKET_COLORS.free);
});