Move the bikeshare layer onto the renderer's draw and camera ports

Station dots and the selected-station highlight are now two point draw
sets, picked through the draw hit, and the layer follows the camera
through the camera port at its own threshold instead of the shared
percentageChanged ledger. Altitude and view centre come from the camera
pose and view rectangle. All five bikeshare files leave the Cesium
allow-list.

The Cesium draw port now keeps a rebuilt host in its place in the scene
instead of re-adding it on top, tags hosts with their set id so sprite
order can raise a draw set (registerSpriteSet), and restyles unclamped
points in place when they have not moved, so a status poll or selection
no longer rebuilds every station. Other draw-port layers (cyclone
markers, earthquake discs) now also keep their first-build slot rather
than jumping above the sprite layers on each rebuild.
This commit is contained in:
Sameh Khamis committed 2026-11-06 20:26:35 -08:00
1 parent 2b66c46a30
commit 8c6fa6258b
22 files changed
+732 -249

No files matched your search

+25 -15
View File
@@ -1,6 +1,7 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import { fromDegrees } from '../geo/ellipsoid.js';
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
import {
BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS,
_clearBikeshareSelectionForTest,
@@ -19,17 +20,17 @@ function makeRecord() {
isInstalled: true,
isRenting: false,
isReturning: true,
point: {
position: Cesium.Cartesian3.fromDegrees(-97.7431, 30.2672, 2),
show: true,
},
key: 'austin-capmetro:3790',
position: fromDegrees(-97.7431, 30.2672, 2),
pixelSize: 8,
color: [0, 1, 0, 1],
};
}
test('selected bikeshare entry preserves source copy and protected-lane policy', () => {
const record = makeRecord();
const entry = createBikeshareSelectedOverlayEntry('austin-capmetro:3790', record);
assert.equal(entry.position, record.point.position);
assert.equal(entry.position, record.position);
assert.equal(entry.title, 'Congress & 6th');
assert.deepEqual(entry.details, [
'🚲 7 avail · 4 docks · 11 cap',
@@ -44,7 +45,7 @@ test('selected bikeshare entry preserves source copy and protected-lane policy',
assert.equal(entry.horizonCull, true);
});
test('real station select/clear path publishes one card and creates no native label graphic', () => {
test('real station select/clear path publishes one card and draws no native label', () => {
const calls = [];
const overlayHost = {
setEntries: (...args) => calls.push(['entries', ...args]),
@@ -53,27 +54,36 @@ test('real station select/clear path publishes one card and creates no native la
};
const key = 'austin-capmetro:3790';
const record = makeRecord();
const viewer = { entities: new Cesium.EntityCollection() };
const viewer = {};
const { draw, unbind } = bindFakeDraw(viewer);
_setBikeshareSelectionStateForTest({ viewer, key, record, overlayHost });
const live = (suffix) =>
[...draw.sets.values()].find((set) => !set.disposed && set.spec.id.endsWith(suffix));
const stations = live(':stations');
const selected = live(':selected');
try {
_selectBikeshareStationForTest(key);
assert.equal(record.point.show, false);
assert.equal(viewer.entities.values.length, 1, 'runtime guard requires a real selected entity');
assert.equal(viewer.entities.values[0].label, undefined);
assert.ok(viewer.entities.values[0].point, 'selected point highlight remains native');
assert.equal(stations.items.get(key).show, false, 'the station’s own dot is hidden');
assert.equal(selected.items.size, 1, 'one highlight dot replaces it');
const [highlight] = selected.items.values();
assert.equal(highlight.pos, record.position);
assert.deepEqual(highlight.color, [0, 1, 1, 1], 'cyan');
assert.equal(highlight.pixelSize, 14);
assert.equal(highlight.disableDepthTest, Infinity);
const publication = calls.find(([type]) => type === 'entries');
assert.ok(publication);
assert.equal(publication[1], 'bikeshare-selected');
assert.equal(publication[2].length, 1);
assert.equal(publication[2][0].position, record.point.position);
assert.equal(publication[2][0].position, record.position);
assert.deepEqual(publication[3], BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS);
_clearBikeshareSelectionForTest();
assert.equal(record.point.show, true);
assert.equal(viewer.entities.values.length, 0);
assert.equal(stations.items.get(key).show, true);
assert.equal(selected.items.size, 0);
assert.deepEqual(calls.at(-1), ['clear', 'bikeshare-selected']);
} finally {
_clearBikeshareSelectionForTest();
unbind();
}
});
+5 -3
View File
@@ -4,9 +4,11 @@
*
* `camera.changed` fires once the view has moved by this fraction, and it is a
* single number on the camera that every listener in the app shares. Several
* layers want it finer than the default — traffic, bikeshare and transit all
* ask for 0.05 so they notice they have entered a coverage area — and each of
* them used to write the number directly and hand back whatever it remembered.
* layers want it finer than the default — traffic and transit ask for 0.05 so
* they notice they have entered a coverage area (bikeshare did too, before it
* listened through the renderer's camera port at its own threshold) — and
* each of them used to write the number directly and hand back whatever it
* remembered.
*
* That cannot work, because a number is not an owner. Two layers asking for the
* same 0.05 write the same value, so when the first one leaves it sees its own
+30 -1
View File
@@ -25,6 +25,35 @@ export function registerSpriteCollection(layerId, collection) {
_collections.set(layerId, collection);
}
/**
* Register a renderer draw set for a sprite layer, by its set id. The
* default renderer names each set's host primitive with `drawSetId`; the
* restorer raises the host it finds under that name, whichever host the
* set draws with now.
* @param {string} layerId - Stable sprite-order layer key.
* @param {string} setId - The draw set's id.
* @returns {object} The registration, for `unregisterSpriteCollection`'s guard.
*/
export function registerSpriteSet(layerId, setId) {
const entry = Object.freeze({ drawSetId: setId });
if (layerId && typeof setId === 'string') _collections.set(layerId, entry);
return entry;
}
/**
* The primitive `entry` names: itself, or a draw set's host found by its id.
* The topmost match wins, so a host still retiring below its replacement is
* skipped.
*/
function resolveSprite(primitives, entry) {
if (typeof entry?.drawSetId !== 'string') return entry;
for (let i = (primitives.length ?? 0) - 1; i >= 0; i--) {
const primitive = primitives.get(i);
if (primitive?.drawSetId === entry.drawSetId) return primitive;
}
return null;
}
/**
* Remove a registered collection (primarily useful to lifecycle tests).
* @param {string} layerId - Stable sprite-order layer key.
@@ -51,7 +80,7 @@ export function restoreSpriteOrder(viewer) {
return;
for (const layerId of SPRITE_LAYER_ORDER) {
const collection = _collections.get(layerId);
const collection = resolveSprite(primitives, _collections.get(layerId));
if (!collection || collection.isDestroyed?.()) continue;
if (primitives.contains?.(collection) === false) continue;
primitives.raiseToTop(collection);