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

+66 -2
View File
@@ -8,7 +8,9 @@
* scene's `sampleHeight` where `sampleHeightSupported`), `project`
* (`SceneTransforms.worldToWindowCoordinates`, which a test may mock),
* `pickPosition` (the scene's), and null for every other pick.
* - globe: `isGlobeVisible` from `globe.show`.
* - globe: `isGlobeVisible` from `globe.show`; `isSettled('surface')` and
* `surfaceVersion` as the Cesium port reads them, off the double's globe
* and its primitives that say whether their tiles have loaded.
* - camera (`withCamera`): `pose().position` from `camera.positionCartographic`,
* `matrices()` from `camera.viewMatrix` and `frustum.projectionMatrix`
* (undefined without them).
@@ -22,6 +24,64 @@ import { fakeDrawPort } from './fakeDrawPort.mjs';
const carto = ({ lon, lat }) => Cesium.Cartographic.fromDegrees(lon, lat);
const ecef = (p) => (p ? { x: p.x, y: p.y, z: p.z } : null);
/**
* The double's tilesets: its shown primitives that say whether their tiles
* have loaded.
*/
function* shownTilesets(s) {
const primitives = s.primitives;
for (let i = 0; i < (primitives?.length || 0); i++) {
const primitive = primitives.get(i);
if (
primitive?.show &&
!primitive.isDestroyed?.() &&
typeof primitive.tilesLoaded === 'boolean'
)
yield primitive;
}
}
/** `isSettled('surface')` as the Cesium globe port answers it. */
function surfaceLoaded(s) {
if (s.globe?.show) return s.globe.tilesLoaded !== false;
let found = false;
for (const tileset of shownTilesets(s)) {
found = true;
if (!tileset.tilesLoaded) return false;
}
return found;
}
// `surfaceVersion` as the Cesium globe port keeps it: bumped when the globe
// is shown or hidden, its terrain swapped, or the set of shown tilesets
// changes (whether or not the globe is shown).
const versions = new WeakMap();
let lastVersion = 0;
function surfaceVersion(s) {
let seen = versions.get(s);
if (!seen) {
seen = { globe: null, terrain: null, tiles: new Set(), version: 0 };
versions.set(s, seen);
}
const globe = Boolean(s.globe?.show);
const terrain = s.globe?.terrainProvider ?? null;
let changed =
seen.version === 0 || seen.globe !== globe || seen.terrain !== terrain;
let count = 0;
for (const tileset of shownTilesets(s)) {
count++;
if (!seen.tiles.has(tileset)) changed = true;
}
if (count !== seen.tiles.size) changed = true;
if (changed) {
seen.globe = globe;
seen.terrain = terrain;
seen.tiles = new Set(shownTilesets(s));
seen.version = ++lastVersion;
}
return seen.version;
}
/** The surface ports over `viewer.scene`. */
export function sceneSurfacePorts(viewer, { withCamera = false } = {}) {
const scene = () => viewer.scene ?? {};
@@ -55,7 +115,11 @@ export function sceneSurfacePorts(viewer, { withCamera = false } = {}) {
};
const ports = {
query,
globe: { isGlobeVisible: () => Boolean(scene().globe?.show) },
globe: {
isGlobeVisible: () => Boolean(scene().globe?.show),
isSettled: (kind) => kind !== 'surface' || surfaceLoaded(scene()),
surfaceVersion: () => surfaceVersion(scene()),
},
frame: {
on(phase, cb) {
const event = phase === 'postRender' ? scene().postRender : null;