Show transit vehicle facts, motion and a fleet breakdown in Context

A transit vehicle picked on the map now finds its record in Context (the
click carries the feed and vehicle key), so the card shows its operator,
place, route, report age and the operator's last reported state in plain
words. The layer card breaks transit in view down by motion (moving,
stopped, waiting for an update, no recent fix), mode, operator, last
reported state and crowding where the feed has it; vehicle-position feeds
carry no timetable, so early or late is not shown. Rows in the in-view
list carry a motion icon.
This commit is contained in:
Manjunath Paparaju authored and Sameh Khamis committed 2026-11-16 14:58:53 -08:00
1 parent 5c580cbd4a
commit 0fe6fd2bb8
6 files changed
+159 -5

No files matched your search

+27 -1
View File
@@ -5,12 +5,23 @@ import {
transitDetectionClass,
transitDetectionId,
transitDetectionMetric,
vehicleReportTimeMs,
} from './policy.js';
import {
TRANSIT_ENABLED_FEEDS,
getRegisteredTransitFeed,
transitRouteLabel,
} from '../../data/transitFeeds.js';
import { transitModeTier } from '../../data/transitPresetStyle.js';
import { displayMotion } from './movement.js';
/** The display's motion word as a record field for the Context card. */
const MOTION_FIELD = Object.freeze({
'EN ROUTE': 'moving',
STOPPED: 'stopped',
WAITING: 'waiting',
'NO FIX': 'no-fix',
});
/** Regions, not feeds: one region can carry several feeds (Rio has two). */
const TRANSIT_REGION_COUNT = new Set(
@@ -211,10 +222,14 @@ export function createQueries({ state, parts }) {
* query engine. On demand only (once per spoken query); [] while the
* layer is off.
* @param {number} [maxCount=Infinity] Most records to return.
* @returns {Array<Object>} {id, label, routeId, mode, lat, lon, speedMps, courseDeg, status, occupancy}.
* @returns {Array<Object>} {id, label, routeId, mode, lat, lon, speedMps, courseDeg, status, occupancy},
* plus `key` (the layer's own vehicle key, which a map click carries),
* `route`, `operator`, `place`, `observedMs` and `motion` (what the
* display shows: moving, stopped, waiting or no-fix) for the Context card.
*/
getAnalystRecords(maxCount = Infinity) {
if (!state._enabled) return [];
const now = Date.now();
const num = (v) => (Number.isFinite(v) ? v : null);
const result = [];
for (const entry of state._vehicles.values()) {
@@ -222,6 +237,8 @@ export function createQueries({ state, parts }) {
const record = entry.record || {};
if (!Number.isFinite(record.lat) || !Number.isFinite(record.lon))
continue;
const feed = feedForEntry(state, entry);
const reportedMs = vehicleReportTimeMs(record, entry.fetchedAt);
result.push({
id: record.label || record.id || entry.key,
label: record.label || null,
@@ -233,6 +250,15 @@ export function createQueries({ state, parts }) {
courseDeg: num(entry.courseDeg ?? record.bearing),
status: record.status || null,
occupancy: record.occupancy || null,
key: entry.key,
route:
record.routeId && feed
? transitRouteLabel(feed, record.routeId)
: record.routeId || null,
operator: feed?.name || null,
place: feed?.region || null,
observedMs: Number.isFinite(reportedMs) ? reportedMs : null,
motion: MOTION_FIELD[displayMotion(entry, now).word] || null,
});
}
return result;