Say why Transit and Bike Share rows are empty outside coverage

Over a city with no feed or system (London, Tokyo) both rows read
"ON · — · never", the same as a feed that never answered. Transit already
computed a coverage note but put it only in `coverage`, which the row does
not show; Bike Share reported nothing at all.

Both layers now report a `zoom-in` guidance status with a `statusMessage`:
"Fly below 3,000 km to a covered region" / "No feed here yet · N regions
available" for Transit, and "Fly below 48 km to a covered city" / "No bike
share here yet · N systems available" for Bike Share. A loading or failed
Bike Share city keeps its own text. Leaving coverage clears the layer's
last-update time, so the row no longer dates data it no longer draws.

The coverage-note translations move from the voice card into
`translateStatusMessage` (ui/statusText.js), which the Layers row and the
voice card now share.
This commit is contained in:
German Khokhlov committed 2026-11-05 12:52:28 +04:00
1 parent 7d8b80db0a
commit b6ad32009f
23 files changed
+459 -37

No files matched your search

+20 -2
View File
@@ -1,5 +1,6 @@
import { msg, t } from '../../i18n/index.js';
import { STATUS_POLL_MS } from './policy.js';
import { ACTIVATION_ENTER_ALTITUDE_M, STATUS_POLL_MS } from './policy.js';
import { GBFS_CITY_REGISTRY } from './registry.js';
export function createControls({ state: layerState, services, parts, source }) {
const methods = {
@@ -57,7 +58,7 @@ export function createControls({ state: layerState, services, parts, source }) {
/**
* Return current layer statistics for the UI status display.
* @returns {{ count: number, lastUpdate: number|null, loading: boolean, loadingLabel?: string, error?: string, degraded?: boolean, stale?: boolean }}
* @returns {{ count: number, lastUpdate: number|null, loading: boolean, loadingLabel?: string, error?: string, degraded?: boolean, stale?: boolean, status?: string, statusMessage?: string }}
*/
getStats() {
const stats = {
@@ -65,6 +66,23 @@ export function createControls({ state: layerState, services, parts, source }) {
lastUpdate: layerState._lastUpdate,
loading: layerState._loading,
};
// No system in range is guidance, not an empty feed: the camera is too
// high, or no catalogued system is near the view. A city that failed
// leaves range empty too, and reports its failure below instead.
if (
layerState._enabled &&
!layerState._loading &&
layerState._activeCityIds.size === 0 &&
layerState._failedCityIds.size === 0
) {
// English data (the analyst's empty note to the model, and the Layers
// row's prompt); both show it through translateStatusMessage
// (ui/statusText.js).
const note = layerState._altitudeGateEnabled
? `No bike share here yet · ${GBFS_CITY_REGISTRY.length} systems available`
: `Fly below ${Math.round(ACTIVATION_ENTER_ALTITUDE_M / 1000).toLocaleString('en-US')} km to a covered city`;
return { ...stats, status: 'zoom-in', statusMessage: note };
}
if (layerState._loading) {
stats.loadingLabel =
layerState._activeCityIds.size > 0
@@ -0,0 +1,124 @@
// BIKESHARE COVERAGE STATUS — a view with no system says so.
//
// Over a city with no catalogued system (London, Tokyo) the layer drew nothing
// and reported nothing, so its row read "ON · — · GBFS · never": the same as a
// feed that had never answered. These cases pin the rule that replaced it:
// with no system in range the layer reports a guidance status that says why,
// and a view it left keeps no date for data it no longer draws.
//
// Run with: npm test
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createState } from './state.js';
import { createControls } from './controls.js';
import { createModel } from './model.js';
import { createViewport } from './viewport.js';
import { GBFS_CITY_REGISTRY } from './registry.js';
const LONDON = { lat: 51.5072, lon: -0.1276 };
function makeLayer() {
const services = {
overlays: {
setOverlayEntries() {},
setOverlaySourceVisible() {},
clearOverlaySource() {},
},
render: { governorRequestRender() {} },
};
const state = createState({ services });
const parts = {
queries: { collectDetectableStations: () => [] },
model: createModel({ state, services, parts: {}, source: null }),
ingestion: { abortInFlight() {} },
rendering: { removeCityPoints() {} },
};
parts.viewport = createViewport({ state, services, parts, source: null });
const { methods } = createControls({ state, services, parts, source: {} });
state._enabled = true;
return { state, methods, viewport: parts.viewport };
}
/** A viewer looking straight down at `at` from `height` metres. */
function viewerAt(at, height) {
const rad = Math.PI / 180;
return {
camera: {
positionCartographic: {
height,
latitude: at.lat * rad,
longitude: at.lon * rad,
},
computeViewRectangle: () => undefined,
},
scene: { globe: {} },
};
}
test('above the altitude gate the row says how low to fly', async () => {
const { state, methods, viewport } = makeLayer();
state._viewer = viewerAt(LONDON, 2_000_000);
await viewport.runProximityCheck();
const stats = methods.getStats();
assert.equal(stats.status, 'zoom-in');
assert.equal(stats.statusMessage, 'Fly below 48 km to a covered city');
assert.equal(stats.error, undefined);
});
test('a city with no system says so and counts the ones there are', async () => {
const { state, methods, viewport } = makeLayer();
state._viewer = viewerAt(LONDON, 8_000);
await viewport.runProximityCheck();
const stats = methods.getStats();
assert.equal(stats.status, 'zoom-in');
assert.equal(
stats.statusMessage,
`No bike share here yet · ${GBFS_CITY_REGISTRY.length} systems available`,
);
assert.equal(stats.count, 0);
});
test('a city with a system in range is not given the prompt', () => {
const { state, methods } = makeLayer();
state._altitudeGateEnabled = true;
state._activeCityIds.add('boston-bluebikes');
assert.equal(methods.getStats().status, undefined);
});
test('a loading or failed city reports itself, not the prompt', () => {
const { state, methods } = makeLayer();
state._altitudeGateEnabled = true;
state._loading = true;
assert.equal(methods.getStats().status, undefined);
// A city that failed is dropped from range, and still owns the row.
state._loading = false;
state._failedCityIds.add('boston-bluebikes');
const stats = methods.getStats();
assert.equal(stats.status, undefined);
assert.equal(stats.error, 'GBFS fetch error');
});
test('a disabled layer reports no prompt', () => {
const { state, methods } = makeLayer();
state._enabled = false;
assert.equal(methods.getStats().status, undefined);
});
test('leaving every system behind drops the date of the data it drew', async () => {
for (const height of [8_000, 2_000_000]) {
const { state, methods, viewport } = makeLayer();
state._lastUpdate = Date.now();
// Boston's stations were drawn and dated; the camera moves to London.
state._activeCityIds.add('boston-bluebikes');
state._cityRuntime.set('boston-bluebikes', {});
state._viewer = viewerAt(LONDON, height);
await viewport.runProximityCheck();
assert.equal(state._activeCityIds.size, 0);
assert.equal(methods.getStats().lastUpdate, null, `at ${height} m`);
}
});
+3
View File
@@ -125,6 +125,8 @@ export function createViewport({ state: layerState, services, parts, source }) {
// A failure belongs to a city in range; none are once everything is off.
layerState._failedCityIds.clear();
layerState._count = 0;
// Nothing is left on the map to date.
layerState._lastUpdate = null;
}
/**
@@ -227,6 +229,7 @@ export function createViewport({ state: layerState, services, parts, source }) {
layerState._activeCityIds = nextActive;
if (layerState._activeCityIds.size === 0) {
layerState._count = 0;
layerState._lastUpdate = null;
return;
}
+39
View File
@@ -3982,3 +3982,42 @@ test('parked transit reprojects held and reported courses at the bounded camera
'selected unknown course also stays screen-up',
);
});
test('a view with no feed reads its coverage prompt, not an undated feed', async (t) => {
const app = harness(t);
app.serve('mbta', () => ({
status: 200,
body: snapshot(
'mbta',
'MBTA',
[vehicle('bus-1', 42.36, -71.06, Date.now() / 1000)],
{ fetchedAt: Date.now() },
),
}));
app.layer.enable(app.viewer);
await app.layer.update();
assert.ok(app.layer.getStats().lastUpdate, 'Boston has a dated snapshot');
// London has no registered feed: the row prompts instead of dating Boston's
// last snapshot over an empty map.
app.lookAt({ west: -0.2, south: 51.45, east: -0.05, north: 51.55 });
app.advance(1_000);
const away = app.layer.getStats();
assert.equal(away.status, 'zoom-in');
assert.equal(away.count, 0);
assert.equal(away.lastUpdate, null);
assert.match(
away.statusMessage,
/^No feed here yet · \d+ regions available$/,
);
assert.equal(away.coverage, away.statusMessage);
// Above the altitude gate the prompt says how low to fly.
app.viewer.camera.positionCartographic.height = 10_000_000;
app.lookAt({ west: -0.2, south: 51.45, east: -0.05, north: 51.55 });
app.advance(1_000);
assert.equal(
app.layer.getStats().statusMessage,
'Fly below 3,000 km to a covered region',
);
});
+8 -5
View File
@@ -240,17 +240,20 @@ export function createQueries({ state, parts }) {
const health = aggregateTransitFeedHealth(statuses, now);
const count = state._vehicles.size;
if (state._enabled && active.length === 0) {
// English data (the analyst's empty note to the model, and the Layers
// row's prompt); both show it through translateStatusMessage
// (ui/statusText.js).
const note = state._altitudeGateOpen
? `No feed here yet · ${TRANSIT_ENABLED_FEEDS.length} regions available`
: `Fly below ${Math.round(ACTIVATION_ALTITUDE_M / 1000).toLocaleString('en-US')} km to a covered region`;
return {
count: 0,
lastUpdate: state._lastUpdate,
error: null,
source: 'GTFS-RT',
status: 'zoom-in',
// English data (the analyst's empty note to the model); the voice
// card shows it through NOTE_PATTERNS (voice/resultDisplay.js).
coverage: state._altitudeGateOpen
? `No feed here yet · ${TRANSIT_ENABLED_FEEDS.length} regions available`
: `Fly below ${Math.round(ACTIVATION_ALTITUDE_M / 1000).toLocaleString('en-US')} km to a covered region`,
statusMessage: note,
coverage: note,
};
}
// Age is shown by the same rule the row state uses, so the text and the
+3
View File
@@ -108,6 +108,9 @@ export function createViewport({ state, services, parts }) {
parts.ingestion.removeFeedVehicles(feedId);
}
}
// Leaving coverage leaves nothing on the map to date: a row that read
// "26s ago" over an empty view would claim a feed that is no longer here.
if (desired.size === 0) state._lastUpdate = null;
for (const [feedId, feed] of desired) {
if (!state._activeFeeds.has(feedId)) {
state._activeFeeds.set(feedId, feed);