Compute street traffic roads, colours and state without Cesium

Road waypoints are plain ECEF points from the geo helpers (the same
formulas as before, so every waypoint and segment length is unchanged), and
the palette is renderer colours. The style part, still on the point
primitives, turns those into the points' colours once per colour and owns
the dot painting the model used to do itself; the rendering part converts
them for the heat lines. The animation keeps its own lerp scratch, and the
ingestion's centre height asks with plain degrees.

Ingestion, model, policy, state and timing leave the allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-07 00:09:10 -08:00
1 parent d6f09f9860
commit 10db177251
15 files changed
+247 -73

No files matched your search

+10 -22
View File
@@ -1,4 +1,5 @@
import * as Cesium from 'cesium';
import { fromDegrees } from '../../geo/ellipsoid.js';
import { distance } from '../../geo/vector.js';
import { roadSurfaceChunks } from './surface.js';
import { t, translateKnown } from '../../i18n/index.js';
import {
@@ -6,11 +7,7 @@ import {
flowBucket,
flowSpeedScale,
} from '../../data/trafficFlowStyle.js';
import {
DOT_HEIGHT_OFFSET,
DENSITY_MULT,
JAM_DOT_FAR_SCALE,
} from './policy.js';
import { DOT_HEIGHT_OFFSET, DENSITY_MULT } from './policy.js';
export function createModel({ state: layerState, services, parts, source }) {
/** Build scene waypoints from source records; thinning and terrain remain rendering policy. */
@@ -26,22 +23,20 @@ export function createModel({ state: layerState, services, parts, source }) {
for (const coords of roadSurfaceChunks(road.coordinates)) {
const type = road.type;
const oneway = road.oneway;
// Pre-compute Cartesian3 waypoints (lon, lat, height) for fast lerp animation
// Pre-compute ECEF waypoints (lon, lat, height) for fast lerp animation
const waypoints = coords.map(([lng, lat]) => {
const floor = services.ground?.cachedGroundFloor?.(lat, lng);
const h =
(Number.isFinite(floor) && Math.abs(floor) <= 9000
? floor
: layerState._viewHeightEstimate || 0) + DOT_HEIGHT_OFFSET;
return Cesium.Cartesian3.fromDegrees(lng, lat, h);
return fromDegrees(lng, lat, h);
});
// Pre-compute segment distances in meters for speed-to-t conversion
const segmentDist = [];
for (let i = 0; i < waypoints.length - 1; i++) {
segmentDist.push(
Cesium.Cartesian3.distance(waypoints[i], waypoints[i + 1]),
);
segmentDist.push(distance(waypoints[i], waypoints[i + 1]));
}
for (const direction of oneway ? [oneway] : [1, -1])
@@ -357,17 +352,15 @@ export function createModel({ state: layerState, services, parts, source }) {
const flow = dot.road?.source ? dot.road.source.flow : dot.road?.flow;
dot.road.flow = flow;
if (flow?.closure || (!flow && layerState._uncoveredMode === 'hide')) {
dot.point.show = false;
parts.style.showDot(dot, false);
dot.mps = 0;
closedDots += 1;
continue;
}
dot.point.show = true;
parts.style.showDot(dot, true);
const bucket = flow ? flowBucket(flow.level) : null;
dot.bucket = bucket;
dot.point.color = bucket
? layerState._activeBucketColors[bucket]
: Cesium.Color.WHITE.withAlpha(0.85);
parts.style.paintDot(dot, bucket);
dot.nominalSize =
parts.style.baseDotSize(dot.road?.type, bucket) +
(bucket === 'jam' ? 1 : 0) +
@@ -386,12 +379,7 @@ export function createModel({ state: layerState, services, parts, source }) {
moving: Math.random() < 0.4,
until: now + Math.random() * 2000,
};
dot.point.scaleByDistance = new Cesium.NearFarScalar(
100,
1.5,
layerState._fadeScaleFar,
JAM_DOT_FAR_SCALE,
);
parts.style.emphasizeJamDot(dot);
} else {
dot.creep = null;
}