Merge pull request #1802 from bilawalsidhu/fix/bikeshare-coverage

Bike Share marks its covered cities on the globe
This commit is contained in:
Sameh Khamis authored and GitHub committed 2026-11-17 21:33:14 -08:00
commit 96fac711f4
25 files changed
+317 -15

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
- Bike Share marks every covered city on the globe above the height its
stations draw at; clicking a city's marker flies down into it
(samehkhamis, #1802).
+5
View File
@@ -3382,6 +3382,11 @@ catalogued systems). The chip stays ON. A loading or failed Bike Share city
shows its own text. Leaving coverage clears the last-update time. The voice
analyst gets the same English notes; both translate them through
`translateStatusMessage` (`src/ui/statusText.js`).
Above its gate Bike Share also marks every covered city on the globe: a
green, white-ringed dot per registry system, 5 km up so terrain never hides
it, shown only while the layer is on and stations are not drawn. Clicking one
flies straight down into the city from 20 km, an explicit camera action like
the other camera controls (`attachShellServices({ runNavigation })`).
## Places and CCTV request bounds
+2 -1
View File
@@ -4549,5 +4549,6 @@
"Move up": "نقل لأعلى",
"Move down": "نقل لأسفل",
"Click a shot to go to it, double-click to rename.": "انقر على لقطة للانتقال إليها، وانقر عليها نقرًا مزدوجًا لإعادة تسميتها.",
"Back to live at the starting view": "العودة إلى البث المباشر في العرض الأولي"
"Back to live at the starting view": "العودة إلى البث المباشر في العرض الأولي",
"Exit cockpit to fly to a bike share city": "اخرج من قمرة القيادة للانتقال إلى مدينة بها مشاركة دراجات"
}
+2 -1
View File
@@ -4137,5 +4137,6 @@
"Move up": "Nach oben verschieben",
"Move down": "Nach unten verschieben",
"Click a shot to go to it, double-click to rename.": "Aufnahme anklicken, um zu ihr zu wechseln, Doppelklick zum Umbenennen.",
"Back to live at the starting view": "Zurück zu Live in der Startansicht"
"Back to live at the starting view": "Zurück zu Live in der Startansicht",
"Exit cockpit to fly to a bike share city": "Cockpit verlassen, um zu einer Stadt mit Bike-Sharing zu fliegen"
}
+2 -1
View File
@@ -4240,5 +4240,6 @@
"Move up": "Subir",
"Move down": "Bajar",
"Click a shot to go to it, double-click to rename.": "Haz clic en un plano para ir a él y doble clic para cambiarle el nombre.",
"Back to live at the starting view": "Volver al directo en la vista inicial"
"Back to live at the starting view": "Volver al directo en la vista inicial",
"Exit cockpit to fly to a bike share city": "Sal de la cabina para volar a una ciudad con bicicletas compartidas"
}
+2 -1
View File
@@ -4240,5 +4240,6 @@
"Move up": "Monter",
"Move down": "Descendre",
"Click a shot to go to it, double-click to rename.": "Cliquez sur un plan pour y aller, double-cliquez pour le renommer.",
"Back to live at the starting view": "Revenir au direct dans la vue de départ"
"Back to live at the starting view": "Revenir au direct dans la vue de départ",
"Exit cockpit to fly to a bike share city": "Quittez le cockpit pour aller vers une ville avec vélos en libre-service"
}
+2 -1
View File
@@ -4240,5 +4240,6 @@
"Move up": "הזזה למעלה",
"Move down": "הזזה למטה",
"Click a shot to go to it, double-click to rename.": "לחץ על שוט כדי לעבור אליו, לחיצה כפולה לשינוי שם.",
"Back to live at the starting view": "חזרה לשידור החי בתצוגת הפתיחה"
"Back to live at the starting view": "חזרה לשידור החי בתצוגת הפתיחה",
"Exit cockpit to fly to a bike share city": "צא מתא הטייס כדי לטוס לעיר עם שיתוף אופניים"
}
+2 -1
View File
@@ -4240,5 +4240,6 @@
"Move up": "Sposta su",
"Move down": "Sposta giù",
"Click a shot to go to it, double-click to rename.": "Fai clic su uno scatto per andarci, doppio clic per rinominarlo.",
"Back to live at the starting view": "Torna alla diretta nella vista iniziale"
"Back to live at the starting view": "Torna alla diretta nella vista iniziale",
"Exit cockpit to fly to a bike share city": "Esci dalla cabina per volare verso una città con bike sharing"
}
+2 -1
View File
@@ -4034,5 +4034,6 @@
"Move up": "上へ移動",
"Move down": "下へ移動",
"Click a shot to go to it, double-click to rename.": "ショットをクリックしてそこへ移動、ダブルクリックで名前を変更します。",
"Back to live at the starting view": "ライブに戻り、最初の表示へ"
"Back to live at the starting view": "ライブに戻り、最初の表示へ",
"Exit cockpit to fly to a bike share city": "シェアサイクルのある都市へ移動するにはコックピットを終了してください"
}
+2 -1
View File
@@ -4240,5 +4240,6 @@
"Move up": "Mover para cima",
"Move down": "Mover para baixo",
"Click a shot to go to it, double-click to rename.": "Clique em um plano para ir até ele e clique duas vezes para renomeá-lo.",
"Back to live at the starting view": "Voltar ao vivo na vista inicial"
"Back to live at the starting view": "Voltar ao vivo na vista inicial",
"Exit cockpit to fly to a bike share city": "Saia do cockpit para voar até uma cidade com bicicletas compartilhadas"
}
+2 -1
View File
@@ -4343,5 +4343,6 @@
"Move up": "Переместить вверх",
"Move down": "Переместить вниз",
"Click a shot to go to it, double-click to rename.": "Щёлкните кадр, чтобы перейти к нему, дважды — чтобы переименовать.",
"Back to live at the starting view": "Вернуться в прямой эфир в начальном виде"
"Back to live at the starting view": "Вернуться в прямой эфир в начальном виде",
"Exit cockpit to fly to a bike share city": "Выйдите из кабины, чтобы перелететь в город с прокатом велосипедов"
}
+2 -1
View File
@@ -4137,5 +4137,6 @@
"Move up": "Flytta upp",
"Move down": "Flytta ned",
"Click a shot to go to it, double-click to rename.": "Klicka på en tagning för att gå till den, dubbelklicka för att byta namn.",
"Back to live at the starting view": "Tillbaka till live i startvyn"
"Back to live at the starting view": "Tillbaka till live i startvyn",
"Exit cockpit to fly to a bike share city": "Lämna cockpit för att flyga till en stad med lånecyklar"
}
+2 -1
View File
@@ -4343,5 +4343,6 @@
"Move up": "Перемістити вгору",
"Move down": "Перемістити вниз",
"Click a shot to go to it, double-click to rename.": "Клацніть кадр, щоб перейти до нього, двічі — щоб перейменувати.",
"Back to live at the starting view": "Повернутися до прямого ефіру в початковому вигляді"
"Back to live at the starting view": "Повернутися до прямого ефіру в початковому вигляді",
"Exit cockpit to fly to a bike share city": "Вийдіть із кабіни, щоб перелетіти до міста з прокатом велосипедів"
}
+2 -1
View File
@@ -4034,5 +4034,6 @@
"Move up": "上移",
"Move down": "下移",
"Click a shot to go to it, double-click to rename.": "单击镜头即可转到该镜头,双击可重命名。",
"Back to live at the starting view": "回到实时并返回初始视图"
"Back to live at the starting view": "回到实时并返回初始视图",
"Exit cockpit to fly to a bike share city": "退出驾驶舱以飞往有共享单车的城市"
}
+2 -1
View File
@@ -4034,5 +4034,6 @@
"Move up": "上移",
"Move down": "下移",
"Click a shot to go to it, double-click to rename.": "單擊鏡頭即可轉到該鏡頭,雙擊可重命名。",
"Back to live at the starting view": "回到實時並返回初始視圖"
"Back to live at the starting view": "回到實時並返回初始視圖",
"Exit cockpit to fly to a bike share city": "退出駕駛艙以飛往有共享單車的城市"
}
+139
View File
@@ -0,0 +1,139 @@
// Bike Share's covered cities on the globe (HAL-921): above the height
// stations draw at, every system in the registry has a marker, so the globe
// says where bike share is, and a click on one flies down into its city.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { GBFS_CITY_REGISTRY } from './registry.js';
import { createState } from './state.js';
import { createIngestion } from './ingestion.js';
import { createModel } from './model.js';
import { createViewport } from './viewport.js';
import { createRendering } from './rendering.js';
import { createSelection } from './selection.js';
import { createLifecycle } from './lifecycle.js';
import { COVERAGE_FLY_HEIGHT_M } from './policy.js';
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
import { fakeInput } from '../../input/testDoubles.mjs';
globalThis.document ??= {
addEventListener() {},
removeEventListener() {},
};
function makeLayer() {
const owners = new Map();
const services = {
render: { governorRequestRender() {} },
overlays: {
setOverlayEntries() {},
setOverlaySourceVisible() {},
clearOverlaySource() {},
},
sprites: { registerSpriteCollection() {}, restoreSpriteOrder() {} },
picking: {
registerPickOwner: (id, owns) => owners.set(id, owns),
unregisterPickOwner: (id) => owners.delete(id),
},
};
const source = { getStations: async () => ({ data: { stations: [] } }) };
const state = createState({ services });
const parts = {};
const context = { state, services, parts, source };
parts.ingestion = createIngestion(context);
parts.model = createModel(context);
parts.viewport = createViewport(context);
parts.rendering = createRendering(context);
parts.selection = createSelection(context);
parts.queries = { collectDetectableStations: () => [] };
parts.lifecycle = createLifecycle(context);
const camera = { lat: 20, lon: 0, height: 18_000_000 };
const flights = [];
const viewer = { scene: { pick: () => undefined, canvas: {} } };
const { draw } = bindFakeDraw(viewer, {
camera: {
pose: () => ({ ...camera }),
viewRectangle: () => null,
on: () => () => {},
flyTo: (destination, options) => flights.push({ destination, options }),
},
});
// The layer's click subscription, called with a hit as the dispatcher gives it.
const fake = fakeInput(viewer);
const clicks = [];
const subscribe = fake.input.onClick;
fake.input.onClick = (fn) => {
clicks.push(fn);
return subscribe.call(fake.input, () => {});
};
parts.lifecycle.methods.init(viewer);
const coverage = () =>
draw.find('bikeshare:') &&
[...draw.sets.values()].find(
(set) => !set.disposed && set.spec.id.endsWith(':coverage'),
);
return {
state,
parts,
owners,
flights,
coverage,
click: (hit) => clicks.at(-1)({ drawHit: hit }),
async moveTo(height) {
camera.height = height;
await parts.viewport.runProximityCheck();
},
enable: () => parts.lifecycle.methods.enable(viewer),
disable: () => parts.lifecycle.methods.disable(),
};
}
test('every covered city has a marker, shown only while the layer is on and too high for stations', async () => {
const layer = makeLayer();
const set = layer.coverage();
assert.equal(set.items.size, GBFS_CITY_REGISTRY.length);
assert.equal(set.show, false, 'hidden while the layer is off');
layer.enable();
await layer.moveTo(18_000_000);
assert.equal(set.show, true, 'the globe shows where bike share is');
await layer.moveTo(20_000);
assert.equal(
set.show,
false,
'stations take over below the activation height',
);
await layer.moveTo(18_000_000);
assert.equal(set.show, true);
layer.disable();
assert.equal(set.show, false, 'gone with the layer');
});
test('a marker belongs to the layer and its click flies straight down into the city', async () => {
const layer = makeLayer();
layer.enable();
await layer.moveTo(18_000_000);
const city = GBFS_CITY_REGISTRY.find(
(each) => each.id === 'boston-bluebikes',
);
const id = `city:${city.id}`;
assert.equal(layer.owners.get('bikeshare')(id), true);
assert.equal(layer.owners.get('bikeshare')('city:nowhere'), false);
const navigated = [];
layer.parts.lifecycle.methods.attachShellServices({
runNavigation: (navigate) => {
navigated.push('explicit');
return navigate();
},
});
layer.click({ set: layer.coverage().spec.id, id });
assert.deepEqual(navigated, ['explicit'], 'an explicit camera action');
assert.equal(layer.flights.length, 1);
const { destination, options } = layer.flights[0];
assert.deepEqual(destination, {
lon: city.centerLon,
lat: city.centerLat,
height: COVERAGE_FLY_HEIGHT_M,
});
assert.equal(options.orientation.pitch, -Math.PI / 2);
assert.ok(COVERAGE_FLY_HEIGHT_M < 48_000, 'below the activation height');
});
+18 -2
View File
@@ -20,6 +20,18 @@ export function createLifecycle({
}
const methods = {
/**
* The shell's services: `runNavigation(navigate)` runs a covered city's
* flight as an explicit camera action, as the other camera controls are.
* @param {{ runNavigation?: Function }|null} shellServices
*/
attachShellServices(shellServices) {
layerState._runNavigation =
typeof shellServices?.runNavigation === 'function'
? shellServices.runNavigation
: null;
},
/**
* Initialize the bikeshare layer. Makes the station draw sets on the
* viewer's renderer (`drawOf`), resets all internal state, and installs
@@ -81,8 +93,11 @@ export function createLifecycle({
);
parts.selection._installClickHandler(viewer);
// Pick-ownership (H2): station point ids are string render-map keys.
registerPickOwner('bikeshare', (pickedId) =>
layerState._stationRenderMap.has(pickedId),
registerPickOwner(
'bikeshare',
(pickedId) =>
layerState._stationRenderMap.has(pickedId) ||
parts.selection.coverageCityOf(pickedId) !== null,
);
if (!layerState._cameraChangedOff) {
@@ -124,6 +139,7 @@ export function createLifecycle({
parts.viewport.deactivateAllCities();
layerState._cityRuntime.clear();
if (layerState._stationSet) layerState._stationSet.show = false;
parts.viewport.showCoverage(false);
layerState._count = 0;
layerState._loading = false;
layerState._loadingOps = 0;
+16
View File
@@ -15,6 +15,22 @@ const ACTIVATION_ALTITUDE_M = 50000;
export const ACTIVATION_ENTER_ALTITUDE_M = ACTIVATION_ALTITUDE_M - 2000;
/**
* Where a covered city's marker flies to: straight down from this height,
* well inside the activation band, with the city's stations in view.
*/
export const COVERAGE_FLY_HEIGHT_M = 20000;
/** A covered city's marker: the stations' green, larger, ringed in white. */
export const COVERAGE_PIXEL_SIZE = 11;
export const COVERAGE_OUTLINE_WIDTH = 2;
/**
* A marker's height: above the highest covered city's ground, so terrain
* never hides it, while the globe itself hides the markers behind it.
*/
export const COVERAGE_HEIGHT_M = 5000;
/** Hysteresis exit threshold — layer deactivates when camera rises above this. */
export const ACTIVATION_EXIT_ALTITUDE_M = ACTIVATION_ALTITUDE_M + 2000;
+26
View File
@@ -13,7 +13,11 @@ import {
POINT_SCALE_BY_DISTANCE,
POINT_FADE_BY_DISTANCE,
POINT_DISABLE_DEPTH_TEST_M,
COVERAGE_PIXEL_SIZE,
COVERAGE_OUTLINE_WIDTH,
COVERAGE_HEIGHT_M,
} from './policy.js';
import { GBFS_CITY_REGISTRY } from './registry.js';
import { heightsOf } from '../../queries/heights.js';
import { fromDegrees } from '../../geo/ellipsoid.js';
import { drawOf } from '../../render/rendererOf.js';
@@ -24,6 +28,9 @@ import { drawOf } from '../../render/rendererOf.js';
* share a renderer. Picks name them as `Hit.set`.
*/
export const BIKESHARE_SET_ID = 'bikeshare';
/** A covered city's marker id: its registry id under this prefix. */
export const COVERAGE_ID_PREFIX = 'city:';
let instances = 0;
export function createRendering({
@@ -51,6 +58,23 @@ export function createRendering({
drawOrder: services.sprites?.spriteDrawOrder?.('bikeshare') ?? 0,
});
layerState._selectedSet = draw.points({ id: `${prefix}:selected` });
// One marker per covered city, drawn while the camera is too high for
// stations: the globe shows where bike share is.
layerState._coverageSet = draw.points({
id: `${prefix}:coverage`,
show: false,
drawOrder: services.sprites?.spriteDrawOrder?.('bikeshare') ?? 0,
});
layerState._coverageSet.set(
GBFS_CITY_REGISTRY.map((city) => ({
id: `${COVERAGE_ID_PREFIX}${city.id}`,
pos: fromDegrees(city.centerLon, city.centerLat, COVERAGE_HEIGHT_M),
pixelSize: COVERAGE_PIXEL_SIZE,
color: COLOR_GREEN,
outlineColor: [1, 1, 1, 0.9],
outlineWidth: COVERAGE_OUTLINE_WIDTH,
})),
);
// Drawn from the start, empty, so both take their place in the scene
// now, as the layer's collections did; the stations' place among the
// other sprite layers is their draw order (`spriteDrawOrder`).
@@ -62,8 +86,10 @@ export function createRendering({
function detachSets() {
layerState._stationSet?.dispose();
layerState._selectedSet?.dispose();
layerState._coverageSet?.dispose();
layerState._stationSet = null;
layerState._selectedSet = null;
layerState._coverageSet = null;
}
/**
+46
View File
@@ -4,7 +4,11 @@ import {
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS,
SELECTED_POINT_STYLE,
COVERAGE_FLY_HEIGHT_M,
} from './policy.js';
import { GBFS_CITY_REGISTRY } from './registry.js';
import { COVERAGE_ID_PREFIX } from './rendering.js';
import { cameraOf } from '../../render/rendererOf.js';
export function createSelection({
state: layerState,
@@ -139,6 +143,38 @@ export function createSelection({
* @param {object} viewer - The viewer the layer draws on.
*/
/**
* The covered city a marker id names, or null.
* @param {unknown} id
*/
function coverageCityOf(id) {
if (typeof id !== 'string' || !id.startsWith(COVERAGE_ID_PREFIX))
return null;
const cityId = id.slice(COVERAGE_ID_PREFIX.length);
return GBFS_CITY_REGISTRY.find((city) => city.id === cityId) ?? null;
}
/**
* Straight down over a covered city, low enough for its stations, as the
* shell's camera action when it gave one.
* @param {{ centerLat: number, centerLon: number }} city
*/
function flyIntoCity(city) {
const viewer = layerState._viewer;
if (!viewer) return;
const fly = () =>
cameraOf(viewer).flyTo(
{
lon: city.centerLon,
lat: city.centerLat,
height: COVERAGE_FLY_HEIGHT_M,
},
{ orientation: { heading: 0, pitch: -Math.PI / 2, roll: 0 } },
);
if (layerState._runNavigation) layerState._runNavigation(fly);
else fly();
}
function _installClickHandler(viewer) {
if (layerState._clickSubscription) return;
@@ -149,6 +185,15 @@ export function createSelection({
// Clicking the selected highlight itself — ignore (don't deselect).
if (hit.set === layerState._selectedSet?.id) return;
// A covered city's marker: fly down into it.
if (hit.set === layerState._coverageSet?.id) {
const city = coverageCityOf(hit.id);
if (city) {
flyIntoCity(city);
return;
}
}
// A station dot of this layer's own set
if (
hit.set === layerState._stationSet?.id &&
@@ -183,5 +228,6 @@ export function createSelection({
_selectStation,
_installClickHandler,
_onKeyDown,
coverageCityOf,
};
}
+11
View File
@@ -27,6 +27,17 @@ export function createState({ services }) {
layerState._stationSet = null;
/**
* Draw set of the covered cities' markers, shown above the activation
* height so the globe says where bike share is, or null.
*/
layerState._coverageSet = null;
/** The shell's camera action for a marker's flight (`attachShellServices`), or null. */
layerState._runNavigation = null;
/** Draw set of the selected station's highlight dot, or null. */
layerState._selectedSet = null;
+15
View File
@@ -115,6 +115,18 @@ export function createViewport({ state: layerState, services, parts, source }) {
parts.rendering.removeCityPoints(cityId);
}
/**
* Show the covered cities' markers, or hide them: shown while the layer is
* on and the camera is too high for stations.
* @param {boolean} shown
*/
function showCoverage(shown) {
const set = layerState._coverageSet;
if (!set || set.show === shown) return;
set.show = shown;
governorRequestRender('bikeshare-coverage');
}
/** Repaint the row now: it follows the camera, the manager tick is 60 s. */
function refreshRow() {
layerState._dataManager?.refreshLayerStats?.('bikeshare');
@@ -212,11 +224,13 @@ export function createViewport({ state: layerState, services, parts, source }) {
const wasGateEnabled = layerState._altitudeGateEnabled;
// Altitude gate: disable all cities when camera is too high
if (!shouldActivateAtAltitude(altitude)) {
showCoverage(true);
deactivateAllCities();
if (wasGateEnabled) refreshRow();
return;
}
showCoverage(false);
const center = getCameraCenterLatLon(layerState._viewer);
if (!center) return;
@@ -288,6 +302,7 @@ export function createViewport({ state: layerState, services, parts, source }) {
activateCity,
runProximityCheck,
scheduleProximityCheck,
showCoverage,
onCameraChanged,
};
}
+1
View File
@@ -4181,6 +4181,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 },
},
+2
View File
@@ -38,6 +38,8 @@ const COCKPIT_REFUSALS = Object.freeze({
cyclone: msg('Exit cockpit to fly to a cyclone'),
// The News panel's cards and the news layer's hotspots fly to the event.
news: msg('Exit cockpit to fly to a news report'),
// A covered city's marker on Bike Share flies down into the city.
'bike share': msg('Exit cockpit to fly to a bike share city'),
// Voice track_entity (TRACKABLE_FAMILIES kinds in gevActions.js) and
// frame_overhead, which frames the contacts around the current view.
aircraft: msg('Exit cockpit to fly to an aircraft'),
+9
View File
@@ -158,6 +158,15 @@ export class LayerBindings {
});
this._weatherShellModules.push(news);
}
// Bike share flies into a covered city from its marker the same way.
const bikeshare = this._dataManager?.layers?.get('bikeshare')?.module;
if (typeof bikeshare?.attachShellServices === 'function') {
bikeshare.attachShellServices({
runNavigation: (navigate) =>
this.runImmediateNavigation('bike share', navigate),
});
this._weatherShellModules.push(bikeshare);
}
}
_persistAwarenessSelection(event, cleared = false) {