Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

Settle pending Traffic height work when the population empties

Said Turksever090eeb9b115e
diff --git a/changelog.d/1281-traffic-issue-fix.md b/changelog.d/1281-traffic-issue-fix.md
index f9477de48..3ce673038 100644
--- a/changelog.d/1281-traffic-issue-fix.md
+++ b/changelog.d/1281-traffic-issue-fix.md
@@ -5,3 +5,4 @@
- Isolate the Traffic keyless browser scenario from the keyed page’s workers and intercepted cache (asturksever, #1281).
- Restore minimized test windows before screenshots so native compositor pauses cannot stall browser acceptance (asturksever, #1281).
- Intercept only Traffic provider URLs, leaving Cesium worker and module loading untouched (asturksever, #1281).
+- Settle an unfinished Traffic height correction when the last animated point leaves, so the layer stops reporting loading once its render hold is released (asturksever, #1281).
diff --git a/src/layers/traffic/animation.js b/src/layers/traffic/animation.js
index 4d9f6c4b3..6c58a57a4 100644
--- a/src/layers/traffic/animation.js
+++ b/src/layers/traffic/animation.js
@@ -25,6 +25,9 @@ export function createAnimation({
layerState._enabled &&
(layerState._dots.length || layerState._heatJamPrim),
);
+ // Height easing only runs in a held frame. Settle it before releasing, so
+ // a population emptied mid-correction cannot report loading forever.
+ if (!needed && layerState._heightPending) parts.retention.finishHeights();
if (needed === Boolean(layerState._renderHeld)) return;
layerState._renderHeld = needed;
if (needed) {
diff --git a/src/layers/traffic/motion.test.mjs b/src/layers/traffic/motion.test.mjs
index 6338eb10f..ef60e478f 100644
--- a/src/layers/traffic/motion.test.mjs
+++ b/src/layers/traffic/motion.test.mjs
@@ -565,6 +565,37 @@ test('provisional opposite-direction heights cannot overwrite a measured sibling
assert.notEqual(forward.waypoints, reverse.waypoints);
});
+test('a closure that empties the population mid-correction settles heights and clears loading before release', (t) => {
+ const h = setup(t);
+ h.parts.retention.reconcile(h.roads(), 450, true);
+ h.settle();
+ assert.equal(h.state._renderHeld, true);
+ const road = h.state._roads[0];
+ // Republishing the sole road starts a height correction.
+ const corrected = h.roads(0, 120);
+ h.parts.retention.reconcile(corrected, 450, true);
+ assert.equal(h.state._heightPending, true);
+ assert.equal(road.heightMoving, true);
+ // The closure arrives before the next population pass, which then removes
+ // the final points after their fade, long before the correction finishes.
+ corrected[0].flow = { level: 0, closure: true };
+ for (let i = 0; i < 20 && h.state._dots.length; i++) h.frame();
+ assert.equal(h.state._dots.length, 0);
+ assert.equal(h.state._heatJamPrim, null);
+ assert.equal(h.state._renderHeld, false);
+ assert.equal(h.state._heightPending, false);
+ assert.equal(h.state._populationPending, false);
+ assert.equal(road.heightMoving, false);
+ assert.ok(
+ Math.abs(C.Cartographic.fromCartesian(road.waypoints[0]).height - 120) <
+ 0.01,
+ );
+ // Frames driven by other layers stay idle and cannot revive the work.
+ h.frame();
+ assert.equal(h.state._heightPending, false);
+ assert.equal(h.state._renderHeld, false);
+});
+
test('large height corrections obey a screen-pixel bound and reuse projection scratch objects', (t) => {
const h = setup(t);
h.state._viewer.scene = {
diff --git a/src/layers/traffic/retention.js b/src/layers/traffic/retention.js
index ec0762b5c..a987f64b0 100644
--- a/src/layers/traffic/retention.js
+++ b/src/layers/traffic/retention.js
@@ -242,6 +242,29 @@ export function createRetention({ state, parts }) {
road.heightMoving = moving;
}
}
+ /**
+ * Settle every retained road on its corrected heights at once. Easing only
+ * runs inside the held animation frame, so once nothing is left to animate
+ * the remaining correction would otherwise stay pending indefinitely.
+ * Published roads whose record was just dropped are settled too, so a later
+ * held frame cannot revive their correction.
+ */
+ function finishHeights() {
+ const roads = new Set(state._roads);
+ for (const record of records.values()) roads.add(record.road);
+ for (const road of roads) {
+ if (!road.heightMoving) continue;
+ for (let i = 0; i < road.waypoints.length; i++)
+ Cesium.Cartesian3.clone(road.targetWaypoints[i], road.waypoints[i]);
+ for (let i = 0; i < road.segmentDist.length; i++)
+ road.segmentDist[i] = Cesium.Cartesian3.distance(
+ road.waypoints[i],
+ road.waypoints[i + 1],
+ );
+ road.heightMoving = false;
+ }
+ state._heightPending = false;
+ }
function clear() {
if (timer !== null) {
if (typeof cancelAnimationFrame === 'function')
@@ -253,5 +276,5 @@ export function createRetention({ state, parts }) {
state._populationPending = false;
state._heightPending = false;
}
- return { reconcile, easeHeights, clear, refreshCounts };
+ return { reconcile, easeHeights, finishHeights, clear, refreshCounts };
}