Merge main into fix/earthquake-click-details

Resolves conflicts with main: a world focus target's own range past its
framed radius replaces the kind's range (#1832), so a quake asks for its
own range only past M6 and the earthquake framing stays its floor; FIRMS
keeps main's marker stand-in under the card-on-top rule; launches keep
main's label click and also read the card on top through the pick
registry.
This commit is contained in:
Sameh Khamis committed 2026-11-18 18:58:07 -08:00
commit e87aa5190d
1337 files changed
+38638 -9950

No files matched your search

+27 -17
View File
@@ -83,13 +83,16 @@ export function createTransitCockpitSubject({ state, parts, services }) {
* lift: the drawn marker's height while the frame pass places it (in view,
* or held), which near the ground follows the terrain between reports;
* else its segment's two reports' floors at the playback fraction. Null
* while either floor is unknown, as on cold terrain, so a view waits for
* the surface. Not `entry.heightM`, the floor at the newest report, which
* playback has not reached yet.
* while either of those two floors is unknown, as on cold terrain, so a
* view waits for the surface. Not `entry.heightM`, the floor at the newest
* report, which playback has not reached yet.
*/
function drawnFloorOf(entry) {
const segment = entry.segment;
if (!segment || entry.heightPending) return null;
const from = segment.from?.h;
const to = segment.to?.h;
if (!Number.isFinite(from) || !Number.isFinite(to)) return null;
const placed =
entry.surfaceReady === true &&
entry.hasRendered &&
@@ -99,9 +102,6 @@ export function createTransitCockpitSubject({ state, parts, services }) {
const drawn = toCartographicRadians(entry.marker.position);
if (drawn) return drawn.height - liftM;
}
const from = segment.from?.h;
const to = segment.to?.h;
if (!Number.isFinite(from) || !Number.isFinite(to)) return null;
const f = Number.isFinite(segment.fraction)
? Math.max(0, Math.min(1, segment.fraction))
: 1;
@@ -173,16 +173,32 @@ export function createTransitCockpitSubject({ state, parts, services }) {
return snapshot;
}
/** Show or hide a vehicle's sprite and trail for the hold. */
/**
* Place a vehicle and show or hide its sprite and trail for the hold now:
* the icon set draws a marker as it was last pushed, not as it is.
*/
function repaint(entry) {
if (!entry?.marker) return;
if (entry.key === state._cockpitSubjectKey) entry.marker.show = false;
else parts.rendering.placeSample(entry);
parts.rendering.placeSample(entry);
parts.rendering.flushMarkers();
parts.rendering.schedulePlayback(entry);
parts.trails.update();
state._detectRevision += 1;
}
/**
* A vehicle let go of is out of play until a sweep finds it in view. It
* played on while held, so the next sweep keeps its clock if it finds it in
* view (rendering.js).
*/
function release(entry) {
if (!entry) return;
state._visible.delete(entry);
entry.releasedFromHold = true;
parts.rendering.requestVisibility();
repaint(entry);
}
const methods = {
/** The selected vehicle (see createTransitCockpitSubject), or null. */
getSelectedVehicle() {
@@ -202,13 +218,7 @@ export function createTransitCockpitSubject({ state, parts, services }) {
const previous = state._vehicles.get(state._cockpitSubjectKey);
if (key === null || key === undefined) {
state._cockpitSubjectKey = null;
// The hold kept it in play out of view: it leaves until the next
// visibility sweep finds it in view again.
if (previous) {
state._visible.delete(previous);
parts.rendering.requestVisibility();
}
repaint(previous);
release(previous);
parts.selection.refreshSelectedCard(true);
return true;
}
@@ -217,7 +227,7 @@ export function createTransitCockpitSubject({ state, parts, services }) {
if (state._selectedKey !== key) parts.selection.selectVehicle(key);
state._cockpitSubjectKey = key;
state._visible.add(entry);
if (previous && previous !== entry) repaint(previous);
if (previous !== entry) release(previous);
repaint(entry);
parts.selection.refreshSelectedCard(true);
return true;
+2
View File
@@ -165,6 +165,8 @@ export function createLifecycle({ state, services, parts }) {
state._visible.clear();
clearTimeout(state._cameraDebounceTimer);
state._cameraDebounceTimer = null;
// A hold ends with the layer (cockpitSubject.js).
state._cockpitSubjectKey = null;
parts.selection.clearSelection();
state._overlayHost.setVisible(TRANSIT_SELECTED_OVERLAY_SOURCE_ID, false);
parts.selection.removeClickHandler();
+250 -6
View File
@@ -958,27 +958,70 @@ test('disable aborts in-flight work and a response that lands late is ignored',
assert.equal(app.vehicles().length, 1);
});
test('a held vehicle with no floor yet tells its view no height', async (t) => {
// Not the ellipsoid: a first-person view waits for the surface instead.
const app = harness(t, { floorAt: () => undefined });
/**
* Serves one bus at `place.lat` (read on every poll), enables the layer, polls
* once and settles; returns its entry.
*/
async function oneBus(app, place = { lat: 42.36 }) {
app.serve('mbta', () => ({
status: 200,
body: snapshot(
'mbta',
'MBTA',
[vehicle('bus-1', 42.36, -71.06, Date.now() / 1000)],
[vehicle('bus-1', place.lat, -71.06, reported())],
{ fetchedAt: Date.now() },
),
}));
app.layer.enable(app.viewer);
await app.layer.update();
app.settle();
const entry = app.vehicles()[0];
return app.vehicles()[0];
}
test('a held vehicle with no floor yet tells its view no height', async (t) => {
// Not the ellipsoid: a first-person view waits for the surface instead.
const app = harness(t, { floorAt: () => undefined });
const entry = await oneBus(app);
assert.equal(entry.heightPending, true, 'it has nothing to stand on');
assert.ok(app.layer.setCockpitSubject(entry.key) !== false);
assert.equal(app.layer.getCockpitSubject().position.groundHeightM, null);
});
test('with the camera above the height gate, a held vehicle drawn on the ellipsoid tells its view no height', async (t) => {
const app = harness(t, { altitude: 100_000, floorAt: () => undefined });
const entry = await oneBus(app);
assert.ok(app.layer.setCockpitSubject(entry.key) !== false);
app.frame();
assert.equal(entry.surfaceReady, true, 'it is drawn');
const drawnM = Cesium.Cartographic.fromCartesian(
entry.marker.position,
).height;
assert.ok(Math.abs(drawnM) < 1e-3, `on the ellipsoid, got ${drawnM} m`);
assert.equal(app.layer.getCockpitSubject().position.groundHeightM, null);
});
test('with the camera above the height gate, a held vehicle with one floor unknown tells its view no height', async (t) => {
// Drawn between a floor its view could stand on and none.
for (const knownLat of [42.36, 42.361]) {
await t.test(`floor known at ${knownLat}`, async (t) => {
const app = harness(t, { altitude: 100_000, floorAt: () => undefined });
app.ground._warm.set(app.ground._key(knownLat, -71.06), 12);
const start = Date.now();
const place = { lat: 42.36 };
const entry = await oneBus(app, place);
place.lat = 42.361;
app.run(TRANSIT_POLL_MS);
await app.layer.update();
assert.equal(app.layer.setCockpitSubject(entry.key), true);
app.run(start - AGE_MS + LAG_MS + TRANSIT_POLL_MS / 2 - Date.now());
const { from, to } = entry.segment;
assert.notEqual(Number.isFinite(from.h), Number.isFinite(to.h));
assert.equal(entry.surfaceReady, true, 'it is drawn');
assert.equal(app.layer.getCockpitSubject().position.groundHeightM, null);
});
}
});
test('a vehicle waits for its floor rather than standing on the ellipsoid', async (t) => {
// The shared ground-floor system answers from the rendered mesh cell or the
// real DEM cell; until one of them is warm there is no honest height to draw
@@ -2119,13 +2162,19 @@ test('a segment climbs from the ground it left to the ground it reaches', async
`its snapshot stands where it is drawn, got ${floor().toFixed(1)} m`,
);
// Halfway along the segment it is halfway up; at the end, on the high ground.
// Halfway along the segment it still follows the low ground it crosses; at
// the end, it is on the high ground.
const firstFixAt = start - AGE_MS;
app.run(firstFixAt + LAG_MS + TRANSIT_POLL_MS / 2 - Date.now());
assert.ok(
Math.abs(height() - 11.5) < 3,
`at the corridor floor, got ${height().toFixed(1)} m`,
);
// The two reports' floors blended at the fraction would say about 55 m.
assert.ok(
Math.abs(floor() + 1.5 - height()) < 1,
`its snapshot stands on that floor too, got ${floor().toFixed(1)} m`,
);
app.run(TRANSIT_POLL_MS);
assert.ok(
Math.abs(height() - 101.5) < 1.5,
@@ -4206,6 +4255,7 @@ test('the actual Transit lifecycle keeps exactly its own camera listener in ever
onCameraChanged: noop,
runProximityCheck: noop,
deactivateAllCities: noop,
showCoverage: noop,
},
ingestion: { abortAllInFlight: noop },
},
@@ -4905,3 +4955,197 @@ test('a held vehicle hides, keeps moving out of view, and lets go when it goes',
assert.equal(app.state()._cockpitSubjectKey, null);
assert.equal(app.layer.getCockpitSubject(), null);
});
/** A vehicle's icon in the set that draws it, still or moving. */
function iconOf(app, key) {
return app.markers('still').get(key) ?? app.markers('moving').get(key);
}
test('turning Transit off ends a hold; on again, the vehicle shows, a click selects it and Escape deselects it', async (t) => {
const app = harness(t);
const key = await busRunningNorth(app);
assert.equal(app.layer.setCockpitSubject(key), true);
app.layer.disable(app.viewer);
assert.equal(
app.state()._cockpitSubjectKey,
null,
'the hold ended with the layer',
);
// On again, without a release: the same bus is listed again.
app.layer.enable(app.viewer);
await app.layer.update();
app.settle();
app.run(TRANSIT_POLL_MS);
await app.layer.update();
app.settle();
const [entry] = app.vehicles();
app.frame();
assert.equal(entry.marker.show, true, 'the vehicle is drawn, not held');
assert.equal(iconOf(app, key)?.show, true, 'and so is its icon in the set');
app.viewer.scene.pick = () => app.pickOf(entry);
app.input.click(new Cesium.Cartesian2(500, 400));
assert.equal(app.state()._selectedKey, key, 'a click selects it');
globalThis.document.dispatchEvent(
Object.assign(new Event('keydown'), { key: 'Escape' }),
);
assert.equal(app.state()._selectedKey, null, 'Escape deselects');
});
test('a held parked vehicle draws no icon; let go, it draws its icon again', async (t) => {
// A parked bus with no course: nothing moves or turns its icon, so only the
// hold itself can take the icon out of the set that draws it.
const app = harness(t);
app.serve('mbta', () => ({
status: 200,
body: snapshot(
'mbta',
'MBTA',
[vehicle('bus-1', 42.36, -71.06, reported(), { stopId: 'place-1' })],
{ fetchedAt: Date.now() },
),
}));
app.layer.enable(app.viewer);
await app.layer.update();
app.settle();
for (let i = 0; i < 3; i += 1) {
app.run(TRANSIT_POLL_MS);
await app.layer.update();
app.settle();
}
const key = 'mbta:bus-1';
const [entry] = app.vehicles();
assert.equal(iconOf(app, key)?.show, true, 'drawn before the hold');
assert.equal(app.layer.setCockpitSubject(key), true);
assert.equal(iconOf(app, key)?.show ?? false, false, 'hidden at once');
// The view rides it for a while: frames, a sweep, a poll.
app.run(2_000, 16);
app.settle();
app.run(TRANSIT_POLL_MS);
await app.layer.update();
app.settle();
assert.equal(entry.marker.show, false, 'its marker is hidden');
assert.equal(
iconOf(app, key)?.show ?? false,
false,
'and so is the icon the set draws',
);
assert.equal(app.layer.setCockpitSubject(null), true);
app.advance(250);
app.settle();
assert.equal(iconOf(app, key)?.show, true, 'let go: drawn again');
});
test('a hold moved to another vehicle lets the first go out of view', async (t) => {
const app = harness(t);
app.serve('mbta', () => ({
status: 200,
body: snapshot(
'mbta',
'MBTA',
[
vehicle('bus-1', 42.36, -71.06, reported()),
vehicle('bus-2', 42.37, -71.05, reported()),
],
{ fetchedAt: Date.now() },
),
}));
app.layer.enable(app.viewer);
await app.layer.update();
app.settle();
const bus = (id) => app.vehicles().find((entry) => entry.key === id);
const first = bus('mbta:bus-1');
assert.equal(app.layer.setCockpitSubject(first.key), true);
// The view looks away from both, as a view from inside the first does.
app.lookAt({ west: -70.98, south: 42.3, east: -70.9, north: 42.42 });
app.advance(250);
app.settle();
assert.equal(app.state()._visible.has(bus('mbta:bus-2')), false);
assert.equal(app.layer.setCockpitSubject('mbta:bus-2'), true);
assert.equal(app.state()._visible.has(first), false, 'let go, out of play');
assert.equal(first.marker.show, false, 'and not drawn out of view');
});
test('a vehicle in view let go of a hold goes on from its own clock', async (t) => {
// Held, it played on; let go, the sweep that finds it in view does not
// set its clock again, though the feed's lag has grown since.
for (const next of ['mbta:b', null]) {
await t.test(`the hold moves to ${next}`, async (t) => {
const app = harness(t, { floorAt: () => 5 });
let fixAt = Date.now() - AGE_MS;
let north = 42.36;
app.serve('mbta', () => ({
status: 200,
body: snapshot(
'mbta',
'MBTA',
[
vehicle('a', north, -71.06, fixAt / 1000),
vehicle('b', 42.37, -71.05, reported()),
],
{ fetchedAt: Date.now() },
),
}));
app.layer.enable(app.viewer);
await app.layer.update();
app.settle();
const a = app.vehicles().find((e) => e.key === 'mbta:a');
app.layer.setCockpitSubject(a.key);
for (let poll = 1; poll <= 5; poll += 1) {
fixAt += TRANSIT_POLL_MS;
north += 0.001;
app.run(TRANSIT_POLL_MS);
await app.layer.update();
}
// One late poll raises the feed's target lag.
app.run(TRANSIT_POLL_MS + 10_000);
fixAt += TRANSIT_POLL_MS;
north += 0.001;
await app.layer.update();
app.run(3_000);
const beforeT = a.track.displayT;
const beforeLat = lat(a);
app.layer.setCockpitSubject(next);
app.advance(250);
app.settle();
assert.equal(app.state()._visible.has(a), true, 'A is in view');
assert.ok(a.track.displayT >= beforeT, 'its clock did not go back');
assert.ok(lat(a) >= beforeLat, 'nor did it move back');
});
}
});
test('holding a vehicle out of view tells its view at once the floor it stands on', async (t) => {
// Out of view a vehicle plays on but its marker is not moved: the hold
// places it, so its view reads the floor it is on now, not the old one or
// null.
const app = harness(t, { floorAt: (lat) => (lat > 42.3625 ? 100 : 10) });
for (const [lat, floorM] of [
[42.361, 10],
[42.362, 10],
[42.363, 100],
[42.364, 100],
])
app.ground._warm.set(app.ground._key(lat, -71.06), floorM);
const place = { lat: 42.36 };
const entry = await oneBus(app, place);
const drawnM = () =>
Cesium.Cartographic.fromCartesian(entry.marker.position).height;
assert.ok(Math.abs(drawnM() - 11.5) < 1, 'drawn on the low ground');
app.lookAt({ west: -70.98, south: 42.3, east: -70.9, north: 42.42 });
app.advance(250);
app.settle();
assert.equal(app.state()._visible.has(entry), false, 'out of view');
// Unseen, it drives up the hill and stands there.
for (const next of [42.361, 42.362, 42.363, 42.364, 42.364, 42.364]) {
place.lat = next;
app.run(TRANSIT_POLL_MS);
await app.layer.update();
}
app.run(LAG_MS);
app.settle();
assert.ok(drawnM() < 30, 'its marker was left on the low ground');
assert.equal(app.layer.setCockpitSubject(entry.key), true);
const floorM = app.layer.getCockpitSubject().position.groundHeightM;
assert.ok(Math.abs(floorM - 100) < 1.5, `up the hill, got ${floorM} m`);
});
+26 -1
View File
@@ -43,6 +43,7 @@ import {
transitModelSpec,
} from '../../data/fleetModels.js';
import { createFleetModelLayer } from '../../data/fleetModelInstances.js';
import { groundVehiclePartState } from '../../data/modelPartDrivers.js';
/** Layers built so far, so each one's draw sets have ids of their own. */
let instances = 0;
@@ -944,6 +945,25 @@ export function createRendering({ state, services, parts }) {
display: fleet.display,
policy: fleet.policy,
resolveAsset: fleet.resolveAsset,
partState: vehiclePartState,
});
}
/**
* Wheels rolling at the speed it is drawn moving at (else its reported
* one), doors open while it stands at a stop.
*/
function vehiclePartState(item, table) {
const entry = item.entry;
const drawn = entry?.sample?.segmentSpeedMps;
const reported = entry?.record?.speedMps;
return groundVehiclePartState(table, {
speedMps: Number.isFinite(drawn)
? drawn
: Number.isFinite(reported)
? reported
: null,
atStop: entry?.record?.status === 'STOPPED_AT',
});
}
@@ -1134,13 +1154,18 @@ export function createRendering({ state, services, parts }) {
visibility.noSample = noSample;
const wasShown = entry.marker.show;
const wasVisible = state._visible.has(entry);
// Just let go of a hold (cockpitSubject.js): it played on, so keep
// its clock.
const playedOn = entry.releasedFromHold === true;
entry.releasedFromHold = false;
if (visible) state._visible.add(entry);
else state._visible.delete(entry);
// Turned afresh once back in view: the camera may have moved while it
// was out, after the pass that would have turned it.
if (visible && !wasVisible) entry.rotationCourse = undefined;
if (visible && entry.track?.count) {
if (!wasVisible && !entry.qaFixture) syncPlayback(entry, now);
if (!wasVisible && !playedOn && !entry.qaFixture)
syncPlayback(entry, now);
// Re-entry can advance into an unprepared corridor; loaded tiles can
// also resolve a cold path without a poll or a render-loop wakeup.
if (!wasVisible || entry.surfaceReady === false || entry.heightPending)