Traffic surface keys and readiness through the globe port; draped lines fall back to overlay where the scene cannot drape

The traffic layer keys its cached road heights by the globe port's
surfaceVersion() and waits on isSettled('surface') instead of reading the
scene through render/cesium/surfaceState.js, which is gone. Heat-lines are
always asked for draped; the layer no longer checks whether the scene can
drape and drops them. The traffic layer and application/sources no longer
reach Cesium, and src/layers/traffic/rendering.js leaves the Cesium list.

Where the Cesium renderer cannot drape (no depth textures), its draw port
now draws every draped line over the surface, as the contract asks: along
the surface's curve between its positions, in its colour where the surface
hides it, hidden past the horizon (tested along its arc, shown in 2D). A
segmented line runs from its first shown segment to its last, in its style
colour. A line whose positions hold what they held takes a new colour in
place, so pulsing jam lines build nothing per frame; one that moves is
built anew alone.
This commit is contained in:
Sameh Khamis committed 2026-11-09 03:10:29 -08:00
1 parent f53f691a80
commit 26633106fc
15 files changed
+543 -169

No files matched your search

+5 -16
View File
@@ -22,12 +22,7 @@ const road = (level, length = 100, x = 0) => ({
],
});
function setup({
live = true,
heatline = true,
preset = 'normal',
supported = true,
} = {}) {
function setup({ live = true, heatline = true, preset = 'normal' } = {}) {
const draw = fakeDrawPort();
const demand = [];
const state = {
@@ -37,7 +32,6 @@ function setup({
_stylePreset: preset,
_heatJam: [],
_heatLineCount: 0,
_heatSupported: supported,
_heatSet: draw.lines({ id: 'traffic:1:heat', clampTo: 'tiles' }),
};
const rendering = createRendering({
@@ -144,14 +138,9 @@ test('no heat-lines in simulation or with the mode off, and removal empties the
assert.equal(items().length, 0, 'nothing to pulse');
});
test('where lines cannot drape, no heat-lines are drawn and that is said once', (t) => {
const warn = t.mock.method(console, 'warn', () => {});
const { state, rendering, items } = setup({ supported: null });
state._viewer = { scene: {} };
test('heat-lines are asked for draped whatever the renderer, with no check of their own', () => {
const { rendering, items } = setup();
rendering.rebuildHeatLines([road(0.2)]);
rendering.rebuildHeatLines([road(0.2)]);
assert.equal(items().length, 0);
assert.equal(state._heatSupported, false);
assert.equal(warn.mock.callCount(), 1);
assert.equal(rendering.heatPulsing(), false);
assert.equal(items().length, 1);
assert.equal(items()[0].mode, 'draped');
});
+1 -1
View File
@@ -759,7 +759,7 @@ test('selection asks the query port for depth and screen positions, and the came
camera: {
pose: () => (poses++, { position: { x: eye.x, y: eye.y, z: eye.z } }),
},
globe: { isGlobeVisible: () => true },
globe: { isGlobeVisible: () => true, isSettled: () => true },
query: {
sampleHeightNow: () => 0,
pickPosition(x, y) {
+2 -27
View File
@@ -12,20 +12,6 @@ import {
} from './policy.js';
import { distance } from '../../geo/vector.js';
import { findCamera } from '../../render/rendererOf.js';
// The layer's other parts reach the renderer through the unbound camera
// factory (with its query port) and globe factory, loaded here with the
// adapter this file needs.
import '../../render/cesium/camera.js';
import '../../render/cesium/globe.js';
// What the dots' surface is, and whether it has loaded, the renderer
// contract cannot say: the Cesium adapter reads it off the scene.
import {
drapesLines,
surfaceTilesReady,
surfaceKey as trafficSurfaceKey,
} from '../../render/cesium/surfaceState.js';
export { surfaceTilesReady, trafficSurfaceKey };
export function createRendering({
state: layerState,
@@ -66,7 +52,8 @@ export function createRendering({
* on top. Lines of the layer's heat-line draw set, draped on the tiles;
* the jam lines pulse together (`pulseHeatLines`). Capped at
* HEAT_LINE_CAP (jam first, longest first); overflow is logged. No-op in
* sim mode, when the heatline mode is off, or where lines cannot drape.
* sim mode or when the heatline mode is off. A renderer that cannot drape
* draws them over the surface instead (the draw port's `overlay`).
*
* @param {Array} roads - Road objects visible in the current render.
*/
@@ -81,18 +68,6 @@ export function createRendering({
removeHeatLines();
return;
}
if (layerState._heatSupported === null) {
layerState._heatSupported = drapesLines(layerState._viewer);
if (!layerState._heatSupported)
console.warn(
'[Data:Traffic] Draped lines unsupported — heat-lines disabled',
);
}
if (!layerState._heatSupported) {
removeHeatLines();
return;
}
const candidates = [];
for (const road of roads) {
const flow = road.flow;
-4
View File
@@ -182,10 +182,6 @@ export function createState({ services }) {
layerState._heatLineCount = 0;
/** @type {boolean|null} Whether lines can drape here, checked once. */
layerState._heatSupported = null;
/** @type {number} Altitude of the last render, for late-flow heat rebuilds. */
layerState._lastRenderAltitude = 0;
+20 -2
View File
@@ -10,9 +10,27 @@ import {
findGlobe,
findQuery,
} from '../../render/rendererOf.js';
import { surfaceTilesReady, trafficSurfaceKey } from './rendering.js';
/**
* What heights are sampled against now: the globe port's surface identity,
* which changes when the base, terrain or photoreal route is swapped or the
* globe is shown or hidden, and never on camera moves or tile loads. A
* renderer without one (`surfaceIdentity`) names a single surface (0), so
* cached heights live as long as the layer's cache.
* @param {object|undefined} viewer
* @returns {number}
*/
export function trafficSurfaceKey(viewer) {
return findGlobe(viewer)?.surfaceVersion?.() ?? 0;
}
export { trafficSurfaceKey };
/**
* Whether the drawn surface has loaded what is in view: the globe's terrain
* while it is shown, otherwise the shown 3D tiles (false with neither).
* @param {object|undefined} viewer
*/
function surfaceTilesReady(viewer) {
return findGlobe(viewer)?.isSettled('surface') === true;
}
/** Whether the globe surface is drawn (else tiles alone are). */
const globeShown = (viewer) => findGlobe(viewer)?.isGlobeVisible?.() === true;
+1 -1
View File
@@ -346,7 +346,7 @@ test('rendered road depth is geographically checked, bounded, and avoids mesh re
);
});
test('surface keys reuse identity without building arrays or strings on unchanged frames', (t) => {
test('surface keys follow the globe port’s surface identity, building nothing on unchanged frames', (t) => {
const tiles = [
{ show: true, tilesLoaded: true },
{ show: true, tilesLoaded: false },