From da689e03ac983499f9682c46889d454195e7231b Mon Sep 17 00:00:00 2001 From: monwiss <547445+monwiss@users.noreply.github.com> Date: Thu, 24 Sep 2026 17:15:39 -0400 Subject: [PATCH 01/61] refactor(providers): move the tile budget helpers out of the TomTom module utcDayKey, normalizeBudget and isOverBudget move unchanged to src/data/tileBudget.js. Nothing in them was TomTom-specific; the next keyed tile proxy (Xweather) counts a monthly allowance through the same two functions. tomtomTiles.js re-exports them, so the traffic provider and its tests keep their imports. Co-Authored-By: Claude Opus 5.5 (1M context) --- scripts/format-scope.json | 2 ++ scripts/package-boundaries.json | 12 ++++++-- src/data/tileBudget.js | 53 +++++++++++++++++++++++++++++++++ src/data/tileBudget.test.mjs | 26 ++++++++++++++++ src/data/tomtomTiles.js | 41 ++----------------------- 5 files changed, 94 insertions(+), 40 deletions(-) create mode 100644 src/data/tileBudget.js create mode 100644 src/data/tileBudget.test.mjs diff --git a/scripts/format-scope.json b/scripts/format-scope.json index eee546dd54..9b82af4b78 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -79,6 +79,8 @@ "src/data/terrainHeightsProxy.test.mjs", "src/data/tomtomTiles.js", "src/data/tomtomTiles.test.mjs", + "src/data/tileBudget.js", + "src/data/tileBudget.test.mjs", "src/data/firmsCsv.js", "src/data/firmsCsv.test.mjs", "src/tooling/environmentProviders.test.mjs", diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 189192f10e..748f11d44f 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -113,12 +113,16 @@ "traffic-provider": { "runtime": "node", "exports": ["./server/providers/traffic"], - "modules": ["server/providers/traffic.js", "src/data/tomtomTiles.js"], + "modules": [ + "server/providers/traffic.js", + "src/data/tomtomTiles.js", + "src/data/tileBudget.js" + ], "external": [] }, "traffic-source": { "exports": ["./sources/traffic"], - "modules": ["src/data/tomtomTiles.js"], + "modules": ["src/data/tomtomTiles.js", "src/data/tileBudget.js"], "external": [] }, "firms-csv": { @@ -1009,6 +1013,7 @@ "src/data/cameraSensitivity.js", "src/data/flowMatch.js", "src/data/tomtomTiles.js", + "src/data/tileBudget.js", "src/data/trafficBounds.js", "src/data/trafficFlowStyle.js", "src/data/trafficPresetStyle.js", @@ -1424,6 +1429,7 @@ "src/data/telegeographySubmarineCables.js", "src/data/terrainHeights.js", "src/data/tomtomTiles.js", + "src/data/tileBudget.js", "src/data/tr3bRegistry.js", "src/data/trackedCamera.js", "src/data/trackedModelRegime.js", @@ -2071,6 +2077,7 @@ "src/data/scenePick.js", "src/data/spriteOrder.js", "src/data/tomtomTiles.js", + "src/data/tileBudget.js", "src/data/tr3bRegistry.js", "src/data/trackedCamera.js", "src/data/trackedModelRegime.js", @@ -2707,6 +2714,7 @@ "exports": ["./layers/traffic/source"], "modules": [ "src/data/tomtomTiles.js", + "src/data/tileBudget.js", "src/layers/traffic/flowDecode.js", "src/layers/traffic/flowSource.js", "src/layers/traffic/source.js", diff --git a/src/data/tileBudget.js b/src/data/tileBudget.js new file mode 100644 index 0000000000..dcc44a28c7 --- /dev/null +++ b/src/data/tileBudget.js @@ -0,0 +1,53 @@ +/** + * @file Upstream-request accounting shared by the keyed tile proxies. + * + * A soft cap per UTC period, persisted as `{date, count}` so it survives a + * restart. Nothing here is provider-specific: the caller picks the period by + * the key it passes, and decides what happens over the cap. + * + * Zero dependencies and Cesium-free, so providers and browser helpers can + * import it and node:test can exercise it directly. + * + * @module data/tileBudget + */ + +/** + * UTC calendar-day key for budget bucketing. + * + * @param {number} [epochMs=Date.now()] - Timestamp in ms. + * @returns {string} 'YYYY-MM-DD' in UTC. + */ +export function utcDayKey(epochMs = Date.now()) { + return new Date(epochMs).toISOString().slice(0, 10); +} + +/** + * Normalize a persisted budget state against today's UTC day key. + * Rolls the counter to zero on day change; replaces missing/corrupt state. + * Returns the SAME object when it is already valid for `dayKey` (cheap to + * call on every request). + * + * @param {{date:string, count:number}|null|undefined} state - Persisted state. + * @param {string} dayKey - Today's UTC day key (from `utcDayKey`). + * @returns {{date:string, count:number}} Valid state for `dayKey`. + */ +export function normalizeBudget(state, dayKey) { + const valid = + Boolean(state) && + state.date === dayKey && + Number.isFinite(state.count) && + state.count >= 0; + return valid ? state : { date: dayKey, count: 0 }; +} + +/** + * Whether the daily soft cap has been reached. + * + * @param {{count:number}} state - Normalized budget state. + * @param {number} limit - Daily tile budget; non-positive/invalid never blocks. + * @returns {boolean} True when `count >= limit`. + */ +export function isOverBudget(state, limit) { + if (!Number.isFinite(limit) || limit <= 0) return false; + return state.count >= limit; +} diff --git a/src/data/tileBudget.test.mjs b/src/data/tileBudget.test.mjs new file mode 100644 index 0000000000..fa48440bbd --- /dev/null +++ b/src/data/tileBudget.test.mjs @@ -0,0 +1,26 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { isOverBudget, normalizeBudget, utcDayKey } from './tileBudget.js'; +import * as tomtom from './tomtomTiles.js'; + +test('tile budget helpers live in one module and TomTom re-exports them', () => { + assert.equal(tomtom.utcDayKey, utcDayKey); + assert.equal(tomtom.normalizeBudget, normalizeBudget); + assert.equal(tomtom.isOverBudget, isOverBudget); +}); + +test('normalizeBudget keeps a valid state and resets another period', () => { + const state = { date: '2026-09-24', count: 3 }; + assert.equal(normalizeBudget(state, '2026-09-24'), state); + assert.deepEqual(normalizeBudget(state, '2026-09-25'), { + date: '2026-09-25', + count: 0, + }); + assert.deepEqual( + normalizeBudget({ date: '2026-09-24', count: -1 }, '2026-09-24'), + { + date: '2026-09-24', + count: 0, + }, + ); +}); diff --git a/src/data/tomtomTiles.js b/src/data/tomtomTiles.js index af4fc95b3b..a1dbc18cb7 100644 --- a/src/data/tomtomTiles.js +++ b/src/data/tomtomTiles.js @@ -131,42 +131,7 @@ export function tilesForBounds(bounds, zoom = 12, { maxTiles = 64 } = {}) { // ─── Daily budget accounting ─────────────────────────────── /** - * UTC calendar-day key for budget bucketing. - * - * @param {number} [epochMs=Date.now()] - Timestamp in ms. - * @returns {string} 'YYYY-MM-DD' in UTC. + * Re-exported from `./tileBudget.js`, which keyed tile proxies share. The + * traffic provider and its tests keep one import for tile math and budget. */ -export function utcDayKey(epochMs = Date.now()) { - return new Date(epochMs).toISOString().slice(0, 10); -} - -/** - * Normalize a persisted budget state against today's UTC day key. - * Rolls the counter to zero on day change; replaces missing/corrupt state. - * Returns the SAME object when it is already valid for `dayKey` (cheap to - * call on every request). - * - * @param {{date:string, count:number}|null|undefined} state - Persisted state. - * @param {string} dayKey - Today's UTC day key (from `utcDayKey`). - * @returns {{date:string, count:number}} Valid state for `dayKey`. - */ -export function normalizeBudget(state, dayKey) { - const valid = - Boolean(state) && - state.date === dayKey && - Number.isFinite(state.count) && - state.count >= 0; - return valid ? state : { date: dayKey, count: 0 }; -} - -/** - * Whether the daily soft cap has been reached. - * - * @param {{count:number}} state - Normalized budget state. - * @param {number} limit - Daily tile budget; non-positive/invalid never blocks. - * @returns {boolean} True when `count >= limit`. - */ -export function isOverBudget(state, limit) { - if (!Number.isFinite(limit) || limit <= 0) return false; - return state.count >= limit; -} +export { utcDayKey, normalizeBudget, isOverBudget } from './tileBudget.js'; From b09db551495e2c9e51c8ff30c903f9e1a4c851c3 Mon Sep 17 00:00:00 2001 From: daikaginza Date: Mon, 28 Sep 2026 11:53:13 +0700 Subject: [PATCH 02/61] fix(server): declare the method contract on the three read-only query proxies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /api/opensky, /api/adsblol/mil and /api/route answered any verb with the same body while ignoring the request entirely. Measured against a running server before the change: POST /api/opensky returned 200 with 833,759 bytes of live state vectors, POST /api/adsblol/mil returned 47,372 bytes. Their siblings do not: /api/geocode, /api/weather and /api/transit answer 405, and /api/overpass is deliberately POST-only. These three are read-only query proxies, so they now answer 405 to anything but GET, using the wording and shape /api/geocode already uses. The refusal comes first, before rate limiting and before any upstream call, which the tests assert by stubbing fetch to throw. Scope, stated plainly: this is a consistency and intent fix. No rate limiter was being bypassed — /api/route already limits every request regardless of verb, and the two aircraft routes have no limiter at all, only 9s and 12s server-side caches that bound upstream cost for any method. One existing fixture in src/search/geospatial.test.mjs built a request without a method, which a real Node request always has; it now sets GET. Verified on a running server after the change: GET still 200 on all three, POST 405 on all three, /api/overpass and the other proxies unchanged. Suite goes from 5090 to 5092 tests, 0 failures. --- docs/CURRENT-STATE.md | 1 + server/providers/aircraft/adsb-lol.js | 7 +++++++ server/providers/aircraft/opensky.js | 8 ++++++++ server/providers/places/routes.js | 7 +++++++ src/search/geospatial.test.mjs | 6 +++++- src/tooling/liveProviders.test.mjs | 23 +++++++++++++++++++++++ src/tooling/placeProviders.test.mjs | 19 +++++++++++++++++++ 7 files changed, 70 insertions(+), 1 deletion(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 22ce1eb3b2..15e159ac8d 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4072,6 +4072,7 @@ are omitted rather than framing the wrong part of the globe. - `/api/overpass` is bounded by body/response caps, per-client/global rate limits, concurrency limits, operator-configured upstreams, in-flight dedupe, cache bounds, and static validation that every selector is spatially bounded. - `/api/military-installations` uses an independent limiter with the same 90-per-client/300-global one-minute bounds, so viewport installation refreshes never consume `/api/overpass` annotation capacity. - `/api/route` proxies bounded OSRM route requests for annotation routes, with profile allowlisting, distance caps, response caps, caching, and sanitized "no route found" errors. +- `/api/opensky`, `/api/adsblol/mil`, and `/api/route` are read-only query proxies and answer `405 Method Not Allowed` to anything but `GET`, as `/api/geocode` and the other query proxies already did. The refusal precedes rate limiting and any upstream call. - Track endpoints: `/api/ais-live/track?mmsi=` (server-accumulated ring buffers; sub-route handled before the rows snapshot), `/api/opensky-track?icao24=` (OAuth, 60s cache, sanitized errors, independent OpenSky credit bucket), `/api/adsblol/trace?hex=` (60s cache, 5MB cap, ODbL attribution required in UI). - Realtime debug logs redact API keys, bearer tokens, client secrets, and image data URLs before writing to disk; request bodies are size-capped. - `/api/realtime/debug-log` enforces an always-on 120-per-client/400-global one-minute limiter (not the opt-in `GEV_RATELIMIT_OPENAI_PER_MIN` bucket the cost-bearing OpenAI routes share), appends asynchronously through a serialized queue, and rotates `realtime-conversations.jsonl` at 32 MB keeping one prior generation, so the sink is bounded at twice that regardless of session length. A malformed record answers 400 and a failed write 500, both with a fixed message. diff --git a/server/providers/aircraft/adsb-lol.js b/server/providers/aircraft/adsb-lol.js index fc5ab0bd3a..80140bb56b 100644 --- a/server/providers/aircraft/adsb-lol.js +++ b/server/providers/aircraft/adsb-lol.js @@ -68,6 +68,13 @@ export function adsbLolProxy() { const installMiddleware = (server) => { server.middlewares.use('/api/adsblol/mil', async (req, res) => { + // Read-only snapshot endpoint; match the method contract its sibling + // query proxies already declare instead of serving every verb alike. + if (req.method !== 'GET') { + res.writeHead(405, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ error: 'Method Not Allowed' })); + return; + } try { const now = Date.now(); if (_cache && now - _cacheAt < CACHE_MS) { diff --git a/server/providers/aircraft/opensky.js b/server/providers/aircraft/opensky.js index 612d01e11a..aa0dad2680 100644 --- a/server/providers/aircraft/opensky.js +++ b/server/providers/aircraft/opensky.js @@ -350,6 +350,14 @@ function openSkySourceIsStale(sourceEpochMs, now = Date.now()) { export function openSkyProxy() { const installMiddleware = (server) => { server.middlewares.use('/api/opensky', async (req, res) => { + // Read-only snapshot endpoint: state the method contract the way + // /api/geocode and the other query proxies state it, rather than + // answering any verb with the same body and ignoring the request body. + if (req.method !== 'GET') { + res.writeHead(405, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ error: 'Method Not Allowed' })); + return; + } try { const requestedMode = normalizeOpenSkyAuthMode( process.env.OPENSKY_AUTH_MODE, diff --git a/server/providers/places/routes.js b/server/providers/places/routes.js index 42e24ad325..8e837fcd4e 100644 --- a/server/providers/places/routes.js +++ b/server/providers/places/routes.js @@ -227,6 +227,13 @@ export function installRouteMiddleware( // only shape that asks the upstream for them. A response WITHOUT steps is // byte for byte what this endpoint has always returned. middlewares.use('/api/route', async (req, res) => { + // The documented shape above is a GET with query parameters; say so, + // the way the other query proxies do, instead of answering any verb. + if (req.method !== 'GET') { + res.writeHead(405, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ error: 'Method Not Allowed' })); + return; + } const fail = (msg) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ ok: false, error: msg })); diff --git a/src/search/geospatial.test.mjs b/src/search/geospatial.test.mjs index be846bb36b..dbedbe53f6 100644 --- a/src/search/geospatial.test.mjs +++ b/src/search/geospatial.test.mjs @@ -209,7 +209,11 @@ test('routing middleware uses configured OSRM servers while retaining request bo const request = async (query) => { let payload; await handler( - { url: `/?${query}`, socket: { remoteAddress: '127.0.0.1' } }, + { + url: `/?${query}`, + method: 'GET', + socket: { remoteAddress: '127.0.0.1' }, + }, { writeHead() {}, end(body) { diff --git a/src/tooling/liveProviders.test.mjs b/src/tooling/liveProviders.test.mjs index 38953eff95..c25c445d4d 100644 --- a/src/tooling/liveProviders.test.mjs +++ b/src/tooling/liveProviders.test.mjs @@ -381,3 +381,26 @@ test('track backfill proxy returns 502 on an oversized upstream body and caches assert.equal(res2.statusCode, 502); assert.equal(callCount, 1); }); + +test('the aircraft snapshot routes decline a non-GET before any upstream work', async (t) => { + // Both routes answered every verb with the full snapshot, unlike the query + // proxies beside them, so nothing said whether a body was read or ignored. + // A stubbed fetch that throws proves the refusal happens before the handler + // reaches upstream, rather than after paying for the work and discarding it. + t.mock.method(globalThis, 'fetch', async (url) => { + throw new Error(`upstream must not be reached: ${url}`); + }); + const cases = [ + [install(providers.openSkyProxy()), '/api/opensky'], + [install(providers.adsbLolProxy()), '/api/adsblol/mil'], + ]; + for (const [request, route] of cases) { + for (const method of ['POST', 'PUT', 'DELETE', 'PATCH']) { + const response = await request(route, '/', method); + assert.equal(response.statusCode, 405, `${method} ${route}`); + assert.deepEqual(JSON.parse(response.body), { + error: 'Method Not Allowed', + }); + } + } +}); diff --git a/src/tooling/placeProviders.test.mjs b/src/tooling/placeProviders.test.mjs index 78d311369d..968c5a9fa0 100644 --- a/src/tooling/placeProviders.test.mjs +++ b/src/tooling/placeProviders.test.mjs @@ -482,3 +482,22 @@ test('the upstream host is pinned: a redirect is refused, not followed', async ( await request('/api/route', '?profile=car&coords=-97,30;-97.01,30.01'); assert.deepEqual(seen, ['error'], 'a redirect would escape the pinned host'); }); + +test('the routing proxy declines a non-GET before rate limiting or upstream', async (t) => { + // The documented shape is a GET with query parameters, but every verb was + // answered alike. Refuse first: a stubbed fetch that throws shows the + // rejection costs neither an upstream call nor a rate-limit slot. + const request = install(installRouteMiddleware); + t.mock.method(globalThis, 'fetch', async () => { + throw new Error('upstream must not be reached'); + }); + for (const method of ['POST', 'PUT', 'DELETE', 'PATCH']) { + const response = await request( + '/api/route', + '?profile=car&coords=-97,30;-97.01,30.01', + method, + ); + assert.equal(response.statusCode, 405, method); + assert.deepEqual(response.body, { error: 'Method Not Allowed' }); + } +}); From fb6b4e34f0aab85c715146739152d753d5a3efa8 Mon Sep 17 00:00:00 2001 From: daikaginza Date: Mon, 28 Sep 2026 13:16:17 +0700 Subject: [PATCH 03/61] docs: changelog entry for the read-only proxy method contract (#794) --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58103d04da..7885f0131c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +- The read-only query proxies state their method contract. `/api/opensky`, + `/api/adsblol/mil` and `/api/route` answered any verb with the same body + while ignoring the request; they now answer `405 Method Not Allowed` to + anything but `GET`, the way `/api/geocode` and the other query proxies + already did, and declare `Allow: GET` with it the way `/api/radio/stations` + does. The refusal precedes rate limiting and any upstream call + (daikaginza, #794). + - Public Overpass instances are no longer used by default. Street Traffic roads come from TomTom flow tiles, OpenFreeMap vector tiles, or both, chosen on the layer row (TomTom / OSM / Hybrid) or with `?trafficRoads=`. With a From 2e5dfce1af9b07664005bd1bd77e5bcb4ccf0ba4 Mon Sep 17 00:00:00 2001 From: daikaginza Date: Tue, 29 Sep 2026 10:56:20 +0700 Subject: [PATCH 04/61] fix(server): declare Allow: GET on the new 405 responses RFC 9110 section 15.5.6 requires a 405 to name the methods it accepts, and /api/radio/stations already does this in-tree. Thanks to kvnloo for catching it on review. The same gap on the pre-existing handlers is tracked in #809 and is deliberately left alone here. --- docs/CURRENT-STATE.md | 2 +- server/providers/aircraft/adsb-lol.js | 5 ++++- server/providers/aircraft/opensky.js | 5 ++++- server/providers/places/routes.js | 2 +- src/tooling/liveProviders.test.mjs | 3 +++ src/tooling/placeProviders.test.mjs | 2 ++ 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 15e159ac8d..6e30399206 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4072,7 +4072,7 @@ are omitted rather than framing the wrong part of the globe. - `/api/overpass` is bounded by body/response caps, per-client/global rate limits, concurrency limits, operator-configured upstreams, in-flight dedupe, cache bounds, and static validation that every selector is spatially bounded. - `/api/military-installations` uses an independent limiter with the same 90-per-client/300-global one-minute bounds, so viewport installation refreshes never consume `/api/overpass` annotation capacity. - `/api/route` proxies bounded OSRM route requests for annotation routes, with profile allowlisting, distance caps, response caps, caching, and sanitized "no route found" errors. -- `/api/opensky`, `/api/adsblol/mil`, and `/api/route` are read-only query proxies and answer `405 Method Not Allowed` to anything but `GET`, as `/api/geocode` and the other query proxies already did. The refusal precedes rate limiting and any upstream call. +- `/api/opensky`, `/api/adsblol/mil`, and `/api/route` are read-only query proxies and answer `405 Method Not Allowed` to anything but `GET`, as `/api/geocode` and the other query proxies already did, declaring `Allow: GET` with it as `/api/radio/stations` does. The refusal precedes rate limiting and any upstream call. - Track endpoints: `/api/ais-live/track?mmsi=` (server-accumulated ring buffers; sub-route handled before the rows snapshot), `/api/opensky-track?icao24=` (OAuth, 60s cache, sanitized errors, independent OpenSky credit bucket), `/api/adsblol/trace?hex=` (60s cache, 5MB cap, ODbL attribution required in UI). - Realtime debug logs redact API keys, bearer tokens, client secrets, and image data URLs before writing to disk; request bodies are size-capped. - `/api/realtime/debug-log` enforces an always-on 120-per-client/400-global one-minute limiter (not the opt-in `GEV_RATELIMIT_OPENAI_PER_MIN` bucket the cost-bearing OpenAI routes share), appends asynchronously through a serialized queue, and rotates `realtime-conversations.jsonl` at 32 MB keeping one prior generation, so the sink is bounded at twice that regardless of session length. A malformed record answers 400 and a failed write 500, both with a fixed message. diff --git a/server/providers/aircraft/adsb-lol.js b/server/providers/aircraft/adsb-lol.js index 80140bb56b..1e5565832d 100644 --- a/server/providers/aircraft/adsb-lol.js +++ b/server/providers/aircraft/adsb-lol.js @@ -71,7 +71,10 @@ export function adsbLolProxy() { // Read-only snapshot endpoint; match the method contract its sibling // query proxies already declare instead of serving every verb alike. if (req.method !== 'GET') { - res.writeHead(405, { 'Content-Type': 'application/json' }); + res.writeHead(405, { + 'Content-Type': 'application/json', + Allow: 'GET', + }); res.end(JSON.stringify({ error: 'Method Not Allowed' })); return; } diff --git a/server/providers/aircraft/opensky.js b/server/providers/aircraft/opensky.js index aa0dad2680..679548300a 100644 --- a/server/providers/aircraft/opensky.js +++ b/server/providers/aircraft/opensky.js @@ -354,7 +354,10 @@ export function openSkyProxy() { // /api/geocode and the other query proxies state it, rather than // answering any verb with the same body and ignoring the request body. if (req.method !== 'GET') { - res.writeHead(405, { 'Content-Type': 'application/json' }); + res.writeHead(405, { + 'Content-Type': 'application/json', + Allow: 'GET', + }); res.end(JSON.stringify({ error: 'Method Not Allowed' })); return; } diff --git a/server/providers/places/routes.js b/server/providers/places/routes.js index 8e837fcd4e..2c67f1f5c9 100644 --- a/server/providers/places/routes.js +++ b/server/providers/places/routes.js @@ -230,7 +230,7 @@ export function installRouteMiddleware( // The documented shape above is a GET with query parameters; say so, // the way the other query proxies do, instead of answering any verb. if (req.method !== 'GET') { - res.writeHead(405, { 'Content-Type': 'application/json' }); + res.writeHead(405, { 'Content-Type': 'application/json', Allow: 'GET' }); res.end(JSON.stringify({ error: 'Method Not Allowed' })); return; } diff --git a/src/tooling/liveProviders.test.mjs b/src/tooling/liveProviders.test.mjs index c25c445d4d..856a528a2e 100644 --- a/src/tooling/liveProviders.test.mjs +++ b/src/tooling/liveProviders.test.mjs @@ -398,6 +398,9 @@ test('the aircraft snapshot routes decline a non-GET before any upstream work', for (const method of ['POST', 'PUT', 'DELETE', 'PATCH']) { const response = await request(route, '/', method); assert.equal(response.statusCode, 405, `${method} ${route}`); + // RFC 9110 section 15.5.6 requires a 405 to name the methods it does + // accept, which is what `/api/radio/stations` already does in-tree. + assert.equal(response.headers.allow, 'GET', `${method} ${route}`); assert.deepEqual(JSON.parse(response.body), { error: 'Method Not Allowed', }); diff --git a/src/tooling/placeProviders.test.mjs b/src/tooling/placeProviders.test.mjs index 968c5a9fa0..afc323efc8 100644 --- a/src/tooling/placeProviders.test.mjs +++ b/src/tooling/placeProviders.test.mjs @@ -498,6 +498,8 @@ test('the routing proxy declines a non-GET before rate limiting or upstream', as method, ); assert.equal(response.statusCode, 405, method); + // RFC 9110 section 15.5.6 requires a 405 to name the methods it accepts. + assert.equal(response.headers.allow, 'GET', method); assert.deepEqual(response.body, { error: 'Method Not Allowed' }); } }); From daed0be99a03d8f416c59617f77c7cea455616eb Mon Sep 17 00:00:00 2001 From: daikaginza Date: Mon, 28 Sep 2026 14:17:20 +0700 Subject: [PATCH 05/61] feat(server): compress the cached OpenSky snapshot for clients that accept gzip The ~860 KB snapshot is held for an adaptive 9-300 s TTL and was served as identity bytes to every request; no response in server/ set Content-Encoding or Vary. Gzip it once per refresh beside the cached body, off the event loop, and return the body and the header that names it together so the two can never disagree. Live against an anonymous snapshot: 874,002 B to 258,012 B, 3.39x, decompressing byte-identical to the uncompressed response. --- docs/CURRENT-STATE.md | 1 + scripts/package-boundaries.json | 1 + server/providers/aircraft/opensky.js | 91 ++++++++++++---- server/providers/common/compress.js | 94 +++++++++++++++++ src/tooling/liveProviders.test.mjs | 113 +++++++++++++++++++- src/tooling/responseCompression.test.mjs | 129 +++++++++++++++++++++++ 6 files changed, 405 insertions(+), 24 deletions(-) create mode 100644 server/providers/common/compress.js create mode 100644 src/tooling/responseCompression.test.mjs diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 22ce1eb3b2..a03d2bd5dc 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4072,6 +4072,7 @@ are omitted rather than framing the wrong part of the globe. - `/api/overpass` is bounded by body/response caps, per-client/global rate limits, concurrency limits, operator-configured upstreams, in-flight dedupe, cache bounds, and static validation that every selector is spatially bounded. - `/api/military-installations` uses an independent limiter with the same 90-per-client/300-global one-minute bounds, so viewport installation refreshes never consume `/api/overpass` annotation capacity. - `/api/route` proxies bounded OSRM route requests for annotation routes, with profile allowlisting, distance caps, response caps, caching, and sanitized "no route found" errors. +- `/api/opensky` negotiates response encoding. The cached global snapshot and the regional adsb.lol fallback are each gzipped once per refresh, so a client that offers gzip receives roughly 860 KB as 250 KB and one that does not receives the same bytes uncompressed; both answers carry `Vary: Accept-Encoding`. Bodies the proxy does not cache — auth failures, cooldown notices — are never sent under a cached response's encoding. - Track endpoints: `/api/ais-live/track?mmsi=` (server-accumulated ring buffers; sub-route handled before the rows snapshot), `/api/opensky-track?icao24=` (OAuth, 60s cache, sanitized errors, independent OpenSky credit bucket), `/api/adsblol/trace?hex=` (60s cache, 5MB cap, ODbL attribution required in UI). - Realtime debug logs redact API keys, bearer tokens, client secrets, and image data URLs before writing to disk; request bodies are size-capped. - `/api/realtime/debug-log` enforces an always-on 120-per-client/400-global one-minute limiter (not the opt-in `GEV_RATELIMIT_OPENAI_PER_MIN` bucket the cost-bearing OpenAI routes share), appends asynchronously through a serialized queue, and rotates `realtime-conversations.jsonl` at 32 MB keeping one prior generation, so the sink is bounded at twice that regardless of session length. A malformed record answers 400 and a failed write 500, both with a fixed message. diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 276b9e0db9..363966ba91 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -35,6 +35,7 @@ "exports": ["./server/providers/live"], "modules": [ "server/providers/live.js", + "server/providers/common/compress.js", "server/providers/common/http.js", "server/providers/common/query.js", "server/providers/aircraft/opensky.js", diff --git a/server/providers/aircraft/opensky.js b/server/providers/aircraft/opensky.js index 612d01e11a..a37315b9de 100644 --- a/server/providers/aircraft/opensky.js +++ b/server/providers/aircraft/opensky.js @@ -1,4 +1,5 @@ import { normalizeAdsbLolPointResponse } from '../../../src/data/adsbLolFallback.js'; +import { encodedBody, gzipBody } from '../common/compress.js'; import { coalesceProxyRequest, readResponseJsonCapped, @@ -15,6 +16,12 @@ let _openskyTokenExpiry = 0; let _openskyTokenPromise = null; /** @type {string|null} Cached upstream response body (JSON text). */ let _openskyCacheBody = null; +/** + * @type {Buffer|null} Gzip of `_openskyCacheBody`, written in the same step as + * the body it encodes so the two can never describe different snapshots. Null + * whenever the cached body is too small to be worth a frame. + */ +let _openskyCacheGzip = null; /** @type {number} HTTP status of the cached response. */ let _openskyCacheStatus = 0; /** @type {number} Epoch-ms when the response was cached. */ @@ -271,8 +278,13 @@ async function fetchAdsbLolPointFallback(req) { ADSBLOL_POINT_MAX_RESPONSE_BYTES, ); const normalized = normalizeAdsbLolPointResponse(payload); + const body = JSON.stringify(normalized); const record = { - body: JSON.stringify(normalized), + body, + // Compressed with the body it belongs to, so a cache entry served + // many times pays for the frame once. Entries are bounded by + // ADSBLOL_POINT_CACHE_MAX, so the extra residency is bounded too. + gzip: await gzipBody(body), cachedAt: Date.now(), count: normalized.states.length, }; @@ -301,6 +313,7 @@ async function fetchAdsbLolPointFallback(req) { async function serveAdsbLolPointFallback(req, res, requestedMode, reason) { const fallback = await fetchAdsbLolPointFallback(req); if (!fallback) return false; + const encoded = encodedBody(req, fallback.body, fallback.gzip); res.writeHead(200, { ...buildOpenSkyHeaders({ cacheStatus: fallback.cacheStatus, @@ -311,8 +324,9 @@ async function serveAdsbLolPointFallback(req, res, requestedMode, reason) { 'X-Flight-Source': 'adsb.lol', 'X-Flight-Coverage': `${ADSBLOL_POINT_RADIUS_NM}nm regional fallback`, 'X-Flight-Count': String(fallback.count), + ...encoded.headers, }); - res.end(fallback.body); + res.end(encoded.body); return true; } @@ -380,9 +394,13 @@ export function openSkyProxy() { reason: 'cached', }; const isStale = now - _openskyCacheTime >= _openskyTtlMs; - res.writeHead( - _openskyCacheStatus || 200, - buildOpenSkyHeaders({ + const encoded = encodedBody( + req, + _openskyCacheBody, + _openskyCacheGzip, + ); + res.writeHead(_openskyCacheStatus || 200, { + ...buildOpenSkyHeaders({ cacheStatus: isStale ? 'STALE' : 'HIT', requestedMode: cachedMeta.requestedMode || requestedMode, usedMode: cachedMeta.usedMode || 'unknown', @@ -396,8 +414,9 @@ export function openSkyProxy() { ? (_openskyCooldownUntil - now) / 1000 : undefined, }), - ); - res.end(_openskyCacheBody); + ...encoded.headers, + }); + res.end(encoded.body); return; } // Cooling down with nothing cached (cold start into a rate limit): @@ -507,7 +526,12 @@ export function openSkyProxy() { ) { // Keep the last global snapshot available as a fail-soft cache, // but do not label or render it as a fresh live result. + // The frame is built before either slot is written so the two are + // always published together: a request arriving mid-refresh reads the + // previous body with the previous body's frame, never a mismatch. + const frame = await gzipBody(body); _openskyCacheBody = body; + _openskyCacheGzip = frame; _openskyCacheStatus = upstream.status; _openskyCacheTime = now; _openskyCacheSourceEpochMs = sourceEpochMs; @@ -532,9 +556,13 @@ export function openSkyProxy() { // Serve the last-good body instead of the 429 when we have one — // the layer keeps rendering (STALE-cued) instead of dying. if (_openskyCacheBody && _openskyCacheStatus === 200) { - res.writeHead( - 200, - buildOpenSkyHeaders({ + const encoded = encodedBody( + req, + _openskyCacheBody, + _openskyCacheGzip, + ); + res.writeHead(200, { + ...buildOpenSkyHeaders({ cacheStatus: 'STALE', requestedMode, usedMode, @@ -542,8 +570,9 @@ export function openSkyProxy() { staleSeconds: (now - _openskyCacheTime) / 1000, retryAfterSeconds: cooldownMs / 1000, }), - ); - res.end(_openskyCacheBody); + ...encoded.headers, + }); + res.end(encoded.body); return; } } @@ -616,7 +645,10 @@ export function openSkyProxy() { // Only cache successful responses — error responses (401/403/429/5xx) // should not be served from cache on subsequent requests if (upstream.ok) { + // Published as a pair, for the reason given at the other cache fill. + const frame = await gzipBody(body); _openskyCacheBody = body; + _openskyCacheGzip = frame; _openskyCacheStatus = upstream.status; _openskyCacheTime = now; _openskyCacheSourceEpochMs = sourceEpochMs; @@ -635,16 +667,26 @@ export function openSkyProxy() { _openskyCooldownUntil = 0; } - res.writeHead( - upstream.status, - buildOpenSkyHeaders({ + // Only the branch above caches, so the gzip slot belongs to this body + // only when this body is the one it just stored. An error response + // (401/403/429/5xx) is not cached and must not borrow the previous + // snapshot's frame — identity comparison, not `upstream.ok`, because it + // stays correct if the caching condition above ever changes. + const encoded = encodedBody( + req, + body, + _openskyCacheBody === body ? _openskyCacheGzip : null, + ); + res.writeHead(upstream.status, { + ...buildOpenSkyHeaders({ cacheStatus: 'MISS', requestedMode, usedMode, reason, }), - ); - res.end(body); + ...encoded.headers, + }); + res.end(encoded.body); } catch (e) { console.error('[OpenSky Proxy]', e.message); if (_openskyCacheBody) { @@ -655,17 +697,22 @@ export function openSkyProxy() { usedMode: 'unknown', reason: 'cached_stale', }; - res.writeHead( - _openskyCacheStatus || 200, - buildOpenSkyHeaders({ + const encoded = encodedBody( + req, + _openskyCacheBody, + _openskyCacheGzip, + ); + res.writeHead(_openskyCacheStatus || 200, { + ...buildOpenSkyHeaders({ cacheStatus: 'STALE', requestedMode: cachedMeta.requestedMode || OPENSKY_AUTH_MODE_DEFAULT, usedMode: cachedMeta.usedMode || 'unknown', reason: cachedMeta.reason || 'cached_stale', }), - ); - res.end(_openskyCacheBody); + ...encoded.headers, + }); + res.end(encoded.body); return; } const requestedMode = normalizeOpenSkyAuthMode( diff --git a/server/providers/common/compress.js b/server/providers/common/compress.js new file mode 100644 index 0000000000..7d93b35948 --- /dev/null +++ b/server/providers/common/compress.js @@ -0,0 +1,94 @@ +import { gzip } from 'node:zlib'; +import { promisify } from 'node:util'; + +const gzipAsync = promisify(gzip); + +/** + * Response compression for proxies that already hold a whole body in memory. + * + * Deliberately not a middleware. Two response paths in this tree must never be + * wrapped: `cctv/media.js` streams a piped body and answers byte-range requests + * with 206, and `wind/gfs.js` also serves ranges — a wrapper that buffered or + * re-encoded those would break playback and range semantics. Seven providers + * additionally forward an upstream `content-type` verbatim, including already + * compressed binary formats that gzip would only make larger. + * + * So compression is opt-in at the call site, for bodies the proxy holds and + * knows to be text. The failure mode of forgetting a site is a response that is + * merely uncompressed, never a corrupt one — but only as long as the encoded + * body and its `Content-Encoding` are chosen together, which is why + * `encodedBody` returns both rather than exposing them separately. + */ + +/** Below this, a gzip frame costs more than the bytes it saves. */ +const MIN_COMPRESSED_BYTES = 1024; + +/** + * Whether the client offered gzip in `Accept-Encoding`. + * + * Anything this cannot read confidently — a missing header, a malformed + * quality value, the `x-gzip` alias — reads as "no", because the fallback is an + * identity response every client can decode. + * + * @param {import('node:http').IncomingMessage} request + * @returns {boolean} + */ +export function acceptsGzip(request) { + const header = request?.headers?.['accept-encoding']; + if (typeof header !== 'string') return false; + return header.split(',').some((part) => { + const [token, ...parameters] = part.split(';'); + if (token.trim().toLowerCase() !== 'gzip') return false; + // `q=0` is the one way a client can name an encoding and still refuse it + // (RFC 9110 section 12.4.2). + const quality = parameters + .map((parameter) => parameter.trim().toLowerCase()) + .find((parameter) => parameter.startsWith('q=')); + return quality === undefined || Number.parseFloat(quality.slice(2)) > 0; + }); +} + +/** + * Gzip a body once, for callers that cache it and serve it many times. + * + * OpenSky's snapshot is ~860 KB and is held for the cache TTL, so this is paid + * per refresh rather than per request. It runs off the event loop on purpose: + * on that snapshot the synchronous call stalls every other in-flight request by + * 11 ms, while this stalls them by under 1 ms and costs the caller — which is + * already waiting on an upstream fetch — about 5 ms more of its own latency. + * + * Returns null when the body is too small to be worth a frame, so callers can + * store the result directly and treat null as "serve identity". + * + * @param {string|Buffer} body - the exact bytes the identity response sends. + * @returns {Promise} + */ +export async function gzipBody(body) { + if (body == null) return null; + const raw = Buffer.isBuffer(body) ? body : Buffer.from(String(body)); + if (raw.byteLength < MIN_COMPRESSED_BYTES) return null; + const compressed = await gzipAsync(raw); + return compressed.byteLength < raw.byteLength ? compressed : null; +} + +/** + * Pick the body to send and the headers that describe it, together. + * + * `Vary: Accept-Encoding` is set on both branches, not only the compressed one: + * a cache that stored an identity response without it would later hand those + * bytes to a client that asked for gzip, and vice versa. + * + * @param {import('node:http').IncomingMessage} request + * @param {string|Buffer} identity - the uncompressed body. + * @param {Buffer|null} compressed - `gzipBody(identity)`, or null. + * @returns {{body: string|Buffer, headers: Record}} + */ +export function encodedBody(request, identity, compressed) { + if (compressed && acceptsGzip(request)) { + return { + body: compressed, + headers: { 'Content-Encoding': 'gzip', Vary: 'Accept-Encoding' }, + }; + } + return { body: identity, headers: { Vary: 'Accept-Encoding' } }; +} diff --git a/src/tooling/liveProviders.test.mjs b/src/tooling/liveProviders.test.mjs index 38953eff95..94bbb6a27b 100644 --- a/src/tooling/liveProviders.test.mjs +++ b/src/tooling/liveProviders.test.mjs @@ -1,6 +1,7 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { once } from 'node:events'; +import { gunzipSync } from 'node:zlib'; import { WebSocketServer } from 'ws'; import { setTimeout as delay } from 'node:timers/promises'; import * as providers from '../../server/providers/live.js'; @@ -15,7 +16,7 @@ function install(plugin, preview = false) { }, }, }); - return async (route, url = '/', method = 'GET') => { + return async (route, url = '/', method = 'GET', headers = {}) => { assert.ok(routes.has(route), `registered route: ${route}`); const response = { statusCode: 200, @@ -32,7 +33,7 @@ function install(plugin, preview = false) { this.body = body; }, }; - await routes.get(route)({ url, method }, response); + await routes.get(route)({ url, method, headers }, response); return response; }; } @@ -381,3 +382,111 @@ test('track backfill proxy returns 502 on an oversized upstream body and caches assert.equal(res2.statusCode, 502); assert.equal(callCount, 1); }); + +test('the OpenSky snapshot is compressed for clients that ask, and an error body never inherits the cached frame', async (t) => { + environment(t, { + OPENSKY_AUTH_MODE: 'anon', + OPENSKY_CLIENT_ID: undefined, + OPENSKY_CLIENT_SECRET: undefined, + OPENSKY_USERNAME: undefined, + OPENSKY_PASSWORD: undefined, + }); + let now = Date.now(); + t.mock.method(Date, 'now', () => now); + t.mock.method(console, 'log', () => {}); + t.mock.method(console, 'error', () => {}); + + let upstreamStatus = 200; + let snapshotAgeMs = 0; + t.mock.method(globalThis, 'fetch', async (url) => { + if (url.includes('/lat/')) + return Response.json({ + now: now / 1000, + ac: Array.from({ length: 200 }, (_, index) => ({ + hex: `abc${index}`, + lat: 30, + lon: -97, + alt_baro: 10000, + })), + }); + assert.ok(url.includes('/states/'), `unexpected upstream call: ${url}`); + if (upstreamStatus !== 200) + return new Response('{"error":"upstream"}', { status: upstreamStatus }); + const sourceSeconds = Math.floor((now - snapshotAgeMs) / 1000); + // A healthy credit budget, so the proxy keeps its 9 s base TTL and the + // clock advances below are unambiguously past it. + return Response.json( + { + time: sourceSeconds, + states: Array.from({ length: 200 }, (_, index) => [ + `abc${index}`, + 'CALLSIGN', + 'United States', + sourceSeconds, + -97.7, + 30.1, + 10000, + ]), + }, + { headers: { 'x-rate-limit-remaining': '4000' } }, + ); + }); + + // A module instance of its own: the snapshot cache, its frame and the + // adaptive TTL are module state, and this test reasons about all three. + const isolated = await import( + `../../server/providers/aircraft/opensky.js?compression=${now}` + ); + const states = install(isolated.openSkyProxy()); + const compressed = await states('/api/opensky', '/', 'GET', { + 'accept-encoding': 'gzip, deflate, br', + }); + assert.equal(compressed.statusCode, 200); + assert.equal(compressed.headers['content-encoding'], 'gzip'); + assert.equal(compressed.headers.vary, 'Accept-Encoding'); + assert.ok(Buffer.isBuffer(compressed.body)); + + // Same snapshot from cache, this time to a client that offered nothing: the + // identity bytes, and the compressed frame above must decode to exactly them. + const identity = await states('/api/opensky'); + assert.equal(identity.headers['x-opensky-cache'], 'HIT'); + assert.equal(identity.headers['content-encoding'], undefined); + assert.equal(identity.headers.vary, 'Accept-Encoding'); + assert.equal(gunzipSync(compressed.body).toString(), identity.body); + + // A client that names gzip and refuses it with q=0 is a non-gzip client. + const refused = await states('/api/opensky', '/', 'GET', { + 'accept-encoding': 'gzip;q=0', + }); + assert.equal(refused.headers['content-encoding'], undefined); + assert.equal(refused.body, identity.body); + + // An upstream rejection is not cached, so it has no frame of its own. It must + // not be sent under the previous snapshot's Content-Encoding. + upstreamStatus = 403; + now += 60000; // past the 9 s base TTL this fresh instance starts with + const rejected = await states('/api/opensky', '/', 'GET', { + 'accept-encoding': 'gzip', + }); + assert.equal(rejected.statusCode, 403); + assert.equal(rejected.headers['content-encoding'], undefined); + assert.ok(JSON.parse(rejected.body).error, 'a readable error body'); + + // The regional fallback is a fifth body this route can answer with. It is + // cached the same way and so it negotiates the same way: a snapshot too old + // to serve hands the request to adsb.lol, compressed. + upstreamStatus = 200; + snapshotAgeMs = 3600000; + now += 60000; + const regional = await states('/api/opensky', '?lat=30&lon=-97', 'GET', { + 'accept-encoding': 'gzip', + }); + assert.equal(regional.statusCode, 200); + assert.equal(regional.headers['x-flight-source'], 'adsb.lol'); + assert.equal(regional.headers['content-encoding'], 'gzip'); + assert.equal(regional.headers.vary, 'Accept-Encoding'); + assert.equal( + JSON.parse(gunzipSync(regional.body).toString()).states.length, + 200, + ); +}); diff --git a/src/tooling/responseCompression.test.mjs b/src/tooling/responseCompression.test.mjs new file mode 100644 index 0000000000..92fee57a37 --- /dev/null +++ b/src/tooling/responseCompression.test.mjs @@ -0,0 +1,129 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { gunzipSync } from 'node:zlib'; +import { + acceptsGzip, + encodedBody, + gzipBody, +} from '../../server/providers/common/compress.js'; + +/** A request shaped like the one Node hands a middleware. */ +function request(acceptEncoding) { + return { + url: '/api/opensky', + method: 'GET', + headers: + acceptEncoding === undefined ? {} : { 'accept-encoding': acceptEncoding }, + }; +} + +/** Repetitive JSON, the shape of an actual snapshot body. */ +function snapshotBody(states = 200) { + return JSON.stringify({ + time: 1700000000, + states: Array.from({ length: states }, (_, index) => [ + `abc${index}`, + 'CALLSIGN', + 'United States', + 1700000000, + 30.1, + -97.7, + 10000, + ]), + }); +} + +/** + * Deterministic high-entropy bytes. Random data would do, but a seeded sequence + * keeps the "gzip made it bigger" assertion from depending on luck. + */ +function incompressibleBytes(length) { + const bytes = Buffer.alloc(length); + let state = 123456789; + for (let index = 0; index < length; index += 1) { + state = (state * 1103515245 + 12345) % 2147483648; + bytes[index] = (state >>> 16) & 0xff; + } + return bytes; +} + +test('accept-encoding is read the way clients actually write it', () => { + assert.equal(acceptsGzip(request('gzip')), true); + assert.equal(acceptsGzip(request('gzip, deflate, br')), true); + assert.equal(acceptsGzip(request('br;q=1.0, gzip;q=0.8')), true); + assert.equal(acceptsGzip(request('GZIP')), true); + assert.equal(acceptsGzip(request(' gzip ')), true); + + assert.equal(acceptsGzip(request('br, deflate')), false); + assert.equal(acceptsGzip(request('identity')), false); + assert.equal(acceptsGzip(request('')), false); + assert.equal(acceptsGzip(request(undefined)), false); + assert.equal(acceptsGzip({}), false); + assert.equal(acceptsGzip(undefined), false); + + // A quality of zero names gzip and refuses it (RFC 9110 section 12.4.2), + // and an unreadable quality falls back to the encoding every client accepts. + assert.equal(acceptsGzip(request('gzip;q=0')), false); + assert.equal(acceptsGzip(request('gzip;q=0.000')), false); + assert.equal(acceptsGzip(request('gzip;q=bogus')), false); + assert.equal(acceptsGzip(request('gzip;q=0.001')), true); + + // `gzip` is not matched as a substring of a neighbouring token. + assert.equal(acceptsGzip(request('x-gzip')), false); + assert.equal(acceptsGzip(request('gzipped')), false); +}); + +test('a body is only compressed when compression pays for itself', async () => { + assert.equal(await gzipBody(null), null); + assert.equal(await gzipBody(undefined), null); + assert.equal(await gzipBody(''), null); + assert.equal( + await gzipBody('{"states":[]}'), + null, + 'below the frame threshold', + ); + assert.equal(await gzipBody(Buffer.alloc(1023, 'a')), null, 'one byte short'); + + const identity = snapshotBody(); + assert.ok(identity.length > 1024, 'fixture is worth compressing'); + const compressed = await gzipBody(identity); + assert.ok(Buffer.isBuffer(compressed)); + assert.ok(compressed.byteLength < Buffer.byteLength(identity)); + assert.equal(gunzipSync(compressed).toString(), identity); + + // Buffers are accepted as-is, and data that gzip cannot shrink is refused + // rather than served as a larger response. + assert.ok((await gzipBody(Buffer.from(identity))) !== null); + assert.equal(await gzipBody(incompressibleBytes(4096)), null); +}); + +test('the encoded body and the header that names it are chosen together', async () => { + const identity = snapshotBody(); + const compressed = await gzipBody(identity); + + const negotiated = encodedBody(request('gzip'), identity, compressed); + assert.equal(negotiated.body, compressed); + assert.equal(negotiated.headers['Content-Encoding'], 'gzip'); + assert.equal(negotiated.headers.Vary, 'Accept-Encoding'); + assert.equal(gunzipSync(negotiated.body).toString(), identity); + + // Offered but not wanted: identity bytes, and no Content-Encoding to + // contradict them. + const refused = encodedBody(request('br'), identity, compressed); + assert.equal(refused.body, identity); + assert.equal(refused.headers['Content-Encoding'], undefined); + assert.equal(refused.headers.Vary, 'Accept-Encoding'); + + // Wanted but not available: same answer. + const unavailable = encodedBody(request('gzip'), identity, null); + assert.equal(unavailable.body, identity); + assert.equal(unavailable.headers['Content-Encoding'], undefined); + + // Vary is on both branches: without it a shared cache could hand a stored + // response to a client whose Accept-Encoding it was not selected for. + assert.equal(unavailable.headers.Vary, 'Accept-Encoding'); + assert.equal( + encodedBody(request(undefined), identity, compressed).headers.Vary, + 'Accept-Encoding', + ); +}); From 47b13ab18e4cafc961f049fd361cb0ed29fe51b1 Mon Sep 17 00:00:00 2001 From: daikaginza Date: Mon, 28 Sep 2026 14:18:09 +0700 Subject: [PATCH 06/61] docs(changelog): note OpenSky snapshot compression (#795) --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58103d04da..aa36408a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +- The live flight snapshot is compressed on the wire. `/api/opensky` gzips its + cached global snapshot and its regional adsb.lol fallback once per upstream + refresh and serves that frame to clients offering gzip — roughly 860 KB + becomes roughly 258 KB — while a client that offers nothing receives the same + bytes uncompressed. Both answers carry `Vary: Accept-Encoding`, and a response + the proxy does not cache, such as an auth failure, is never sent under a + cached snapshot's encoding (daikaginza, #795). + - Public Overpass instances are no longer used by default. Street Traffic roads come from TomTom flow tiles, OpenFreeMap vector tiles, or both, chosen on the layer row (TomTom / OSM / Hybrid) or with `?trafficRoads=`. With a From e7dd71e9bcdd836e046aba84ba98d5889d482025 Mon Sep 17 00:00:00 2001 From: daikaginza Date: Tue, 29 Sep 2026 11:13:36 +0700 Subject: [PATCH 07/61] fix(server): read the whole q value, not a numeric prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Number.parseFloat accepts any valid numeric prefix, so `gzip;q=1oops` read as 1 and the out-of-range `gzip;q=2` was accepted — both contradicting the comment two lines above, which promises that a quality this cannot read confidently fails closed. Matching the qvalue grammar of RFC 9110 section 12.4.2 makes the code do what it already claimed to do. Thanks to kvnloo for catching it on review. --- server/providers/common/compress.js | 21 +++++++++++++++------ src/tooling/responseCompression.test.mjs | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/server/providers/common/compress.js b/server/providers/common/compress.js index 7d93b35948..ebf736eda2 100644 --- a/server/providers/common/compress.js +++ b/server/providers/common/compress.js @@ -23,12 +23,20 @@ const gzipAsync = promisify(gzip); /** Below this, a gzip frame costs more than the bytes it saves. */ const MIN_COMPRESSED_BYTES = 1024; +/** + * The `qvalue` grammar of RFC 9110 section 12.4.2: zero to three decimals + * below one, or one with only zeros after it. Matching the whole token rather + * than parsing a numeric prefix is what makes `q=1oops` and the out-of-range + * `q=2` unreadable instead of quietly rounding to something acceptable. + */ +const QVALUE = /^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/; + /** * Whether the client offered gzip in `Accept-Encoding`. * - * Anything this cannot read confidently — a missing header, a malformed - * quality value, the `x-gzip` alias — reads as "no", because the fallback is an - * identity response every client can decode. + * Anything this cannot read confidently — a missing header, a malformed or + * out-of-range quality value, the `x-gzip` alias — reads as "no", because the + * fallback is an identity response every client can decode. * * @param {import('node:http').IncomingMessage} request * @returns {boolean} @@ -39,12 +47,13 @@ export function acceptsGzip(request) { return header.split(',').some((part) => { const [token, ...parameters] = part.split(';'); if (token.trim().toLowerCase() !== 'gzip') return false; - // `q=0` is the one way a client can name an encoding and still refuse it - // (RFC 9110 section 12.4.2). const quality = parameters .map((parameter) => parameter.trim().toLowerCase()) .find((parameter) => parameter.startsWith('q=')); - return quality === undefined || Number.parseFloat(quality.slice(2)) > 0; + if (quality === undefined) return true; + // `q=0` is the one way a client can name an encoding and still refuse it. + const value = quality.slice(2); + return QVALUE.test(value) && Number(value) > 0; }); } diff --git a/src/tooling/responseCompression.test.mjs b/src/tooling/responseCompression.test.mjs index 92fee57a37..c5c70dae70 100644 --- a/src/tooling/responseCompression.test.mjs +++ b/src/tooling/responseCompression.test.mjs @@ -61,12 +61,23 @@ test('accept-encoding is read the way clients actually write it', () => { assert.equal(acceptsGzip({}), false); assert.equal(acceptsGzip(undefined), false); - // A quality of zero names gzip and refuses it (RFC 9110 section 12.4.2), - // and an unreadable quality falls back to the encoding every client accepts. + // A quality of zero names gzip and refuses it (RFC 9110 section 12.4.2). assert.equal(acceptsGzip(request('gzip;q=0')), false); assert.equal(acceptsGzip(request('gzip;q=0.000')), false); - assert.equal(acceptsGzip(request('gzip;q=bogus')), false); assert.equal(acceptsGzip(request('gzip;q=0.001')), true); + assert.equal(acceptsGzip(request('gzip;q=1')), true); + assert.equal(acceptsGzip(request('gzip;q=1.000')), true); + + // A quality that is not a whole `qvalue` is unreadable, not a number with + // trailing noise: the grammar allows three decimals and a ceiling of 1, so + // these must not round into acceptance. + assert.equal(acceptsGzip(request('gzip;q=bogus')), false); + assert.equal(acceptsGzip(request('gzip;q=1oops')), false); + assert.equal(acceptsGzip(request('gzip;q=0.5abc')), false); + assert.equal(acceptsGzip(request('gzip;q=2')), false); + assert.equal(acceptsGzip(request('gzip;q=1.5')), false); + assert.equal(acceptsGzip(request('gzip;q=0.0001')), false); + assert.equal(acceptsGzip(request('gzip;q=')), false); // `gzip` is not matched as a substring of a neighbouring token. assert.equal(acceptsGzip(request('x-gzip')), false); From d3370d6bc4ce5f264fd29eece459052e6565cb1a Mon Sep 17 00:00:00 2001 From: daikaginza Date: Sun, 18 Oct 2026 13:36:40 +0700 Subject: [PATCH 08/61] docs(changelog): move the entry into a changelog.d fragment Main now takes pending entries as changelog.d/-.md files (#787), so the entry leaves CHANGELOG.md for changelog.d/794-api-method-guard.md. --- changelog.d/794-api-method-guard.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog.d/794-api-method-guard.md diff --git a/changelog.d/794-api-method-guard.md b/changelog.d/794-api-method-guard.md new file mode 100644 index 0000000000..530be060ea --- /dev/null +++ b/changelog.d/794-api-method-guard.md @@ -0,0 +1,7 @@ +- The read-only query proxies state their method contract. `/api/flights`, + `/api/military` and `/api/route` answered any verb with the same body + while ignoring the request; they now answer `405 Method Not Allowed` to + anything but `GET`, the way `/api/geocode` and the other query proxies + already did, and declare `Allow: GET` with it the way `/api/radio/stations` + does. The refusal precedes rate limiting and any upstream call + (daikaginza, #794). From 69777700674fa5f4dfcc3729a553b96a9a91ffe0 Mon Sep 17 00:00:00 2001 From: daikaginza Date: Sun, 18 Oct 2026 13:36:42 +0700 Subject: [PATCH 09/61] docs(changelog): move the entry into a changelog.d fragment Main now takes pending entries as changelog.d/-.md files (#787), so the entry leaves CHANGELOG.md for changelog.d/795-opensky-compress-cached-body.md. --- changelog.d/795-opensky-compress-cached-body.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog.d/795-opensky-compress-cached-body.md diff --git a/changelog.d/795-opensky-compress-cached-body.md b/changelog.d/795-opensky-compress-cached-body.md new file mode 100644 index 0000000000..c0bbadbed7 --- /dev/null +++ b/changelog.d/795-opensky-compress-cached-body.md @@ -0,0 +1,7 @@ +- The live flight snapshot is compressed on the wire. `/api/flights` gzips its + cached global snapshot and its regional adsb.lol fallback once per upstream + refresh and serves that frame to clients offering gzip — roughly 860 KB + becomes roughly 258 KB — while a client that offers nothing receives the same + bytes uncompressed. Both answers carry `Vary: Accept-Encoding`, and a response + the proxy does not cache, such as an auth failure, is never sent under a + cached snapshot's encoding (daikaginza, #795). From bbfb23a765e0bc2927993a4884317f38f92fa4bd Mon Sep 17 00:00:00 2001 From: BreezeDelegate <271538431+BreezeDelegate@users.noreply.github.com> Date: Sat, 26 Sep 2026 00:04:43 +0200 Subject: [PATCH 10/61] fix(ci): run allocation gates on Node 26 --- changelog.d/766-node26-allocation-gates.md | 1 + docs/CURRENT-STATE.md | 17 +++++++------- scripts/qa-l9-matrix.mjs | 24 ++++++++++---------- scripts/run-unit-tests.mjs | 22 +++++++++--------- src/data/focusAllocations.test.mjs | 2 +- src/overlays/worldOverlayAllocation.test.mjs | 2 +- src/qaL9MatrixVerdicts.test.mjs | 3 ++- src/unitTestRunner.test.mjs | 23 ++++++++----------- 8 files changed, 46 insertions(+), 48 deletions(-) create mode 100644 changelog.d/766-node26-allocation-gates.md diff --git a/changelog.d/766-node26-allocation-gates.md b/changelog.d/766-node26-allocation-gates.md new file mode 100644 index 0000000000..a0fcb6a9f0 --- /dev/null +++ b/changelog.d/766-node26-allocation-gates.md @@ -0,0 +1 @@ +- Run the existing GC-bracketed allocation regression gates on Node 26 as well as Node 24. Keep the current byte budgets so CI catches allocation regressions on both supported runtimes (#39). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index d49d92238f..a7c2e2f7f1 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -3148,9 +3148,9 @@ down | auth-failed` (plus the unchanged `missing-key`/`unsupported`) with > style-switch persistence state. Browser/GPU performance comparison remains > operator-side; the final accounting records only comparable population > reductions and deterministic Node allocation/solve measurements. Those -> allocation gates are calibrated on Node.js 24.14.x; `package.json` permits -> supported product runtimes on Node 24 or 26, while the allocation runner -> separately enforces Node 24 for these two calibrated probes. Each probe +> allocation gates are calibrated on both supported Node majors (24 and 26); +> `package.json` permits those same product runtimes, and the existing CI matrix +> executes the two calibrated probes on both entries. Each probe > compiles synchronously and discards explicit-GC > transition chunks before applying the unchanged byte ceilings. The unit > runner executes ordinary test files with Node's default parallelism, then @@ -4987,12 +4987,11 @@ and unreachable upstream (502/504) separately from road geometry. > **Reading `npm test` totals:** the count depends on the Node major. The two > GC-bracketed allocation microbenchmarks (`src/data/focusAllocations.test.mjs` -> = 1 test, `src/overlays/worldOverlayAllocation.test.mjs` = 13) only RUN on the -> calibrated Node 24 runtime; on any other major the runner skips both files and -> their 14 tests are absent from the total. A branch total quoted without its -> Node version is therefore not reproducible. As of the fly_route cinematic -> branch: **2,281 on Node 25.6.1** (allocation suites skipped) = 2,255 on -> `main` + 26 route pins; the same tree on Node 24 reports 2,295. +> = 1 test, `src/overlays/worldOverlayAllocation.test.mjs` = 13) RUN on both +> supported Node 24 and Node 26. Unsupported majors may still skip those files +> unless `GEV_REQUIRE_ALLOCATION_GATE=1` is set; every current supported CI +> matrix entry is calibrated and therefore executes them. Historical totals recorded from unsupported Node 25 +> runs can therefore remain lower because their 14 allocation tests were skipped. - **Camera verbs** (`src/cameraVerbs.js`) — one motion slot, driven per clock tick. `move_camera` orbits/pans/tilts/rotates; `fly_route` is a cinematic dolly along an existing route annotation. `rotate_globe` rotates the world-space camera rigidly around Earth's center using its screen-up axis, preserving geocentric range and framing. Left/right describe visible globe motion, while `rotate` turns the camera in place. Omitted globe direction/mode default to right/continuous; explicit values prevail. Other camera motions keep their once default. Admission requires 3D, no Cockpit/tracking owner and the whole globe inside the existing keyhole circle, using the shared keyhole/projection geometry and vertical camera FOV with a rotation-local bounding-sphere cone for off-axis containment. Canvas-edge clipping alone does not block a rigid rotation or its unchanged Globe View preset. There is no altitude cutoff. An already smaller, fully framed globe rotates directly; repeated nudges, direction and speed changes recheck current framing without demanding a reset merely because ellipsoid altitude varied. A close-up or overlap refuses without moving the camera. When the unchanged Globe View preset fits, voice says “Globe rotation isn’t available from this view. You can say ‘Reset to Globe View and rotate the globe.’” without asking a permission question or automatically resetting. Explicit Reset/Show Globe View commands remain direct; an explicit reset-and-rotate request waits for reset success before requesting rotation. If OpenAI dispatches both tools together, rotation waits for earlier same-response resets and is skipped if any fails or is cancelled. OpenAI rejects later tool calls in the same response after a globe refusal, including calls arriving while globe admission is pending, and preserves response-scoped `tool_choice: none` for the refusal follow-up; Gemini rejects further tool execution, including queued sibling calls, until fresh typed input or admitted speech. Model interruption, advisory captions and microphone toggles do not release that guard. There is no pending Yes/No offer. Outside the refused response, explicit-command interpretation and avoiding repeated resets remain model-guided; a distinct model-issued reset call is not an app-enforced proof of user intent. A failed standalone reset can still be retried by the model, and a reset result does not guarantee the camera has fully settled. Before suggesting a reset, a cloned camera checks the unchanged Globe View destination against the same keyhole/depth rules without moving the live camera. If that preset cannot fit, `globe-reset-unavailable` asks for further zoom and the refusal instructs further zoom instead of a reset; this also covers ultrawide views. Unsupported view geometry or non-WGS84 projection assumptions fail closed without the closer-zoom instruction. Supported camera inputs/navigation intents cancel rotation before their action. Finite radius greater than the ellipsoid's maximum radius proves whole-arc clearance at constant centre-distance; no low-altitude swept solver is needed. The unchanged Globe View reset preset remains 18,000,000 m. Terrain and buildings remain outside the guarantee. - **The route dolly is shaped, not linear** (2026-08-20). A trapezoid speed profile (smoothstep up, cruise, smoothstep down, distance taken as the closed-form integral) eases both ends without changing the pace — duration is still `totalM / ROUTE_M_S[speed]`, with one exception: a 0.5 s minimum keeps a degenerate route from being an instant teleport, so routes under 10 m (slow) / 20 m (normal) / 45 m (fast) fly SLOWER than the speed word, never faster. Turns bank up to **10°** (a 90° street corner settles near 7.5°), measured as a triangular pulse over a 4 s window centred on the camera so the roll leads in and unwinds after. Altitude breathes ±20 m around the 260 m mean and lifts up to 26 m into turns. Pitch is LOCKED at −32°; heading comes from a gaze that leads the path by 6.5 s of travel. `prefers-reduced-motion` zeroes the roll and the altitude shaping and keeps the easing. diff --git a/scripts/qa-l9-matrix.mjs b/scripts/qa-l9-matrix.mjs index 8709366dea..d36bab9cb3 100644 --- a/scripts/qa-l9-matrix.mjs +++ b/scripts/qa-l9-matrix.mjs @@ -239,11 +239,11 @@ function satisfiesEngines(version, range) { * re-resolve the interpreter from PATH and hand the gate a different Node than * the one the check believes it selected. * @param {string} version e.g. "v24.19.0" - * @returns {boolean} true only for a parseable Node 24. + * @returns {boolean} true for a parseable supported Node 24 or 26. */ function isCalibratedAllocationRuntime(version) { const [maj] = String(version || '').trim().replace(/^v/, '').split('.').map((n) => Number.parseInt(n, 10)); - return maj === 24; + return maj === 24 || maj === 26; } /** @@ -546,7 +546,7 @@ const check = (spec) => { CHECKS.push(spec); }; // ─── A · REPO GATES ─────────────────────────────────────────────────────── check({ - id: 'A1', group: 'A', desc: 'Node runtime satisfies package.json engines (allocation budgets are pinned to Node 24)', + id: 'A1', group: 'A', desc: 'Node runtime satisfies package.json engines (allocation budgets cover supported Node majors)', run: async () => { const pkg = JSON.parse(readFileSync(resolve(REPO_ROOT, 'package.json'), 'utf8')); const range = pkg.engines?.node || '(unset)'; @@ -557,7 +557,7 @@ check({ if (satisfied) return pass(`node ${process.versions.node} satisfies "${range}"`); // An off-range runtime is an environment problem, not a product defect — // but it silently disables the allocation gate, so say so loudly. A3 then - // runs that gate under a discovered Node 24. + // runs that gate under a discovered calibrated Node 24 fallback. return env.node24 ? skip(`node ${process.versions.node} is OUTSIDE "${range}"; A3 runs the allocation gate under ${env.node24.label}, but prefer running the whole L9 pass on Node 24`, 'ENV') : fail(`node ${process.versions.node} is OUTSIDE "${range}" and no Node 24 runtime was found — the allocation gate cannot run at all`); @@ -579,13 +579,13 @@ check({ }); check({ - id: 'A3', group: 'A', desc: 'Allocation microbenchmarks actually EXECUTE (they silently skip off Node 24)', + id: 'A3', group: 'A', desc: 'Allocation microbenchmarks actually EXECUTE on supported Node majors', run: async () => { // npm test prints "[unit] SKIPPED n allocation microbenchmarks" and still - // exits 0 when the runtime is not Node 24. A green suite is therefore NOT - // proof the gate ran. Force it, under Node 24 when one is discoverable. + // exits 0 when the runtime is outside the calibrated supported majors. A green + // suite is therefore NOT proof the gate ran. Force it under a calibrated runtime. // - // ALWAYS invoke the Node 24 BINARY directly — never `npm test`. npm + // ALWAYS invoke the calibrated Node binary directly — never `npm test`. npm // re-resolves the interpreter from PATH and can land back on the system // Node even when THIS process is already 24: running the whole matrix under // `mise exec node@24.19.0 --`, the npm shell-out still re-execed system @@ -597,10 +597,10 @@ check({ const v = await sh(bin, ['--version'], { timeoutMs: 60000 }); const version = (v.out || '').trim(); if (!isCalibratedAllocationRuntime(version)) { - // run-unit-tests.mjs refuses to measure calibrated budgets off Node 24, + // run-unit-tests.mjs refuses to measure calibrated budgets off supported Node majors, // so a wrong binary means the gate never ran. That is this check failing // to establish its own claim — not evidence about the product. - return crash(`the runtime selected for the allocation gate (${label}) reports ${version || 'no parseable version'}, not Node 24 — the gate would refuse or silently skip, so this check verified nothing`); + return crash(`the runtime selected for the allocation gate (${label}) reports ${version || 'no parseable version'}, not Node 24 or 26 — the gate would refuse or silently skip, so this check verified nothing`); } const r = await sh(bin, [resolve(REPO_ROOT, 'scripts/run-unit-tests.mjs')], { timeoutMs: 600000, env: { GEV_REQUIRE_ALLOCATION_GATE: '1' }, @@ -611,9 +611,9 @@ check({ }; const [maj] = process.versions.node.split('.').map(Number); - if (maj === 24) return runGate(process.execPath, 'this runtime'); + if (maj === 24 || maj === 26) return runGate(process.execPath, 'this runtime'); if (env.node24) return runGate(env.node24.bin, env.node24.label); - return skip(`no Node 24 runtime found (running ${process.versions.node}); the gate SKIPS silently — install Node 24 and re-run`, 'OWNER-RUN'); + return skip(`no calibrated Node 24/26 runtime found (running ${process.versions.node}); the gate SKIPS silently — install a supported Node runtime and re-run`, 'OWNER-RUN'); }, }); diff --git a/scripts/run-unit-tests.mjs b/scripts/run-unit-tests.mjs index 3712df28e5..29c3e2b001 100644 --- a/scripts/run-unit-tests.mjs +++ b/scripts/run-unit-tests.mjs @@ -8,15 +8,16 @@ export const ALLOCATION_TEST_FILES = Object.freeze([ 'src/overlays/worldOverlayAllocation.test.mjs', ]); -/** Whether this runtime matches the one the allocation budgets were calibrated on. */ +/** Whether this runtime matches a supported major the allocation budgets are calibrated on. */ export function isCalibratedAllocationRuntime(version = process.versions.node) { - return Number.parseInt(String(version).split('.')[0], 10) === 24; + const major = Number.parseInt(String(version).split('.')[0], 10); + return major === 24 || major === 26; } -/** Require the runtime on which allocation budgets were calibrated. */ -export function assertNode24AllocationRuntime(version = process.versions.node) { +/** Require a runtime on which allocation budgets are calibrated. */ +export function assertCalibratedAllocationRuntime(version = process.versions.node) { if (!isCalibratedAllocationRuntime(version)) { - throw new Error(`Allocation budgets require the calibrated Node 24 runtime; received ${version}`); + throw new Error(`Allocation budgets require calibrated Node 24 or 26; received ${version}`); } return version; } @@ -86,19 +87,18 @@ export function runUnitTests() { const parallelStatus = runTests(['--test', ...plan.parallel]); if (parallelStatus !== 0) return parallelStatus; - // The GC-bracketed budgets are calibrated on Node 24 and are meaningless on - // other allocators. A contributor's suite must stay green on any supported - // engine (package.json permits >=24), so uncalibrated runtimes skip the + // The GC-bracketed budgets are calibrated on every supported Node major. + // Unsupported runtimes may still run ordinary tests, so uncalibrated runtimes skip the // probes with a warning. Set GEV_REQUIRE_ALLOCATION_GATE=1 (pinned CI / // release batteries) to make an uncalibrated runtime a hard failure. if (!isCalibratedAllocationRuntime()) { if (process.env.GEV_REQUIRE_ALLOCATION_GATE === '1') { - assertNode24AllocationRuntime(); + assertCalibratedAllocationRuntime(); } console.warn( `[unit] SKIPPED ${ALLOCATION_TEST_FILES.length} allocation microbenchmarks: ` - + `budgets are calibrated for Node 24, running ${process.versions.node}. ` - + 'Run under Node 24 (or set GEV_REQUIRE_ALLOCATION_GATE=1 to fail instead).', + + `budgets are calibrated for Node 24 and 26, running ${process.versions.node}. ` + + 'Run under Node 24 or 26 (or set GEV_REQUIRE_ALLOCATION_GATE=1 to fail instead).', ); return 0; } diff --git a/src/data/focusAllocations.test.mjs b/src/data/focusAllocations.test.mjs index 86f28db187..f58e5f1217 100644 --- a/src/data/focusAllocations.test.mjs +++ b/src/data/focusAllocations.test.mjs @@ -13,7 +13,7 @@ import { isCalibratedAllocationRuntime } from '../../scripts/run-unit-tests.mjs' */ test('converged focus treatment stays within the GC-bracketed allocation budget', (t) => { if (!isCalibratedAllocationRuntime()) { - return t.skip(`allocation budgets are calibrated for Node 24; running ${process.versions.node}`); + return t.skip(`allocation budgets are calibrated for Node 24 or 26; running ${process.versions.node}`); } const result = spawnSync( process.execPath, diff --git a/src/overlays/worldOverlayAllocation.test.mjs b/src/overlays/worldOverlayAllocation.test.mjs index e29785d487..70197097a5 100644 --- a/src/overlays/worldOverlayAllocation.test.mjs +++ b/src/overlays/worldOverlayAllocation.test.mjs @@ -333,7 +333,7 @@ function runAllocationProbe(entryCount, profile = 'generic') { for (const workload of WORKLOADS) { test(`steady moving-source frames stay in budget ${workload.name}`, (t) => { if (!CALIBRATED_ALLOCATION_RUNTIME) { - return t.skip(`allocation budgets are calibrated for Node 24; running ${process.versions.node}`); + return t.skip(`allocation budgets are calibrated for Node 24 or 26; running ${process.versions.node}`); } const payload = runAllocationProbe(workload.entries, workload.profile); diff --git a/src/qaL9MatrixVerdicts.test.mjs b/src/qaL9MatrixVerdicts.test.mjs index 867e344107..2ec826e8dd 100644 --- a/src/qaL9MatrixVerdicts.test.mjs +++ b/src/qaL9MatrixVerdicts.test.mjs @@ -127,9 +127,10 @@ test('an unevaluable engines range reports unknown rather than guessing', () => // A full pass run under `mise exec node@24 --` still re-execed system Node 25 // through npm; the forced gate refused ("received 25.6.1") and A3 reported it // as a product failure. A3 now invokes the binary directly and checks it. -test('only a parseable Node 24 counts as the calibrated allocation runtime', () => { +test('every supported Node major counts as a calibrated allocation runtime', () => { assert.equal(isCalibratedAllocationRuntime('v24.19.0'), true); assert.equal(isCalibratedAllocationRuntime('24.19.0'), true, 'the v prefix is optional'); + assert.equal(isCalibratedAllocationRuntime('v26.3.0'), true); assert.equal(isCalibratedAllocationRuntime('v25.6.1'), false, 'the npm re-resolution case'); assert.equal(isCalibratedAllocationRuntime('v22.21.1'), false); for (const junk of ['', ' ', 'node', undefined, null]) { diff --git a/src/unitTestRunner.test.mjs b/src/unitTestRunner.test.mjs index 80d9091e02..e206726e86 100644 --- a/src/unitTestRunner.test.mjs +++ b/src/unitTestRunner.test.mjs @@ -7,7 +7,7 @@ import { ALLOCATION_TEST_FILES, UNIT_TEST_ROOTS, allocationTestArgs, - assertNode24AllocationRuntime, + assertCalibratedAllocationRuntime, buildUnitTestPlan, discoverUnitTestFiles, isCalibratedAllocationRuntime, @@ -87,30 +87,27 @@ test('the runner discovers every test file in the repository', () => { } }); -test('allocation runtime calibration is explicit and pinned to Node 24', () => { - assert.equal(assertNode24AllocationRuntime('24.19.0'), '24.19.0'); +test('allocation runtime calibration covers both supported Node majors', () => { + assert.equal(assertCalibratedAllocationRuntime('24.19.0'), '24.19.0'); assert.throws( - () => assertNode24AllocationRuntime('22.23.1'), - /calibrated Node 24 runtime/, - ); - assert.throws( - () => assertNode24AllocationRuntime('26.0.0'), - /calibrated Node 24 runtime/, + () => assertCalibratedAllocationRuntime('22.23.1'), + /calibrated Node 24 or 26/, ); + assert.equal(assertCalibratedAllocationRuntime('26.0.0'), '26.0.0'); assert.equal(isCalibratedAllocationRuntime('24.19.0'), true); assert.equal(isCalibratedAllocationRuntime('22.23.1'), false); - assert.equal(isCalibratedAllocationRuntime('26.3.0'), false); + assert.equal(isCalibratedAllocationRuntime('26.3.0'), true); }); -test('npm test stays green on every supported engine, not only the calibrated one', () => { +test('npm test calibrates both supported engines while retaining off-range warnings', () => { // package.json wiring: `npm test` must invoke this runner, and the engines // range it advertises must not be narrower than what the runner tolerates. const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')); assert.equal(pkg.scripts.test, 'node scripts/run-unit-tests.mjs'); const enginesNode = String(pkg.engines?.node || ''); assert.ok(enginesNode, 'engines.node must be declared'); - // The runner throws for uncalibrated runtimes ONLY behind the explicit - // opt-in env; by default it skips, so a supported non-24 engine cannot fail. + // Unsupported runtimes only skip probes without the explicit opt-in hard gate. + // Node 26 is calibrated and runs those probes with the same budgets. const runner = readFileSync(new URL('../scripts/run-unit-tests.mjs', import.meta.url), 'utf8'); assert.match(runner, /GEV_REQUIRE_ALLOCATION_GATE/); assert.match(runner, /SKIPPED .*allocation microbenchmarks/); From ae55963a0e5638b0aa2e2a90d7a66d8f10a40597 Mon Sep 17 00:00:00 2001 From: quanticsoul4772 <71096528+quanticsoul4772@users.noreply.github.com> Date: Thu, 29 Oct 2026 07:10:06 -0700 Subject: [PATCH 11/61] fix(tools): wrap whole-degree headings at 360 to 0 The query tools rounded courses, headings, bearings and azimuths with Number(value.toFixed(0)) and no wrap, so a direction of 359.5 degrees or more came back as 360: find_vessel with course 359.7 and heading 359.6 returned course_deg 360 and heading_deg 360. Round them through the shared roundHeadingDegrees helper the layers and UI already use (src/data/headingDegrees.js), which wraps into 0 to 359: course_deg and heading_deg (vessels), course_deg (aircraft), bearing_deg (transit), heading_deg (cameras), and rise_azimuth_deg and azimuth_deg (satellites). Other rounding is unchanged. Co-Authored-By: Claude Opus 5.5 --- docs/CURRENT-STATE.md | 5 ++++- src/tools/queries/aviation.js | 3 ++- src/tools/queries/aviation.test.mjs | 13 +++++++++++++ src/tools/queries/maritime.js | 5 +++-- src/tools/queries/maritime.test.mjs | 19 +++++++++++++++++++ src/tools/queries/media.js | 3 ++- src/tools/queries/media.test.mjs | 14 ++++++++++++++ src/tools/queries/mobility.js | 3 ++- src/tools/queries/mobility.test.mjs | 17 +++++++++++++++++ src/tools/queries/space.js | 5 +++-- src/tools/queries/space.test.mjs | 18 ++++++++++++++++++ 11 files changed, 97 insertions(+), 8 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 35d81dd054..35db1b1bbe 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -204,7 +204,10 @@ perimeters, terrain height, military installations and map features, plus a combined situation brief, military awareness around a point, the app's heads-up display caption, and a link that opens the app over an area. Tools reuse the layers' portable source factories, take a shared `area` argument (place name, bounding box, or point and radius) and cap -lists at 25 rows by default. `aircraft_in_area` and `vessels_in_area` can also +lists at 25 rows by default. Vessel `course_deg` and `heading_deg`, aircraft +`course_deg`, transit `bearing_deg`, camera `heading_deg` and satellite +`rise_azimuth_deg` and `azimuth_deg` are whole degrees from 0 to 359; a +direction of 359.5° or more reads 0 rather than 360. `aircraft_in_area` and `vessels_in_area` can also count every match by a field (`group_by`: airline, read from the ICAO designator in the callsign, or operator, country or type for aircraft; type or destination for ships; the ten largest groups, then other and unknown counts; diff --git a/src/tools/queries/aviation.js b/src/tools/queries/aviation.js index 153e36e030..7c988c5ea0 100644 --- a/src/tools/queries/aviation.js +++ b/src/tools/queries/aviation.js @@ -19,6 +19,7 @@ import { numericSummary, thinEvenly, } from '../results.js'; +import { roundHeadingDegrees } from '../../data/headingDegrees.js'; const ICAO24_SCHEMA = Object.freeze({ type: 'string', @@ -75,7 +76,7 @@ function aircraftRow(record, from) { altitude_m: round(record.baroAltitudeM ?? record.ellipsoidAltitudeM, 0), on_ground: record.onGround === true, speed_mps: round(record.speedMps, 1), - course_deg: round(record.courseDeg, 0), + course_deg: roundHeadingDegrees(record.courseDeg), vertical_rate_mps: round(record.verticalRateMps, 1), type_code: record.typeCode || null, registration: record.registration || null, diff --git a/src/tools/queries/aviation.test.mjs b/src/tools/queries/aviation.test.mjs index 4847197908..59a9286728 100644 --- a/src/tools/queries/aviation.test.mjs +++ b/src/tools/queries/aviation.test.mjs @@ -146,6 +146,19 @@ test('the military feed is used on request and reported when missing', async () ); }); +test('an aircraft course that rounds to 360 reads as 0', async () => { + const catalog = composeCatalog({ + tools: coreTools, + services: { + aircraft: feed([ + record('ddd444', 37.6, -122.3, { callsign: 'N360', courseDeg: 359.6 }), + ]), + }, + }); + const result = await catalog.call('find_aircraft', { callsign: 'N360' }); + assert.equal(result.data.rows[0].course_deg, 0); +}); + test('aircraft are found by exactly one identifier across feeds', async () => { const catalog = composeCatalog({ tools: coreTools, diff --git a/src/tools/queries/maritime.js b/src/tools/queries/maritime.js index 5798a09366..0e9d803739 100644 --- a/src/tools/queries/maritime.js +++ b/src/tools/queries/maritime.js @@ -20,6 +20,7 @@ import { numericSummary, thinEvenly, } from '../results.js'; +import { roundHeadingDegrees } from '../../data/headingDegrees.js'; import { normalizeVesselType } from '../../data/vesselTypes.js'; const MMSI_SCHEMA = Object.freeze({ @@ -57,8 +58,8 @@ function vesselRow(record, from) { lat: round(record.latitude, 5), lon: round(record.longitude, 5), speed_mps: round(record.speedMps, 1), - course_deg: round(record.courseDeg, 0), - heading_deg: round(record.headingDeg, 0), + course_deg: roundHeadingDegrees(record.courseDeg), + heading_deg: roundHeadingDegrees(record.headingDeg), observed_at: isoTime(record.observedAtMs), ...(from ? { distance_km: round(distanceKm(from, point), 1) } : {}), }; diff --git a/src/tools/queries/maritime.test.mjs b/src/tools/queries/maritime.test.mjs index d86bdf352a..f89e6bce33 100644 --- a/src/tools/queries/maritime.test.mjs +++ b/src/tools/queries/maritime.test.mjs @@ -351,6 +351,25 @@ test('find_vessel answers carry normalized types and destinations', async () => ); }); +test('a vessel course or heading that rounds to 360 reads as 0', async () => { + const catalog = composeCatalog({ + tools: coreTools, + services: { + vessels: vessels({ + records: [ + vessel('366000003', 37.78, -122.4, { + courseDeg: 359.7, + headingDeg: 359.6, + }), + ], + }), + }, + }); + const [row] = (await catalog.call('find_vessel', { mmsi: '366000003' })).data + .rows; + assert.deepEqual([row.course_deg, row.heading_deg], [0, 0]); +}); + test('a destination with no letters counts as unknown', async () => { const catalog = composeCatalog({ tools: coreTools, diff --git a/src/tools/queries/media.js b/src/tools/queries/media.js index a03e88bb40..d154619db0 100644 --- a/src/tools/queries/media.js +++ b/src/tools/queries/media.js @@ -10,6 +10,7 @@ import { resolveArea, } from '../area.js'; import { LIMIT_SCHEMA, capRows, countNoun, toBase64 } from '../results.js'; +import { roundHeadingDegrees } from '../../data/headingDegrees.js'; const FRAME_TYPES = new Set(['image/jpeg', 'image/png', 'image/webp']); const MAX_FRAME_BYTES = 3 * 1024 * 1024; @@ -85,7 +86,7 @@ export const findCctvCameras = defineTool({ provider: text(camera.provider), lat: round(camera.lat, 6), lon: round(camera.lon, 6), - heading_deg: round(camera.headingDeg, 0), + heading_deg: roundHeadingDegrees(camera.headingDeg), feed_type: text(camera.feedType), credit: text(camera.credit), distance_km: round(distanceKm(center, camera), 2), diff --git a/src/tools/queries/media.test.mjs b/src/tools/queries/media.test.mjs index 28c037a57e..f690966c52 100644 --- a/src/tools/queries/media.test.mjs +++ b/src/tools/queries/media.test.mjs @@ -77,6 +77,20 @@ test('cameras in an area are listed nearest first', async () => { assert.equal(result.data.rows[1].credit, null); }); +test('a camera heading that rounds to 360 reads as 0', async () => { + const source = { + async getCatalog() { + return { sources: [{ ...cameras[0], headingDeg: 359.6 }] }; + }, + }; + const catalog = composeCatalog({ + tools: coreTools, + services: { cctv: source }, + }); + const result = await catalog.call('find_cctv_cameras', { area: downtown }); + assert.equal(result.data.rows[0].heading_deg, 0); +}); + test('a snapshot returns the frame as an image with its credit', async () => { const source = cctv(); const catalog = composeCatalog({ diff --git a/src/tools/queries/mobility.js b/src/tools/queries/mobility.js index 0a57ae3ae2..c31f038632 100644 --- a/src/tools/queries/mobility.js +++ b/src/tools/queries/mobility.js @@ -19,6 +19,7 @@ import { resolveArea, } from '../area.js'; import { LIMIT_SCHEMA, capRows, countNoun, isoTime } from '../results.js'; +import { roundHeadingDegrees } from '../../data/headingDegrees.js'; const MAX_SYSTEMS = 3; @@ -244,7 +245,7 @@ export const getTransitVehicles = defineTool({ trip_id: vehicle.tripId ?? null, lat: vehicle.lat, lon: vehicle.lon, - bearing_deg: round(vehicle.bearing, 0), + bearing_deg: roundHeadingDegrees(vehicle.bearing), speed_mps: round(vehicle.speedMps, 1), status: vehicle.status ?? null, occupancy: vehicle.occupancy ?? null, diff --git a/src/tools/queries/mobility.test.mjs b/src/tools/queries/mobility.test.mjs index 0ea882727e..aaaa97bad7 100644 --- a/src/tools/queries/mobility.test.mjs +++ b/src/tools/queries/mobility.test.mjs @@ -311,6 +311,23 @@ test('transit vehicles come from nearby feeds and can be limited to a route', as assert.equal(rapid.data.rows[0].id, 'v2'); }); +test('a transit bearing that rounds to 360 reads as 0', async () => { + const north = [{ ...vehicles[0], bearing: 359.6 }]; + const catalog = composeCatalog({ + tools: coreTools, + services: { + transit: transit({ + ok: true, + status: 200, + json: async () => ({ vehicles: north }), + }), + clock, + }, + }); + const result = await catalog.call('get_transit_vehicles', { area: downtown }); + assert.equal(result.data.rows[0].bearing_deg, 0); +}); + test('transit reports uncovered areas and unavailable feeds', async () => { const catalog = composeCatalog({ tools: coreTools, diff --git a/src/tools/queries/space.js b/src/tools/queries/space.js index ef59c0be56..a589e801c4 100644 --- a/src/tools/queries/space.js +++ b/src/tools/queries/space.js @@ -10,6 +10,7 @@ import { parseTleText, tleCatalogNumber } from '../../sources/tle.js'; import { POINT_SCHEMA, resolvePoint } from '../area.js'; import { defineTool, ToolError } from '../catalog.js'; import { LIMIT_SCHEMA, capRows, countNoun, isoTime } from '../results.js'; +import { roundHeadingDegrees } from '../../data/headingDegrees.js'; const text = (value) => (typeof value === 'string' && value ? value : null); @@ -241,7 +242,7 @@ export const nextSatellitePass = defineTool({ peak: isoTime(pass.maxElevMs), set: isoTime(pass.setMs), max_elevation_deg: round(pass.maxElevDeg, 1), - rise_azimuth_deg: round(pass.riseAzDeg, 0), + rise_azimuth_deg: roundHeadingDegrees(pass.riseAzDeg), rise_direction: compass(pass.riseAzDeg), visible: pass.visible, }, @@ -283,7 +284,7 @@ export const satellitesOverhead = defineTool({ name: entry.name, norad: entry.norad, elevation_deg: round(look.elevDeg, 1), - azimuth_deg: round(look.azDeg, 0), + azimuth_deg: roundHeadingDegrees(look.azDeg), direction: compass(look.azDeg), }, ] diff --git a/src/tools/queries/space.test.mjs b/src/tools/queries/space.test.mjs index 0eb5ce346e..0e44fe208f 100644 --- a/src/tools/queries/space.test.mjs +++ b/src/tools/queries/space.test.mjs @@ -296,6 +296,24 @@ test('satellites overhead are those above the elevation, highest first', async ( ); }); +test('satellite azimuths that round to 360 read as 0', async () => { + const catalog = composeCatalog({ + tools: coreTools, + services: { satellites: satellites(), clock: CLOCK }, + }); + // From these points the ISS rises at 359.7° and stands at 359.8° at CLOCK. + const pass = await catalog.call('next_satellite_pass', { + location: { lat: 10, lon: 30 }, + }); + assert.equal(pass.data.pass.rise_azimuth_deg, 0); + assert.equal(pass.data.pass.rise_direction, 'N'); + const overhead = await catalog.call('satellites_overhead', { + location: { lat: 39.25, lon: 65.75 }, + }); + assert.equal(overhead.data.rows[0].name, 'ISS (ZARYA)'); + assert.equal(overhead.data.rows[0].azimuth_deg, 0); +}); + test('stale orbit and launch data are reported', async () => { const stale = { readGroup: async () => ({ ok: true, status: 200, text: TLE, stale: true }), From d1ed2e8e6f14d0c6e23c4b9f51949621d498dad6 Mon Sep 17 00:00:00 2001 From: quanticsoul4772 <71096528+quanticsoul4772@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:49:55 -0800 Subject: [PATCH 12/61] changelog: tool headings wrap at 360 (#1524) Co-Authored-By: Claude Opus 5.5 --- changelog.d/1524-tools-heading-wrap.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/1524-tools-heading-wrap.md diff --git a/changelog.d/1524-tools-heading-wrap.md b/changelog.d/1524-tools-heading-wrap.md new file mode 100644 index 0000000000..3aefce6c52 --- /dev/null +++ b/changelog.d/1524-tools-heading-wrap.md @@ -0,0 +1,4 @@ +- The agent and voice query tools report a direction of 359.5° or more as 0 + instead of 360: vessel course and heading, aircraft course, transit bearing, + camera heading and satellite azimuths now round through the shared heading + helper the layers use (@quanticsoul4772, #1524). From ccd83c5fa2ffdd9ad4f0564c4ec95976330d6109 Mon Sep 17 00:00:00 2001 From: quanticsoul4772 <71096528+quanticsoul4772@users.noreply.github.com> Date: Tue, 3 Nov 2026 07:00:27 -0800 Subject: [PATCH 13/61] docs(tools): say heading values wrap into 0-359, not that 359.5 and up read 0 Co-Authored-By: Claude Opus 5.5 --- changelog.d/1524-tools-heading-wrap.md | 8 ++++---- docs/CURRENT-STATE.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/changelog.d/1524-tools-heading-wrap.md b/changelog.d/1524-tools-heading-wrap.md index 3aefce6c52..2a630f600a 100644 --- a/changelog.d/1524-tools-heading-wrap.md +++ b/changelog.d/1524-tools-heading-wrap.md @@ -1,4 +1,4 @@ -- The agent and voice query tools report a direction of 359.5° or more as 0 - instead of 360: vessel course and heading, aircraft course, transit bearing, - camera heading and satellite azimuths now round through the shared heading - helper the layers use (@quanticsoul4772, #1524). +- The agent and voice query tools report a direction that rounds to 360 as 0: + vessel course and heading, aircraft course, transit bearing, camera heading + and satellite azimuths now round through the shared heading helper the + layers use, which wraps into 0–359 (@quanticsoul4772, #1524). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 35db1b1bbe..ecbdf5e0f4 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -207,7 +207,7 @@ shared `area` argument (place name, bounding box, or point and radius) and cap lists at 25 rows by default. Vessel `course_deg` and `heading_deg`, aircraft `course_deg`, transit `bearing_deg`, camera `heading_deg` and satellite `rise_azimuth_deg` and `azimuth_deg` are whole degrees from 0 to 359; a -direction of 359.5° or more reads 0 rather than 360. `aircraft_in_area` and `vessels_in_area` can also +direction that rounds to 360 reads 0, and larger or negative values wrap. `aircraft_in_area` and `vessels_in_area` can also count every match by a field (`group_by`: airline, read from the ICAO designator in the callsign, or operator, country or type for aircraft; type or destination for ships; the ten largest groups, then other and unknown counts; From 4f43ded5da41303d71258ffbf7b244e7f81b16f9 Mon Sep 17 00:00:00 2001 From: quanticsoul4772 <71096528+quanticsoul4772@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:05:17 -0800 Subject: [PATCH 14/61] test(nominatim): check cache file modes only where POSIX modes exist The disk-cache test asserts the cache directory is 0o700 and its files 0o600. Windows has no POSIX mode bits (the directory stats as 0o666), so the test always failed there. Both checks now run only off Windows, as localServices.test.mjs and mcpPanelKey.test.mjs already do for their 0o600 checks. The cache code is unchanged. Co-Authored-By: Claude Opus 5.5 --- src/tooling/nominatimOutlineRoute.test.mjs | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/tooling/nominatimOutlineRoute.test.mjs b/src/tooling/nominatimOutlineRoute.test.mjs index c29b41f21d..774099efe4 100644 --- a/src/tooling/nominatimOutlineRoute.test.mjs +++ b/src/tooling/nominatimOutlineRoute.test.mjs @@ -684,25 +684,29 @@ test('the disk cache survives a restart and stays within its bounds', async () = await createNominatimCache({ dir, now: time.now }).get('k0'), null, ); - assert.equal( - fs.statSync(dir).mode & 0o777, - 0o700, - 'the query cache directory is private', - ); + // Windows has no POSIX mode bits (directories stat as 0o666), so only + // POSIX systems can check privacy this way. + if (process.platform !== 'win32') + assert.equal( + fs.statSync(dir).mode & 0o777, + 0o700, + 'the query cache directory is private', + ); const text = fs .readdirSync(dir) .filter((name) => name.endsWith('.json')) .map((name) => fs.readFileSync(path.join(dir, name), 'utf8')) .join('\n'); assert.equal(text.includes('k4'), false, 'disk entries never store raw keys'); - for (const name of fs - .readdirSync(dir) - .filter((entry) => entry.endsWith('.json'))) - assert.equal( - fs.statSync(path.join(dir, name)).mode & 0o777, - 0o600, - `${name} is private`, - ); + if (process.platform !== 'win32') + for (const name of fs + .readdirSync(dir) + .filter((entry) => entry.endsWith('.json'))) + assert.equal( + fs.statSync(path.join(dir, name)).mode & 0o777, + 0o600, + `${name} is private`, + ); fs.rmSync(dir, { recursive: true, force: true }); }); From 1c2cdc67752df80491ff6aa97708074b18d3029c Mon Sep 17 00:00:00 2001 From: quanticsoul4772 <71096528+quanticsoul4772@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:06:45 -0800 Subject: [PATCH 15/61] changelog: Nominatim cache mode test on Windows (#1547) Co-Authored-By: Claude Opus 5.5 --- changelog.d/1547-nominatim-cache-mode-windows.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog.d/1547-nominatim-cache-mode-windows.md diff --git a/changelog.d/1547-nominatim-cache-mode-windows.md b/changelog.d/1547-nominatim-cache-mode-windows.md new file mode 100644 index 0000000000..9a48b1ee6b --- /dev/null +++ b/changelog.d/1547-nominatim-cache-mode-windows.md @@ -0,0 +1,3 @@ +- The Nominatim disk-cache test checks the cache directory and file modes + only where POSIX modes exist, so it no longer always fails on Windows + (quanticsoul4772, #1547). From 84c1fef8d34dfd4dd556b6dca6bda9e3d2cf6b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Itallo=20Brand=C3=A3o?= <45429643+IMBrandao@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:15:34 -0300 Subject: [PATCH 16/61] fix(firms): stop requesting the retired Suomi NPP source NASA stopped delivering Suomi NPP data on 2026-11-02 (FIRMS news page). With a live MAP_KEY on 2026-11-04, VIIRS_SNPP_NRT came back ok with zero rows while NOAA-20, NOAA-21 and MODIS returned 57k, 49k and 11k, so the source only spent one transaction per refresh. The proxy now requests NOAA-20, NOAA-21 and MODIS NRT. The "N" satellite label stays, so cached or archived Suomi NPP rows still read SNPP. Tests count sources from the list instead of assuming four, and a regression test keeps the retired source out of the production list. Refs #849 Co-Authored-By: Claude Opus 5.5 --- DATA_SOURCES.md | 7 ++++--- docs/CURRENT-STATE.md | 5 +++++ server/providers/firms.js | 14 ++++++-------- src/data/firmsProxy.test.mjs | 18 ++++++++++++++---- src/tooling/environmentProviders.test.mjs | 4 ++-- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index cac0b5ab7b..efee6b9ffe 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -273,11 +273,12 @@ Bundled OSM-derived data is distributed under [ODbL 1.0](https://opendatacommons > We acknowledge the use of data and/or imagery from NASA's Fire Information for Resource Management System (FIRMS) (https://earthdata.nasa.gov/firms), part of NASA's Earth Observing System Data and Information System (EOSDIS). FIRMS active fires are **fetched live at runtime** (CC0 / U.S. public domain data): the -`/api/firms` server-side proxy merges the three VIIRS NRT sources (NOAA-20, NOAA-21, -Suomi-NPP) and MODIS NRT (Terra + Aqua), clamped to the trailing 24 h, cached 30 min to respect the shared MAP_KEY +`/api/firms` server-side proxy merges the two VIIRS NRT sources (NOAA-20, NOAA-21) +and MODIS NRT (Terra + Aqua), clamped to the trailing 24 h, cached 30 min to respect the shared MAP_KEY transaction quota. Requires a free `FIRMS_MAP_KEY` (https://firms.modaps.eosdis.nasa.gov/api/map_key/); the layer is empty without it. -The former bundled 2026-05-25 snapshot was removed 2026-07-16. +The former bundled 2026-05-25 snapshot was removed 2026-07-16. Suomi NPP (`VIIRS_SNPP_NRT`) +is no longer requested: NASA stopped delivering its data on 2026-11-02. ### Natural Earth physical regions (`natural_earth/`) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index e868dfc95e..102efb997b 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -2325,6 +2325,11 @@ accessible name remains "Don't show this again". Control behavior is unchanged. ## FIRMS source status +The FIRMS proxy requests VIIRS NOAA-20, VIIRS NOAA-21 and MODIS NRT (Terra and +Aqua). It no longer requests VIIRS Suomi NPP: NASA stopped delivering Suomi NPP +data on 2026-11-02, and the source returned no rows while still costing one +MAP_KEY transaction per refresh. + The FIRMS CSV parser rejects impossible acquisition calendar dates before the proxy filters records to the trailing 24 hours, while retaining valid UTC acquisition times. The `get_active_fires` tool reports acquisition times as UTC ISO timestamps, including zero-padded hours and minutes; missing or invalid dates and times diff --git a/server/providers/firms.js b/server/providers/firms.js index 20a2f4bab2..51ea4fc567 100644 --- a/server/providers/firms.js +++ b/server/providers/firms.js @@ -131,8 +131,8 @@ export async function fetchFirms( * NASA FIRMS live active-fire proxy with a memory + disk cache. * Upstream: https://firms.modaps.eosdis.nasa.gov/api/area/csv/{KEY}/{SOURCE}/world/2 * - * Merges three VIIRS NRT sources (NOAA-20, NOAA-21, Suomi-NPP — independent - * satellites, no cross-source dedup) plus MODIS_NRT (combined Terra+Aqua, + * Merges two VIIRS NRT sources (NOAA-20, NOAA-21 — independent satellites, no + * cross-source dedup) plus MODIS_NRT (combined Terra+Aqua, * ~1 km, numeric 0-100 confidence), fetched sequentially (quota courtesy) * with `days=2` (`days=1` means "current UTC day", nearly empty just after * 00:00Z) and clamps to the trailing 24 h via src/data/firmsCsv.js. FIRMS @@ -141,6 +141,9 @@ export async function fetchFirms( * fresh-enough disk cache (.gev-cache/firms.json) prevents ANY upstream * fetch across dev-server restarts. Pattern mirrors celestrakProxy. * + * VIIRS_SNPP_NRT is not requested: NASA stopped delivering Suomi NPP data on + * 2026-11-02, so that source only spent a transaction per refresh (#849). + * * Routes: * GET /api/firms → {fetchedAt, stale, ttlMs, sources, count, fires} * GET /api/firms/status → {hasKey, lastFetch, count, stale, ttlMs, transactions} @@ -153,12 +156,7 @@ export async function fetchFirms( export function firmsProxy() { const TTL_MS = 30 * 60_000; const STATUS_TTL_MS = 5 * 60_000; - const SOURCES = [ - 'VIIRS_NOAA20_NRT', - 'VIIRS_NOAA21_NRT', - 'VIIRS_SNPP_NRT', - 'MODIS_NRT', - ]; + const SOURCES = ['VIIRS_NOAA20_NRT', 'VIIRS_NOAA21_NRT', 'MODIS_NRT']; /** * Per-source body cap. A VIIRS world/2 pull is ~130k rows x ~100 B, about * 13 MB per satellite in heavy fire season (MODIS runs smaller), so this is a diff --git a/src/data/firmsProxy.test.mjs b/src/data/firmsProxy.test.mjs index 14668c8259..135002ca72 100644 --- a/src/data/firmsProxy.test.mjs +++ b/src/data/firmsProxy.test.mjs @@ -21,7 +21,7 @@ assert.notEqual(start, -1, 'FIRMS refresh function exists'); const end = config.indexOf('\n }', start); assert.notEqual(end, -1, 'FIRMS refresh function closes'); const refreshSource = config.slice(start, end + 4); -const SOURCES = ['VIIRS_NOAA20_NRT', 'VIIRS_NOAA21_NRT', 'VIIRS_SNPP_NRT', 'MODIS_NRT']; +const SOURCES = ['VIIRS_NOAA20_NRT', 'VIIRS_NOAA21_NRT', 'MODIS_NRT']; const NOW = Date.UTC(2026, 8, 11, 12); const recent = { acqDate: '2026-09-11', acqTime: '1100' }; @@ -63,7 +63,7 @@ test('FIRMS keeps successful sources when another upstream fails', async () => { if (source === SOURCES[1]) throw new Error('upstream unavailable'); return [recent]; })('fixture'); - assert.equal(result.fires.length, 3); + assert.equal(result.fires.length, SOURCES.length - 1); assert.deepEqual(result.sources, SOURCES.map((source, index) => ({ source, count: index === 1 ? 0 : 1, ok: index !== 1, }))); @@ -77,7 +77,7 @@ test('FIRMS reports one failure if consuming a source throws before append', asy // Fault injection for aggregation; ordinary parsed CSV returns an array. return { length: 1, [Symbol.iterator]() { throw new Error('aggregation failed'); } }; })('fixture'); - assert.equal(result.fires.length, 3); + assert.equal(result.fires.length, SOURCES.length - 1); assert.deepEqual(result.sources, SOURCES.map((source, index) => ({ source, count: index === 0 ? 0 : 1, ok: index !== 0, }))); @@ -107,7 +107,7 @@ function wrappedAddressSelectionFailure() { { name: 'ConnectTimeoutError', code: 'UND_ERR_CONNECT_TIMEOUT', cause: inner }); return new TypeError('fetch failed', { cause }); } -const URL_WITH_KEY = 'https://firms.modaps.eosdis.nasa.gov/api/area/csv/SECRET/VIIRS_SNPP_NRT/world/2'; +const URL_WITH_KEY = 'https://firms.modaps.eosdis.nasa.gov/api/area/csv/SECRET/VIIRS_NOAA20_NRT/world/2'; test('FIRMS failures log the socket cause, never the keyed URL', () => { const described = describeFetchError(addressSelectionFailure()); @@ -307,3 +307,13 @@ test('every FIRMS upstream request goes through the IPv4 fallback', async () => assert.ok(calls[0][2] instanceof AbortSignal); assert.deepEqual(calls[1], ['read', response, calls[0][2]], 'the body read shares the request deadline'); }); + +test('FIRMS requests only the satellites NASA still delivers', () => { + const listed = config.match(/const SOURCES = \[([^\]]*)\];/); + assert.ok(listed, 'FIRMS source list exists'); + const production = [...listed[1].matchAll(/'([A-Z0-9_]+)'/g)].map((m) => m[1]); + assert.deepEqual(production, SOURCES, 'the test mirrors the production source list'); + // NASA stopped delivering Suomi NPP data on 2026-11-02 (#849): requesting it + // returns no rows and still spends a MAP_KEY transaction on every refresh. + assert.ok(!production.includes('VIIRS_SNPP_NRT')); +}); diff --git a/src/tooling/environmentProviders.test.mjs b/src/tooling/environmentProviders.test.mjs index da3cfc335b..feca9432d3 100644 --- a/src/tooling/environmentProviders.test.mjs +++ b/src/tooling/environmentProviders.test.mjs @@ -313,9 +313,9 @@ test('FIRMS retains a large successful source during partial failure and filters const first = json(await request()); assert.equal(first.count, 130001); assert.equal(first.sources.filter((s) => s.ok).length, 1); - assert.equal(calls, 4); + assert.equal(calls, first.sources.length); assert.equal(json(await request()).count, 130001); - assert.equal(calls, 4); + assert.equal(calls, first.sources.length); assert.deepEqual(json(await request('/status')).transactions, { used: 3, limit: 5000, From b342e405d7514505861ab26244f38496a59350cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Itallo=20Brand=C3=A3o?= <45429643+IMBrandao@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:20:09 -0300 Subject: [PATCH 17/61] docs(changelog): add fragment for #1552 Co-Authored-By: Claude Opus 5.5 --- changelog.d/1552-firms-drop-snpp.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/1552-firms-drop-snpp.md diff --git a/changelog.d/1552-firms-drop-snpp.md b/changelog.d/1552-firms-drop-snpp.md new file mode 100644 index 0000000000..fcb375bda3 --- /dev/null +++ b/changelog.d/1552-firms-drop-snpp.md @@ -0,0 +1,4 @@ +- Stop requesting Suomi NPP in Active Fires. NASA stopped delivering its data + on November 2, 2026, so `VIIRS_SNPP_NRT` returned no rows while still costing + a MAP_KEY transaction on every refresh; the layer now merges VIIRS NOAA-20, + VIIRS NOAA-21 and MODIS (IMBrandao, #1552). From e2ccac56ae9c8e8b087197c925c726281ae4fd7c Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Wed, 4 Nov 2026 21:58:42 -0500 Subject: [PATCH 18/61] fix(perimeters): show a 0.25-acre fire as 0.25 ac, not 0 ac The incident card rounded the WFIGS size to whole acres, so every fire under half an acre read "0 ac". The live perimeter feed carries many of these (0.01 to 0.37 acres). Sizes under one acre now keep the reported hundredths. --- docs/CURRENT-STATE.md | 4 ++++ src/layers/perimeters/cards.js | 5 ++++- src/layers/perimeters/cards.test.mjs | 31 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index f1244947d4..e954ae0828 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4239,6 +4239,10 @@ by `scripts/qa-emergency-squawk.mjs`. Both accept `--timeout-ms` for slow boot. Fire Perimeters uses capped, timed server reads with stale-on-error caching and a per-client limit. A stale snapshot is served for at most 24 hours; the layer row then reads STALE, dated by that snapshot's fetch, and `get_fire_perimeters` returns `stale` and `retrieved_at` with "(data may be stale)" in its summary. Unchanged snapshots retain geometry; link checks cancel on disable or selection change, and the row legend shows reported containment. +The incident card rounds the WFIGS size to whole acres, except under one acre, +where it keeps the reported hundredths: a 0.25-acre fire reads `0.25 ac`, not +`0 ac`. + Prohibited & Restricted Airspace is off by default (share-link token `8`) and sits in Infrastructure. The proxy pages `TYPE_CODE IN ('P','R')` from the FAA SUA FeatureServer, caps the body, and reuses a one-hour snapshot, serving the last diff --git a/src/layers/perimeters/cards.js b/src/layers/perimeters/cards.js index aef5913ce5..a6cb3ac4d9 100644 --- a/src/layers/perimeters/cards.js +++ b/src/layers/perimeters/cards.js @@ -159,7 +159,10 @@ export function buildIncidentCard(row, nowMs, { link = null } = {}) { // the known cause, behavior and complexity values and the wording around them. const facts = []; if (Number.isFinite(row.acres)) { - const acres = Math.round(row.acres); + // WFIGS reports sizes to the hundredth of an acre; a fire under one acre + // keeps them rather than reading "0 ac". + const acres = + row.acres < 1 ? Math.round(row.acres * 100) / 100 : Math.round(row.acres); facts.push( tn(acres, '{acres} ac', '{acres} ac', { acres: formatNumber(acres) }), ); diff --git a/src/layers/perimeters/cards.test.mjs b/src/layers/perimeters/cards.test.mjs index 0e064bff03..fe4aac06ba 100644 --- a/src/layers/perimeters/cards.test.mjs +++ b/src/layers/perimeters/cards.test.mjs @@ -302,3 +302,34 @@ test('partial incident details render only the facts that exist', () => { 'Catron County · $85K to date', ]); }); + +test('a fire under one acre keeps its WFIGS size instead of reading 0 ac', () => { + const row = { + stableId: 'x', + name: 'Grey', + acres: 0.25, + containedPct: null, + state: 'US-WA', + category: 'WF', + discoveredTime: null, + updatedTime: null, + cause: null, + behavior: null, + personnel: null, + county: null, + costToDate: null, + complexity: null, + }; + assert.equal( + buildIncidentCard(row, 1758000000000).details[0], + '0.25 ac · containment unknown · US-WA', + ); + assert.equal( + buildIncidentCard({ ...row, acres: 0.01 }, 1758000000000).details[0], + '0.01 ac · containment unknown · US-WA', + ); + assert.equal( + buildIncidentCard({ ...row, acres: 1.4 }, 1758000000000).details[0], + '1 ac · containment unknown · US-WA', + ); +}); From 79c867c8cbd923b58bbed7873217eb43be12b643 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Wed, 4 Nov 2026 22:14:16 -0500 Subject: [PATCH 19/61] docs(changelog): add the perimeter size fragment for #1569 --- changelog.d/1569-perimeters-sub-acre-size.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog.d/1569-perimeters-sub-acre-size.md diff --git a/changelog.d/1569-perimeters-sub-acre-size.md b/changelog.d/1569-perimeters-sub-acre-size.md new file mode 100644 index 0000000000..5ee4ffa985 --- /dev/null +++ b/changelog.d/1569-perimeters-sub-acre-size.md @@ -0,0 +1,3 @@ +- Show a fire perimeter under one acre at its reported size. The incident card + rounded WFIGS sizes to whole acres, so a 0.25-acre fire read "0 ac" + (Rudy Celekli, @rudycelekli, #1569). From b37025414d90d6b696dcecd252c222972c00c557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Itallo=20Brand=C3=A3o?= <45429643+IMBrandao@users.noreply.github.com> Date: Thu, 5 Nov 2026 02:57:27 -0300 Subject: [PATCH 20/61] test(firms): pin the refresh call count and read sources from production Review follow-up for #1552: - environmentProviders: assert exactly 3 upstream calls per refresh again, so a returning fourth source would fail the test. - firmsProxy: build the test's SOURCES from server/providers/firms.js, so there is one list instead of a mirrored copy. - firmsProxy: drop the unused fourth count entry. Co-Authored-By: Claude Opus 5.5 --- src/data/firmsProxy.test.mjs | 13 ++++++------- src/tooling/environmentProviders.test.mjs | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/data/firmsProxy.test.mjs b/src/data/firmsProxy.test.mjs index 135002ca72..dc9ed81447 100644 --- a/src/data/firmsProxy.test.mjs +++ b/src/data/firmsProxy.test.mjs @@ -21,7 +21,10 @@ assert.notEqual(start, -1, 'FIRMS refresh function exists'); const end = config.indexOf('\n }', start); assert.notEqual(end, -1, 'FIRMS refresh function closes'); const refreshSource = config.slice(start, end + 4); -const SOURCES = ['VIIRS_NOAA20_NRT', 'VIIRS_NOAA21_NRT', 'MODIS_NRT']; +// Read the source list from production so these tests share one source of truth. +const listed = config.match(/const SOURCES = \[([^\]]*)\];/); +assert.ok(listed, 'FIRMS source list exists'); +const SOURCES = [...listed[1].matchAll(/'([A-Z0-9_]+)'/g)].map((m) => m[1]); const NOW = Date.UTC(2026, 8, 11, 12); const recent = { acqDate: '2026-09-11', acqTime: '1100' }; @@ -54,7 +57,7 @@ test('FIRMS retains large sources in order and filters expired rows', async () = assert.equal(result.fires[199_999], large.at(-1)); assert.equal(result.fires.at(-1), last); assert.deepEqual(result.sources, SOURCES.map((source, index) => ({ - source, count: [200_000, 1, 0, 0][index], ok: true, + source, count: [200_000, 1, 0][index], ok: true, }))); }); @@ -309,11 +312,7 @@ test('every FIRMS upstream request goes through the IPv4 fallback', async () => }); test('FIRMS requests only the satellites NASA still delivers', () => { - const listed = config.match(/const SOURCES = \[([^\]]*)\];/); - assert.ok(listed, 'FIRMS source list exists'); - const production = [...listed[1].matchAll(/'([A-Z0-9_]+)'/g)].map((m) => m[1]); - assert.deepEqual(production, SOURCES, 'the test mirrors the production source list'); // NASA stopped delivering Suomi NPP data on 2026-11-02 (#849): requesting it // returns no rows and still spends a MAP_KEY transaction on every refresh. - assert.ok(!production.includes('VIIRS_SNPP_NRT')); + assert.ok(!SOURCES.includes('VIIRS_SNPP_NRT')); }); diff --git a/src/tooling/environmentProviders.test.mjs b/src/tooling/environmentProviders.test.mjs index feca9432d3..22eb39ad3d 100644 --- a/src/tooling/environmentProviders.test.mjs +++ b/src/tooling/environmentProviders.test.mjs @@ -313,9 +313,9 @@ test('FIRMS retains a large successful source during partial failure and filters const first = json(await request()); assert.equal(first.count, 130001); assert.equal(first.sources.filter((s) => s.ok).length, 1); - assert.equal(calls, first.sources.length); + assert.equal(calls, 3); assert.equal(json(await request()).count, 130001); - assert.equal(calls, first.sources.length); + assert.equal(calls, 3); assert.deepEqual(json(await request('/status')).transactions, { used: 3, limit: 5000, From b6ad32009fec418d1a5bbff4aa18adb1fbf5cd4c Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Thu, 5 Nov 2026 12:52:28 +0400 Subject: [PATCH 21/61] Say why Transit and Bike Share rows are empty outside coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- docs/CURRENT-STATE.md | 13 ++ src/i18n/locales/ar.json | 9 ++ src/i18n/locales/de.json | 5 + src/i18n/locales/es.json | 6 + src/i18n/locales/fr.json | 6 + src/i18n/locales/it.json | 6 + src/i18n/locales/ja.json | 4 + src/i18n/locales/pt.json | 6 + src/i18n/locales/ru.json | 7 ++ src/i18n/locales/uk.json | 7 ++ src/i18n/locales/zh-CN.json | 4 + src/i18n/locales/zh-Hant.json | 4 + src/layers/bikeshare/controls.js | 22 +++- src/layers/bikeshare/coverageStatus.test.mjs | 124 +++++++++++++++++++ src/layers/bikeshare/viewport.js | 3 + src/layers/transit/lifecycle.test.mjs | 39 ++++++ src/layers/transit/queries.js | 13 +- src/layers/transit/viewport.js | 3 + src/ui/layerPanel.js | 9 +- src/ui/layerPanel.test.mjs | 54 ++++++++ src/ui/statusText.js | 63 ++++++++++ src/ui/statusText.test.mjs | 58 ++++++++- src/voice/resultDisplay.js | 31 +---- 23 files changed, 459 insertions(+), 37 deletions(-) create mode 100644 src/layers/bikeshare/coverageStatus.test.mjs diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index f1244947d4..8368eeacf3 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1817,6 +1817,19 @@ Mapped-installation zoom guidance appears in the layer row without counting as a global loading failure. Guidance statuses do not suppress independent refresh errors. +Transit and Bike Share report the same kind of guidance when no feed or system +covers the view, instead of an undated `never`. Above their altitude gates the +rows read `GTFS-RT · Fly below 3,000 km to a covered region` and +`GBFS · Fly below 48 km to a covered city`; lower down over a city neither +covers (London, Tokyo) they read `GTFS-RT · No feed here yet · N regions +available` and `GBFS · No bike share here yet · N systems available`, N being +the enabled feeds and the catalogued systems. The +chip stays ON. A Bike Share city that is loading or failed keeps its own +loading or error text. Leaving every covered feed or system clears the layer's +last-update time, so the row never dates data it no longer draws. The same +English notes are the voice analyst's empty-result notes; both surfaces show +them translated through `translateStatusMessage` (`src/ui/statusText.js`). + ## Places and CCTV request bounds With a Google key configured, nearby and text search reject missing, blank, diff --git a/src/i18n/locales/ar.json b/src/i18n/locales/ar.json index c9fca14ce6..b7193b9e87 100644 --- a/src/i18n/locales/ar.json +++ b/src/i18n/locales/ar.json @@ -2912,6 +2912,15 @@ "many": "لا مصدر بيانات هنا بعد · {n} منطقة متاحة", "other": "لا مصدر بيانات هنا بعد · {n} منطقة متاحة" }, + "Fly below {km} km to a covered city": "انخفض إلى ما دون {km} كم فوق مدينة مغطاة", + "No bike share here yet · {n} systems available": { + "zero": "لا دراجات مشتركة هنا بعد · {n} نظام متاح", + "one": "لا دراجات مشتركة هنا بعد · نظام واحد متاح ({n})", + "two": "لا دراجات مشتركة هنا بعد · نظامان متاحان ({n})", + "few": "لا دراجات مشتركة هنا بعد · {n} أنظمة متاحة", + "many": "لا دراجات مشتركة هنا بعد · {n} نظامًا متاحًا", + "other": "لا دراجات مشتركة هنا بعد · {n} نظام متاح" + }, "degraded": "متدهور", "stale": "متقادم", "partial": "جزئي", diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index bb683ed9f9..57be9f3881 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -2662,6 +2662,11 @@ "one": "Hier noch kein Feed · {n} Region verfügbar", "other": "Hier noch kein Feed · {n} Regionen verfügbar" }, + "Fly below {km} km to a covered city": "Unter {km} km Höhe zu einer abgedeckten Stadt fliegen", + "No bike share here yet · {n} systems available": { + "one": "Hier noch kein Bikesharing · {n} System verfügbar", + "other": "Hier noch kein Bikesharing · {n} Systeme verfügbar" + }, "degraded": "eingeschränkt", "stale": "veraltet", "partial": "teilweise", diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index 10dcbef8f8..2a3bb478d8 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -2821,6 +2821,12 @@ "many": "Aún no hay fuente aquí · {n} de regiones disponibles", "other": "Aún no hay fuente aquí · {n} regiones disponibles" }, + "Fly below {km} km to a covered city": "Desciende por debajo de {km} km sobre una ciudad con cobertura", + "No bike share here yet · {n} systems available": { + "one": "Aún no hay bicis compartidas aquí · {n} sistema disponible", + "many": "Aún no hay bicis compartidas aquí · {n} de sistemas disponibles", + "other": "Aún no hay bicis compartidas aquí · {n} sistemas disponibles" + }, "Wind speed field unavailable": "Campo de velocidad del viento no disponible", "Decoder feeds": "Fuentes del decodificador", "WebUSB + decoder feeds": "WebUSB + fuentes del decodificador", diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 108e56f365..57186643bf 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -2531,6 +2531,12 @@ "many": "Pas encore de flux ici · {n} de régions disponibles", "other": "Pas encore de flux ici · {n} régions disponibles" }, + "Fly below {km} km to a covered city": "Descendez sous {km} km au-dessus d'une ville couverte", + "No bike share here yet · {n} systems available": { + "one": "Pas encore de vélos partagés ici · {n} système disponible", + "many": "Pas encore de vélos partagés ici · {n} de systèmes disponibles", + "other": "Pas encore de vélos partagés ici · {n} systèmes disponibles" + }, "degraded": "dégradé", "stale": "obsolète", "partial": "partiel", diff --git a/src/i18n/locales/it.json b/src/i18n/locales/it.json index 6768f93c76..cecbc7a034 100644 --- a/src/i18n/locales/it.json +++ b/src/i18n/locales/it.json @@ -2531,6 +2531,12 @@ "many": "Ancora nessun feed qui · {n} di regioni disponibili", "other": "Ancora nessun feed qui · {n} regioni disponibili" }, + "Fly below {km} km to a covered city": "Scendi sotto {km} km su una città coperta", + "No bike share here yet · {n} systems available": { + "one": "Ancora nessun bike sharing qui · {n} sistema disponibile", + "many": "Ancora nessun bike sharing qui · {n} di sistemi disponibili", + "other": "Ancora nessun bike sharing qui · {n} sistemi disponibili" + }, "degraded": "degradato", "stale": "obsoleto", "partial": "parziale", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index b4566b4cb1..47a84c9d46 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -2401,6 +2401,10 @@ "No feed here yet · {n} regions available": { "other": "ここにはまだフィードがありません · 利用可能な地域 {n}か所" }, + "Fly below {km} km to a covered city": "{km} km未満まで高度を下げ、カバー範囲内の都市へ移動してください", + "No bike share here yet · {n} systems available": { + "other": "ここにはまだシェアサイクルがありません · 利用可能なシステム {n}件" + }, "degraded": "性能低下", "stale": "更新遅延", "partial": "部分的", diff --git a/src/i18n/locales/pt.json b/src/i18n/locales/pt.json index 3f37cde2ec..2ac851bc01 100644 --- a/src/i18n/locales/pt.json +++ b/src/i18n/locales/pt.json @@ -2533,6 +2533,12 @@ "many": "Ainda não há feed aqui · {n} de regiões disponíveis", "other": "Ainda não há feed aqui · {n} regiões disponíveis" }, + "Fly below {km} km to a covered city": "Desça abaixo de {km} km sobre uma cidade com cobertura", + "No bike share here yet · {n} systems available": { + "one": "Ainda não há bicicletas compartilhadas aqui · {n} sistema disponível", + "many": "Ainda não há bicicletas compartilhadas aqui · {n} de sistemas disponíveis", + "other": "Ainda não há bicicletas compartilhadas aqui · {n} sistemas disponíveis" + }, "degraded": "degradado", "stale": "desatualizado", "partial": "parcial", diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index e279508ef8..cba8c8796b 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -2884,6 +2884,13 @@ "many": "Здесь пока нет потока данных · доступно {n} регионов", "other": "Здесь пока нет потока данных · доступно {n} региона" }, + "Fly below {km} km to a covered city": "Опуститесь ниже {km} км над городом с покрытием", + "No bike share here yet · {n} systems available": { + "one": "Здесь пока нет проката велосипедов · доступна {n} система", + "few": "Здесь пока нет проката велосипедов · доступны {n} системы", + "many": "Здесь пока нет проката велосипедов · доступно {n} систем", + "other": "Здесь пока нет проката велосипедов · доступно {n} системы" + }, "Wind speed field unavailable": "Поле скорости ветра недоступно", "Decoder feeds": "Потоки декодера", "WebUSB + decoder feeds": "WebUSB + потоки декодера", diff --git a/src/i18n/locales/uk.json b/src/i18n/locales/uk.json index 8c3b634b97..71054ea181 100644 --- a/src/i18n/locales/uk.json +++ b/src/i18n/locales/uk.json @@ -2595,6 +2595,13 @@ "many": "Тут поки немає потоку даних · доступно {n} регіонів", "other": "Тут поки немає потоку даних · доступно {n} регіону" }, + "Fly below {km} km to a covered city": "Опустіться нижче {km} км над містом із покриттям", + "No bike share here yet · {n} systems available": { + "one": "Тут поки немає прокату велосипедів · доступна {n} система", + "few": "Тут поки немає прокату велосипедів · доступні {n} системи", + "many": "Тут поки немає прокату велосипедів · доступно {n} систем", + "other": "Тут поки немає прокату велосипедів · доступно {n} системи" + }, "degraded": "з перебоями", "stale": "застарів", "partial": "частково", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index 6125315f29..0d4033ced9 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -2302,6 +2302,10 @@ "No feed here yet · {n} regions available": { "other": "此处暂无数据源 · 有 {n} 个覆盖区域" }, + "Fly below {km} km to a covered city": "请降至 {km} km 以下并飞往有覆盖的城市", + "No bike share here yet · {n} systems available": { + "other": "此处暂无共享单车 · 有 {n} 个可用系统" + }, "degraded": "降级", "stale": "过期", "partial": "部分可用", diff --git a/src/i18n/locales/zh-Hant.json b/src/i18n/locales/zh-Hant.json index 66eb37b964..457a32aebc 100644 --- a/src/i18n/locales/zh-Hant.json +++ b/src/i18n/locales/zh-Hant.json @@ -2290,6 +2290,10 @@ "No feed here yet · {n} regions available": { "other": "此處暫無數據源 · 有 {n} 個覆蓋區域" }, + "Fly below {km} km to a covered city": "請降至 {km} km 以下並飛往有覆蓋的城市", + "No bike share here yet · {n} systems available": { + "other": "此處暫無共享單車 · 有 {n} 個可用系統" + }, "degraded": "降級", "stale": "過期", "partial": "部分可用", diff --git a/src/layers/bikeshare/controls.js b/src/layers/bikeshare/controls.js index 5f73a2dc94..9930225066 100644 --- a/src/layers/bikeshare/controls.js +++ b/src/layers/bikeshare/controls.js @@ -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 diff --git a/src/layers/bikeshare/coverageStatus.test.mjs b/src/layers/bikeshare/coverageStatus.test.mjs new file mode 100644 index 0000000000..a9f17e73e1 --- /dev/null +++ b/src/layers/bikeshare/coverageStatus.test.mjs @@ -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`); + } +}); diff --git a/src/layers/bikeshare/viewport.js b/src/layers/bikeshare/viewport.js index 25a4df7d04..0739d341c0 100644 --- a/src/layers/bikeshare/viewport.js +++ b/src/layers/bikeshare/viewport.js @@ -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; } diff --git a/src/layers/transit/lifecycle.test.mjs b/src/layers/transit/lifecycle.test.mjs index ea547f85da..a269dc9e97 100644 --- a/src/layers/transit/lifecycle.test.mjs +++ b/src/layers/transit/lifecycle.test.mjs @@ -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', + ); +}); diff --git a/src/layers/transit/queries.js b/src/layers/transit/queries.js index b86613160a..8023cdb395 100644 --- a/src/layers/transit/queries.js +++ b/src/layers/transit/queries.js @@ -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 diff --git a/src/layers/transit/viewport.js b/src/layers/transit/viewport.js index 730126f10c..27cc0569ce 100644 --- a/src/layers/transit/viewport.js +++ b/src/layers/transit/viewport.js @@ -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); diff --git a/src/ui/layerPanel.js b/src/ui/layerPanel.js index b24e8be7b5..29a4bc3c08 100644 --- a/src/ui/layerPanel.js +++ b/src/ui/layerPanel.js @@ -11,14 +11,17 @@ import { } from './layerNames.js'; export { localizeLayerName } from './layerNames.js'; import { createWeatherPanel } from './weatherPanel.js'; -import { translateFeedError, translateStatusLine } from './statusText.js'; +import { + translateFeedError, + translateStatusLine, + translateStatusMessage, +} from './statusText.js'; import { formatNumber, getLocale, msg, onLocaleChange, t, - translateKnown, } from '../i18n/index.js'; // Feed-state values are machine ids (QA hooks, CSS feed-* classes); only the @@ -691,7 +694,7 @@ export class LayerPanel { typeof stats.statusMessage === 'string' && stats.statusMessage.trim() ) { - return `${source} · ${translateKnown(stats.statusMessage.trim())}`; + return `${source} · ${translateStatusMessage(stats.statusMessage.trim())}`; } const ago = stats.lastUpdate ? this._timeAgo(stats.lastUpdate) : t('never'); if (stats.loading) { diff --git a/src/ui/layerPanel.test.mjs b/src/ui/layerPanel.test.mjs index 73710e3fca..1be2df5d70 100644 --- a/src/ui/layerPanel.test.mjs +++ b/src/ui/layerPanel.test.mjs @@ -431,3 +431,57 @@ test('without the Utilities list, Directions stays in Data Layers under Utilitie restore(); } }); + +test('a layer with no feed in view says why instead of "never"', async () => { + const { LayerPanel, presentLayerCount, presentLayerToggle } = + await import('./layerPanel.js'); + const { setLocale } = await import('../i18n/index.js'); + const panel = LayerPanel.prototype; + const rows = [ + { + id: 'transit', + name: 'Transit', + source: 'GTFS-RT', + enabled: true, + stats: { + count: 0, + lastUpdate: null, + source: 'GTFS-RT', + status: 'zoom-in', + statusMessage: 'No feed here yet · 16 regions available', + }, + meta: 'GTFS-RT · No feed here yet · 16 regions available', + }, + { + id: 'bikeshare', + name: 'Bikeshare', + source: 'GBFS', + enabled: true, + stats: { + count: 0, + lastUpdate: null, + loading: false, + status: 'zoom-in', + statusMessage: 'Fly below 48 km to a covered city', + }, + meta: 'GBFS · Fly below 48 km to a covered city', + }, + ]; + for (const layer of rows) { + // Guidance is normal operation: the layer is on and nothing has failed. + assert.equal(presentLayerToggle(layer).text, 'ON'); + assert.equal(presentLayerCount(layer.stats).empty, true); + assert.equal(panel._buildMetaText(layer), layer.meta); + } + + setLocale('ru'); + try { + for (const layer of rows) { + const meta = panel._buildMetaText(layer); + assert.doesNotMatch(meta, /never|Fly below|No feed|covered/, meta); + assert.match(meta, /^(GTFS-RT|GBFS) · /, meta); + } + } finally { + setLocale('en'); + } +}); diff --git a/src/ui/statusText.js b/src/ui/statusText.js index 1af6b8b2ad..f4cbb59a0b 100644 --- a/src/ui/statusText.js +++ b/src/ui/statusText.js @@ -265,3 +265,66 @@ export function translateStatusLine(text) { .map(translateStatusPiece) .join(STATUS_SEPARATOR); } + +/** Thousands separators out of an English number ("3,000" → 3000). */ +const englishNumber = (text) => Number(text.replace(/,/g, '')); + +// Coverage notes of a layer whose view has no feed, whole lines with a number +// in them: transit (transit/queries.js) and bikeshare (bikeshare/controls.js). +// Their " · " is part of one sentence, so they are matched before the line is +// split into pieces. Keep these in step with the producers. +const COVERAGE_NOTE_PATTERNS = [ + [ + /^Fly below ([\d,]+) km to a covered region$/, + ([, km]) => + t('Fly below {km} km to a covered region', { + km: formatNumber(englishNumber(km)), + }), + ], + [ + /^No feed here yet · ([\d,]+) regions available$/, + ([, regions]) => { + const count = englishNumber(regions); + return tn( + count, + 'No feed here yet · {n} region available', + 'No feed here yet · {n} regions available', + { n: formatNumber(count) }, + ); + }, + ], + [ + /^Fly below ([\d,]+) km to a covered city$/, + ([, km]) => + t('Fly below {km} km to a covered city', { + km: formatNumber(englishNumber(km)), + }), + ], + [ + /^No bike share here yet · ([\d,]+) systems available$/, + ([, systems]) => { + const count = englishNumber(systems); + return tn( + count, + 'No bike share here yet · {n} system available', + 'No bike share here yet · {n} systems available', + { n: formatNumber(count) }, + ); + }, + ], +]; + +/** + * A layer's status message in the UI language: its catalog entry, a coverage + * note by its shape, or a status line translated piece by piece. + */ +export function translateStatusMessage(text) { + if (typeof text !== 'string') return text; + const known = translateKnown(text); + if (known !== text) return known; + for (const [pattern, format] of COVERAGE_NOTE_PATTERNS) { + const match = pattern.exec(text); + if (match) return format(match); + } + return translateStatusLine(text); +} diff --git a/src/ui/statusText.test.mjs b/src/ui/statusText.test.mjs index a64975c48b..1b6479b45c 100644 --- a/src/ui/statusText.test.mjs +++ b/src/ui/statusText.test.mjs @@ -3,7 +3,11 @@ import assert from 'node:assert/strict'; import test from 'node:test'; import { setLocale, t } from '../i18n/index.js'; -import { translateFeedError, translateStatusLine } from './statusText.js'; +import { + translateFeedError, + translateStatusLine, + translateStatusMessage, +} from './statusText.js'; function inLocale(locale, run) { setLocale(locale); @@ -75,3 +79,55 @@ for (const locale of ['es', 'ru']) { }); }); } + +// A layer's coverage note when no feed covers the view: one sentence with a +// " · " in it (transit/queries.js, bikeshare/controls.js). +const COVERAGE_NOTES = [ + 'Fly below 3,000 km to a covered region', + 'No feed here yet · 16 regions available', + 'Fly below 48 km to a covered city', + 'No bike share here yet · 61 systems available', +]; + +test('en: coverage notes show as they came', () => { + setLocale('en'); + for (const text of COVERAGE_NOTES) + assert.equal(translateStatusMessage(text), text); + assert.equal( + translateStatusMessage('No bike share here yet · 1 systems available'), + 'No bike share here yet · 1 system available', + ); +}); + +for (const locale of ['es', 'ru', 'ja']) { + test(`${locale}: a coverage note translates whole, numbers kept`, () => { + inLocale(locale, () => { + for (const text of COVERAGE_NOTES) { + const shown = translateStatusMessage(text); + assert.doesNotMatch( + shown, + /\b(Fly|below|covered|feed|bike share|available)\b/, + shown, + ); + const number = /[\d,]+(?= km| regions| systems)/.exec(text)[0]; + assert.ok( + shown.replace(/[^\d]/g, '').includes(number.replace(/,/g, '')), + shown, + ); + } + }); + }); + + test(`${locale}: a status message without a coverage note keeps its other forms`, () => { + inLocale(locale, () => { + assert.equal( + translateStatusMessage('Upstream response too large'), + t('Upstream response too large'), + ); + assert.equal( + translateStatusMessage('2 feeds live · 14 heard'), + translateStatusLine('2 feeds live · 14 heard'), + ); + }); + }); +} diff --git a/src/voice/resultDisplay.js b/src/voice/resultDisplay.js index 112200f7f1..cd909d2f76 100644 --- a/src/voice/resultDisplay.js +++ b/src/voice/resultDisplay.js @@ -29,7 +29,7 @@ import { } from '../i18n/index.js'; import { layerNameForId, sourceLabel } from '../ui/layerNames.js'; import { localizePlaceName } from '../ui/placeNames.js'; -import { translateStatusLine } from '../ui/statusText.js'; +import { translateStatusMessage } from '../ui/statusText.js'; import { formatQuantity } from '../ui/unitLabels.js'; /** Split "a; b" caveat text into separate notes. */ @@ -397,27 +397,6 @@ const NOTE_PATTERNS = [ 'Contacts panel snapshot — the same retained cohort supplies the card, speech, and follow-up memory', )) + period, ], - // Transit's empty note when no feed covers the view (transit/queries.js); - // the model gets the English. - [ - /^Fly below ([\d,]+) km to a covered region$/, - ([, km]) => - t('Fly below {km} km to a covered region', { - km: formatNumber(Number(km.replace(/,/g, ''))), - }), - ], - [ - /^No feed here yet · ([\d,]+) regions available$/, - ([, regions]) => { - const count = Number(regions.replace(/,/g, '')); - return tn( - count, - 'No feed here yet · {n} region available', - 'No feed here yet · {n} regions available', - { n: formatNumber(count) }, - ); - }, - ], [ /^([a-z0-9-]+) (off|loading|error)$/, ([, key, status]) => @@ -444,10 +423,10 @@ function shownNote(text) { const shown = match ? show(match) : null; if (shown) return shown; } - // A layer's empty note can be its status line, English pieces joined by - // " · " ("feeds 1090, 978 stale · 0 heard", "TTC 0 (95s old)"). - const known = translateKnown(text); - return known !== text ? known : translateStatusLine(text); + // A layer's empty note can be its coverage note ("Fly below 3,000 km to a + // covered region") or its status line, English pieces joined by " · " + // ("feeds 1090, 978 stale · 0 heard", "TTC 0 (95s old)"). + return translateStatusMessage(text); } /** Feed states as the card's chips show them; the values stay English. */ From 25c33893f666bf77b8cb416151657ab84a4a1834 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Thu, 5 Nov 2026 12:53:09 +0400 Subject: [PATCH 22/61] Add the changelog entry for #1576 --- changelog.d/1576-transit-bikeshare-coverage-prompt.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog.d/1576-transit-bikeshare-coverage-prompt.md diff --git a/changelog.d/1576-transit-bikeshare-coverage-prompt.md b/changelog.d/1576-transit-bikeshare-coverage-prompt.md new file mode 100644 index 0000000000..c3dcbe82a2 --- /dev/null +++ b/changelog.d/1576-transit-bikeshare-coverage-prompt.md @@ -0,0 +1,6 @@ +- Say why Transit and Bike Share are empty outside coverage. Over a city with + no feed or system (London, Tokyo) their Layers rows read + `No feed here yet · 16 regions available` and + `No bike share here yet · 61 systems available`, or how low to fly, instead + of `never`; leaving coverage clears the last-update time (German, @gekh, + #1576). From e5ab5f945a3ea5ae28c21a200a63fd2277f4d0dd Mon Sep 17 00:00:00 2001 From: quanticsoul4772 <71096528+quanticsoul4772@users.noreply.github.com> Date: Thu, 5 Nov 2026 05:43:36 -0800 Subject: [PATCH 23/61] test(nominatim): share one POSIX guard and say the cache is private only on POSIX Co-Authored-By: Claude Opus 5.5 --- src/tooling/nominatimOutlineRoute.test.mjs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/tooling/nominatimOutlineRoute.test.mjs b/src/tooling/nominatimOutlineRoute.test.mjs index 774099efe4..74f0b2d6a4 100644 --- a/src/tooling/nominatimOutlineRoute.test.mjs +++ b/src/tooling/nominatimOutlineRoute.test.mjs @@ -684,29 +684,34 @@ test('the disk cache survives a restart and stays within its bounds', async () = await createNominatimCache({ dir, now: time.now }).get('k0'), null, ); - // Windows has no POSIX mode bits (directories stat as 0o666), so only - // POSIX systems can check privacy this way. - if (process.platform !== 'win32') + // The cache is private only through POSIX mode bits. Windows has none + // (directories stat as 0o666) and the cache keeps the checkout's ACLs, + // so these checks run, and privacy holds, only on POSIX systems. + const posixModes = process.platform !== 'win32'; + if (posixModes) { assert.equal( fs.statSync(dir).mode & 0o777, 0o700, - 'the query cache directory is private', + 'the query cache directory is private (POSIX modes)', ); + } const text = fs .readdirSync(dir) .filter((name) => name.endsWith('.json')) .map((name) => fs.readFileSync(path.join(dir, name), 'utf8')) .join('\n'); assert.equal(text.includes('k4'), false, 'disk entries never store raw keys'); - if (process.platform !== 'win32') + if (posixModes) { for (const name of fs .readdirSync(dir) - .filter((entry) => entry.endsWith('.json'))) + .filter((entry) => entry.endsWith('.json'))) { assert.equal( fs.statSync(path.join(dir, name)).mode & 0o777, 0o600, - `${name} is private`, + `${name} is private (POSIX modes)`, ); + } + } fs.rmSync(dir, { recursive: true, force: true }); }); From df87419e64815164062637b00769c502999a3bb7 Mon Sep 17 00:00:00 2001 From: quanticsoul4772 <71096528+quanticsoul4772@users.noreply.github.com> Date: Thu, 5 Nov 2026 05:43:42 -0800 Subject: [PATCH 24/61] test(tools): pin the raw near-360 satellite azimuths and list the tools with the heading helper Co-Authored-By: Claude Opus 5.5 --- docs/CURRENT-STATE.md | 9 ++++----- src/tools/queries/environment.js | 1 + src/tools/queries/space.test.mjs | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index e546fd563d..d03064e8f0 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -246,10 +246,9 @@ perimeters, terrain height, military installations and map features, plus a combined situation brief, military awareness around a point, the app's heads-up display caption, and a link that opens the app over an area. Tools reuse the layers' portable source factories, take a shared `area` argument (place name, bounding box, or point and radius) and cap -lists at 25 rows by default. Vessel `course_deg` and `heading_deg`, aircraft -`course_deg`, transit `bearing_deg`, camera `heading_deg` and satellite -`rise_azimuth_deg` and `azimuth_deg` are whole degrees from 0 to 359; a -direction that rounds to 360 reads 0, and larger or negative values wrap. `aircraft_in_area` and `vessels_in_area` can also +lists at 25 rows by default. Their whole-degree directions round through +`roundHeadingDegrees`, listed with the heading readouts below. +`aircraft_in_area` and `vessels_in_area` can also count every match by a field (`group_by`: airline, read from the ICAO designator in the callsign, or operator, country or type for aircraft; type or destination for ships; the ten largest groups, then other and unknown counts; @@ -6091,7 +6090,7 @@ apply to `public/` assets or built-preview serving. - **Cockpit camera anchor:** first-person mode does not write feed-boundary corrections directly into the camera. A cockpit-only inertial anchor advances from the selected aircraft's displayed course and speed, then converges toward the authoritative delayed track with correction capped below forward motion. The displayed kinematics are derived from the same consecutive fix segment as the rendered position, with raw feed speed/course used only as fallback; a transient zero/missing feed speed therefore cannot freeze a visibly moving aircraft after layer enable or a map/cockpit handoff. Rendered altitude continues to come from that interpolated track position. Late ADS-B fixes and short render stalls can remove drift without accelerating or reversing the view. Camera placement runs before scene update/culling at a bounded 20 Hz so a moving cockpit does not force Photoreal 3D Tiles to retraverse on every display frame; textual instruments update at 10 Hz and context/layout work at 4 Hz. Every far Cockpit contact pip shares one stable Cesium texture-atlas entry and skips unused screen-projected course calculations, while only in-range 2D aircraft silhouettes pay the screen-projected rotation cost; ambient glTF collections are hidden/retained rather than synchronously destroyed at cockpit entry, and context rails lay out only on explicit content/state changes and viewport resize. The deliberate 15/30-second layer interpolation delays and per-Cesium-frame position caches remain unchanged. - **Cockpit route, vision, and view controls:** visible on-screen `COCKPIT`, `RESET`, and `EXIT COCKPIT` controls replace reliance on the `C` shortcut. RESET uses the same canonical globe route as the map and voice actions, exits Cockpit, and releases its camera ownership rather than exposing the hidden map-style top action. When the tracked commercial flight has a plausible ADSBDB route, the top of the right briefing rail shows a compact `FROM → TO` airport strip and the visor shows a centered estimated-destination chevron with its relative bearing; its destination label rounds to whole degrees in 000–359, wrapping rounded north to 000° while the chevron continues to use the relative bearing independently of label rounding; absent or implausible route data hides the strip and cue rather than guessing. The cockpit-local vision control is an interactive `PREV / CURRENT / NEXT` carousel over `NORMAL`, `CRT`, `NVG`, `FLIR`, `ANIME`, and `NOIR`; its previous/next actions wrap, and activating the current value advances to the next style. Cockpit enters on the active map preset, so a Cyber FLIR map opens Cockpit on FLIR while Normal remains a distinct option instead of producing a second FLIR entry. Cockpit choices temporarily activate the existing Cesium post-process stages, while exiting Cockpit through either EXIT or RESET restores the pre-entry map style. The regional-news page uses a free Google News RSS locality query first, with the existing GDELT query retained only as a fail-soft fallback; linked headlines remain reporting, not verified incidents or risk intelligence. - Cockpit wind-direction labels wrap after rounding to whole degrees, so a direction of 359.5° displays as `N · 0°` rather than `N · 360°`. -- The transit, ALPR, vessel, CCTV, Local ADS-B, flight and military context, awareness, Cockpit and Street Level heading readouts round through `roundHeadingDegrees` in `src/data/headingDegrees.js` (whole degrees 0–359, `null` when not finite, so each caller keeps its own placeholder); `normalizeHeading` lives there too and `cockpitMath.js` re-exports it. The Cockpit's `TRACK ACQUIRED` signal uses `formatHeadingReadout`, so a 359.6° track reads `COURSE 000°`. +- The transit, ALPR, vessel, CCTV, Local ADS-B, flight and military context, awareness, Cockpit and Street Level heading readouts, and the query tools' vessel `course_deg` and `heading_deg`, aircraft `course_deg`, transit `bearing_deg`, camera `heading_deg` and satellite `rise_azimuth_deg` and `azimuth_deg`, round through `roundHeadingDegrees` in `src/data/headingDegrees.js` (whole degrees 0–359, `null` when not finite, so each caller keeps its own placeholder); `normalizeHeading` lives there too and `cockpitMath.js` re-exports it. The Cockpit's `TRACK ACQUIRED` signal uses `formatHeadingReadout`, so a 359.6° track reads `COURSE 000°`. - **Cockpit missing observations:** missing local weather observations remain unknown rather than being converted to zero or clear skies, in the briefing and in the cloud effects; a missing temperature drops the whole local weather record, including its wind and condition. - **Cockpit weather status:** the earlier multi-canvas atmospheric compositor remains fail-closed and is not attached to the live viewer. Cockpit clouds are a separate transparent WebGL pass with a capped 520×320 framebuffer, 24 ray steps, three FBM octaves, and a 12 FPS ceiling. It defaults off and starts only when local storage explicitly contains the persisted `WX ON` opt-in (`'1'`). When opted in, observations refresh after five minutes or 25 km of aircraft movement, fail transparent when unavailable or clear, and stop on exit or disable. `WX OFF` governs atmospheric rendering only: the briefing still fetches source-backed Natural Earth region, headline, and Open-Meteo local-information data, aborting and replacing any in-flight request when the selected aircraft changes. No weather effect runs in map mode and no synthetic fallback is shown. - **Cockpit trail visibility:** entering cockpit hides the selected aircraft's trail body and head so they cannot cross the first-person view; exit restores them. This cockpit-only presentation change does not alter the normal map-mode invariant that aircraft trails render through terrain using their depth-fail material. diff --git a/src/tools/queries/environment.js b/src/tools/queries/environment.js index 08db732fc9..0af696e369 100644 --- a/src/tools/queries/environment.js +++ b/src/tools/queries/environment.js @@ -71,6 +71,7 @@ function weatherRow(weather) { precipitation_mm: weather.precipitationMm ?? null, cloud_cover_pct: weather.cloudCoverPct ?? null, wind_kph: weather.windKph ?? null, + // Raw Open-Meteo value, like the fields above; it reports north as 360. wind_direction_deg: weather.windDirectionDeg ?? null, visibility_m: weather.visibilityM ?? null, }; diff --git a/src/tools/queries/space.test.mjs b/src/tools/queries/space.test.mjs index 0e44fe208f..41394e3051 100644 --- a/src/tools/queries/space.test.mjs +++ b/src/tools/queries/space.test.mjs @@ -2,6 +2,10 @@ import assert from 'node:assert/strict'; import test from 'node:test'; import { twoline2satrec } from 'satellite.js'; import { composeCatalog, coreTools } from '../index.js'; +import { + findNextSatellitePass, + lookAnglesAt, +} from '../../data/satellitePass.js'; import { noradIdFromSatnum, parseTleText, @@ -301,7 +305,20 @@ test('satellite azimuths that round to 360 read as 0', async () => { tools: coreTools, services: { satellites: satellites(), clock: CLOCK }, }); - // From these points the ISS rises at 359.7° and stands at 359.8° at CLOCK. + // These points are chosen so the ISS's raw azimuths fall just below 360°; + // pin that first, so the test cannot pass on a raw value already near 0. + const [, line1, line2] = TLE.split('\n'); + const iss = twoline2satrec(line1, line2); + const nearNorth = (deg) => deg > 359.5 && deg < 360; + const rawPass = findNextSatellitePass({ + satrec: iss, + latDeg: 10, + lonDeg: 30, + fromMs: CLOCK.now(), + }); + assert.ok(nearNorth(rawPass.riseAzDeg), `rise ${rawPass.riseAzDeg}°`); + const rawLook = lookAnglesAt(iss, CLOCK.now(), 39.25, 65.75); + assert.ok(nearNorth(rawLook.azDeg), `azimuth ${rawLook.azDeg}°`); const pass = await catalog.call('next_satellite_pass', { location: { lat: 10, lon: 30 }, }); From 90db4eb2c9ed0c61adbfe6ffaf7a17b1ffe1d829 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Thu, 5 Nov 2026 21:21:03 +0400 Subject: [PATCH 25/61] Name the real gate altitude and repaint coverage rows at once The Transit prompt said "Fly below 3,000 km", but the closed gate opens at 2,850 km; it now names the enter threshold, as Bike Share does. When the camera changes coverage, Transit and Bike Share ask the Layers panel to repaint instead of leaving the old prompt up until the next 15 s / 60 s tick. --- docs/CURRENT-STATE.md | 2 +- src/layers/bikeshare/controls.js | 9 ++ src/layers/bikeshare/lifecycle.js | 1 + src/layers/bikeshare/state.js | 4 + src/layers/bikeshare/viewport.js | 17 ++++ src/layers/promptRepaint.test.mjs | 122 +++++++++++++++++++++++++ src/layers/transit/gatePrompt.test.mjs | 66 +++++++++++++ src/layers/transit/lifecycle.test.mjs | 2 +- src/layers/transit/queries.js | 4 +- src/layers/transit/viewport.js | 7 ++ src/ui/statusText.test.mjs | 2 +- src/voice/analystEmptyNotes.test.mjs | 2 +- src/voice/resultDisplay.js | 2 +- 13 files changed, 233 insertions(+), 7 deletions(-) create mode 100644 src/layers/promptRepaint.test.mjs create mode 100644 src/layers/transit/gatePrompt.test.mjs diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 8368eeacf3..946254fbfb 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1819,7 +1819,7 @@ errors. Transit and Bike Share report the same kind of guidance when no feed or system covers the view, instead of an undated `never`. Above their altitude gates the -rows read `GTFS-RT · Fly below 3,000 km to a covered region` and +rows read `GTFS-RT · Fly below 2,850 km to a covered region` and `GBFS · Fly below 48 km to a covered city`; lower down over a city neither covers (London, Tokyo) they read `GTFS-RT · No feed here yet · N regions available` and `GBFS · No bike share here yet · N systems available`, N being diff --git a/src/layers/bikeshare/controls.js b/src/layers/bikeshare/controls.js index 9930225066..78edd907b0 100644 --- a/src/layers/bikeshare/controls.js +++ b/src/layers/bikeshare/controls.js @@ -14,6 +14,15 @@ export function createControls({ state: layerState, services, parts, source }) { updateInterval: STATUS_POLL_MS, + /** + * Keep the manager so camera-driven coverage changes can repaint the row + * before the next status poll. + * @param {object} dataManager DataLayerManager instance. + */ + attachDataManager(dataManager) { + layerState._dataManager = dataManager; + }, + /** * Return a sampled array of detectable station objects for HUD overlay rendering. * @param {Object} [options] - Sampling options (maxCount, seed). diff --git a/src/layers/bikeshare/lifecycle.js b/src/layers/bikeshare/lifecycle.js index 3e46b59724..050269bfd4 100644 --- a/src/layers/bikeshare/lifecycle.js +++ b/src/layers/bikeshare/lifecycle.js @@ -169,6 +169,7 @@ export function createLifecycle({ viewer.scene.primitives.remove(layerState._pointCollection); layerState._pointCollection = null; } + layerState._dataManager = null; layerState._viewer = null; }, }; diff --git a/src/layers/bikeshare/state.js b/src/layers/bikeshare/state.js index 3617914bf5..518c2397aa 100644 --- a/src/layers/bikeshare/state.js +++ b/src/layers/bikeshare/state.js @@ -19,6 +19,10 @@ export function createState({ services }) { layerState._viewer = null; + /** @type {{ refreshLayerStats?: () => void }|null} Manager that repaints the layer's row. */ + + layerState._dataManager = null; + /** @type {Cesium.PointPrimitiveCollection|null} Primitive collection for station dots. */ layerState._pointCollection = null; diff --git a/src/layers/bikeshare/viewport.js b/src/layers/bikeshare/viewport.js index 0739d341c0..dbc328f61d 100644 --- a/src/layers/bikeshare/viewport.js +++ b/src/layers/bikeshare/viewport.js @@ -116,6 +116,14 @@ export function createViewport({ state: layerState, services, parts, source }) { parts.rendering.removeCityPoints(cityId); } + /** + * Repaint the layer's row now. Its text follows the camera (coverage + * prompt, station count), and the manager tick is 60 s. + */ + function refreshRow() { + layerState._dataManager?.refreshLayerStats?.(); + } + /** Deactivate all currently active cities and clear the active set. */ function deactivateAllCities() { @@ -205,9 +213,11 @@ export function createViewport({ state: layerState, services, parts, source }) { const generation = ++layerState._proximityGeneration; const altitude = getCameraAltitude(layerState._viewer); + const wasGateEnabled = layerState._altitudeGateEnabled; // Altitude gate: disable all cities when camera is too high if (!shouldActivateAtAltitude(altitude)) { deactivateAllCities(); + if (wasGateEnabled) refreshRow(); return; } @@ -226,12 +236,18 @@ export function createViewport({ state: layerState, services, parts, source }) { if (!nextActive.has(cityId)) layerState._failedCityIds.delete(cityId); } + const changed = + !wasGateEnabled || + nextActive.size !== layerState._activeCityIds.size || + [...nextActive].some((cityId) => !layerState._activeCityIds.has(cityId)); layerState._activeCityIds = nextActive; if (layerState._activeCityIds.size === 0) { layerState._count = 0; layerState._lastUpdate = null; + if (changed) refreshRow(); return; } + if (changed) refreshRow(); // Only activate cities that don't already have rendered points const toActivate = []; @@ -243,6 +259,7 @@ export function createViewport({ state: layerState, services, parts, source }) { await Promise.all( toActivate.map((cityId) => activateCity(cityId, generation)), ); + if (generation === layerState._proximityGeneration) refreshRow(); } /** Schedule a debounced proximity check after camera movement. */ diff --git a/src/layers/promptRepaint.test.mjs b/src/layers/promptRepaint.test.mjs new file mode 100644 index 0000000000..563aaeac77 --- /dev/null +++ b/src/layers/promptRepaint.test.mjs @@ -0,0 +1,122 @@ +// When the camera changes which coverage prompt a Transit or +// Bike Share row shows, the layer asks the panel to repaint at once, instead +// of leaving the old prompt up until the manager's next tick (Transit 15 s, +// Bike Share 60 s). +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { createState as createBikeState } from './bikeshare/state.js'; +import { createControls as createBikeControls } from './bikeshare/controls.js'; +import { createModel as createBikeModel } from './bikeshare/model.js'; +import { createViewport as createBikeViewport } from './bikeshare/viewport.js'; +import { createState as createTransitState } from './transit/state.js'; +import { createViewport as createTransitViewport } from './transit/viewport.js'; +import { createQueries as createTransitQueries } from './transit/queries.js'; + +const rad = Math.PI / 180; +const LONDON = { lat: 51.5072, lon: -0.1276 }; +const BOSTON = { lat: 42.3601, lon: -71.0589 }; + +const services = () => ({ + overlays: { + setOverlayEntries() {}, + setOverlaySourceVisible() {}, + clearOverlaySource() {}, + }, + render: { governorRequestRender() {} }, +}); + +function viewer(at, height) { + return { + camera: { + positionCartographic: { + height, + latitude: at.lat * rad, + longitude: at.lon * rad, + }, + computeViewRectangle: () => undefined, + }, + scene: { globe: {} }, + }; +} + +function spyManager() { + const dm = { repaints: 0 }; + dm.refreshLayerStats = () => { + dm.repaints++; + }; + return dm; +} + +test('Bike Share: flying from London into Boston repaints the prompt row', async () => { + const svc = services(); + const state = createBikeState({ services: svc }); + const parts = { + queries: { collectDetectableStations: () => [] }, + model: createBikeModel({ state, services: svc, parts: {}, source: null }), + ingestion: { + abortInFlight() {}, + loadCityStationInfo: async () => new Map(), + loadCityStationStatus: async () => new Map(), + }, + rendering: { + removeCityPoints() {}, + ensureCityPoints() {}, + applyStatusToPoints() {}, + }, + }; + parts.viewport = createBikeViewport({ + state, + services: svc, + parts, + source: null, + }); + const { methods } = createBikeControls({ + state, + services: svc, + parts, + source: {}, + }); + state._enabled = true; + const dm = spyManager(); + methods.attachDataManager(dm); + + state._viewer = viewer(LONDON, 8_000); + await parts.viewport.runProximityCheck(); + assert.equal(methods.getStats().status, 'zoom-in'); + + const before = dm.repaints; + state._viewer = viewer(BOSTON, 3_000); + await parts.viewport.runProximityCheck(); + assert.equal(methods.getStats().status, undefined, 'Boston is covered'); + assert.ok(dm.repaints > before, 'the row was asked to repaint'); +}); + +test('Transit: leaving Boston for London repaints the row', () => { + const svc = services(); + const state = createTransitState({ services: svc }); + const parts = { + ingestion: { + feedStatus: () => ({ count: 0 }), + pollFeed() {}, + removeFeedVehicles() {}, + sweepAgedVehicles() {}, + }, + rendering: { requestVisibility() {}, syncRenderHold() {} }, + }; + parts.viewport = createTransitViewport({ state, services: svc, parts }); + const queries = createTransitQueries({ state, parts }).methods; + state._enabled = true; + const dm = spyManager(); + state._dataManager = dm; + + state._viewer = viewer(BOSTON, 4_000); + parts.viewport.runProximityCheck(); + assert.ok(state._activeFeeds.size > 0, 'Boston has a feed'); + state._lastUpdate = Date.now(); + + const before = dm.repaints; + state._viewer = viewer(LONDON, 4_000); + parts.viewport.runProximityCheck(); + assert.equal(queries.getStats().status, 'zoom-in'); + assert.ok(dm.repaints > before, 'the row was asked to repaint'); +}); diff --git a/src/layers/transit/gatePrompt.test.mjs b/src/layers/transit/gatePrompt.test.mjs new file mode 100644 index 0000000000..7f439fcdc6 --- /dev/null +++ b/src/layers/transit/gatePrompt.test.mjs @@ -0,0 +1,66 @@ +// The Transit coverage prompt names the altitude the closed gate +// actually opens at. Descending over Boston to 2,900 km (below 3,000 km, above +// the 2,850 km enter threshold) loads nothing, so a prompt "Fly below 3,000 km" +// asks for something the camera has already done. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { createState } from './state.js'; +import { createViewport } from './viewport.js'; +import { createQueries } from './queries.js'; +import { ACTIVATION_ENTER_ALTITUDE_M } from './policy.js'; + +const BOSTON = { lat: 42.3601, lon: -71.0589 }; + +function makeLayer() { + const services = { + overlays: { + setOverlayEntries() {}, + setOverlaySourceVisible() {}, + clearOverlaySource() {}, + }, + render: { governorRequestRender() {} }, + }; + const state = createState({ services }); + const polled = []; + const parts = { + ingestion: { + feedStatus: () => ({ count: 0 }), + pollFeed: (feed) => polled.push(feed.id), + removeFeedVehicles() {}, + sweepAgedVehicles() {}, + }, + rendering: { requestVisibility() {}, syncRenderHold() {} }, + }; + parts.viewport = createViewport({ state, services, parts }); + const queries = createQueries({ state, parts }).methods; + state._enabled = true; + const rad = Math.PI / 180; + state._viewer = { + camera: { + positionCartographic: { + height: 0, + latitude: BOSTON.lat * rad, + longitude: BOSTON.lon * rad, + }, + computeViewRectangle: () => undefined, + }, + scene: { globe: {} }, + }; + return { state, queries, viewport: parts.viewport, polled }; +} + +test('below the prompted altitude but above the gate, the prompt names the gate', () => { + const { state, queries, viewport, polled } = makeLayer(); + state._viewer.camera.positionCartographic.height = 2_900_000; + viewport.runProximityCheck(); + + // Nothing loads at 2,900 km: the gate opens at the enter threshold. + assert.equal(state._altitudeGateOpen, false); + assert.deepEqual(polled, []); + + const km = Math.round(ACTIVATION_ENTER_ALTITUDE_M / 1000).toLocaleString( + 'en-US', + ); + const { statusMessage } = queries.getStats(); + assert.equal(statusMessage, `Fly below ${km} km to a covered region`); +}); diff --git a/src/layers/transit/lifecycle.test.mjs b/src/layers/transit/lifecycle.test.mjs index a269dc9e97..dc18fd6f02 100644 --- a/src/layers/transit/lifecycle.test.mjs +++ b/src/layers/transit/lifecycle.test.mjs @@ -4018,6 +4018,6 @@ test('a view with no feed reads its coverage prompt, not an undated feed', async app.advance(1_000); assert.equal( app.layer.getStats().statusMessage, - 'Fly below 3,000 km to a covered region', + 'Fly below 2,850 km to a covered region', ); }); diff --git a/src/layers/transit/queries.js b/src/layers/transit/queries.js index 8023cdb395..7489292136 100644 --- a/src/layers/transit/queries.js +++ b/src/layers/transit/queries.js @@ -1,5 +1,5 @@ import { - ACTIVATION_ALTITUDE_M, + ACTIVATION_ENTER_ALTITUDE_M, FEED_STALE_AFTER_MS, aggregateTransitFeedHealth, transitDetectionClass, @@ -245,7 +245,7 @@ export function createQueries({ state, parts }) { // (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`; + : `Fly below ${Math.round(ACTIVATION_ENTER_ALTITUDE_M / 1000).toLocaleString('en-US')} km to a covered region`; return { count: 0, lastUpdate: state._lastUpdate, diff --git a/src/layers/transit/viewport.js b/src/layers/transit/viewport.js index 27cc0569ce..0e3b317d47 100644 --- a/src/layers/transit/viewport.js +++ b/src/layers/transit/viewport.js @@ -83,7 +83,9 @@ export function createViewport({ state, services, parts }) { if (!state._enabled || !state._viewer) return; refreshViewBounds(); const altitude = getCameraAltitude(); + const wasGateOpen = state._altitudeGateOpen; state._altitudeGateOpen = altitudeGateOpen(altitude); + let changed = state._altitudeGateOpen !== wasGateOpen; const center = state._altitudeGateOpen ? getCameraCenterLatLon() : null; const desired = new Map(); if (center) { @@ -106,6 +108,7 @@ export function createViewport({ state, services, parts }) { state._activeFeeds.delete(feedId); state._feedStatus.delete(feedId); parts.ingestion.removeFeedVehicles(feedId); + changed = true; } } // Leaving coverage leaves nothing on the map to date: a row that read @@ -115,11 +118,15 @@ export function createViewport({ state, services, parts }) { if (!state._activeFeeds.has(feedId)) { state._activeFeeds.set(feedId, feed); void parts.ingestion.pollFeed(feed, state._generation); + changed = true; } } parts.ingestion.sweepAgedVehicles(Date.now()); parts.rendering.syncRenderHold(); governorRequestRender('transit-proximity'); + // The row's text follows the camera (coverage prompt, feed list), so it + // repaints now instead of at the next 15 s manager tick. + if (changed) state._dataManager?.refreshLayerStats?.(); } function onCameraChanged() { diff --git a/src/ui/statusText.test.mjs b/src/ui/statusText.test.mjs index 1b6479b45c..6d1648b6d4 100644 --- a/src/ui/statusText.test.mjs +++ b/src/ui/statusText.test.mjs @@ -83,7 +83,7 @@ for (const locale of ['es', 'ru']) { // A layer's coverage note when no feed covers the view: one sentence with a // " · " in it (transit/queries.js, bikeshare/controls.js). const COVERAGE_NOTES = [ - 'Fly below 3,000 km to a covered region', + 'Fly below 2,850 km to a covered region', 'No feed here yet · 16 regions available', 'Fly below 48 km to a covered city', 'No bike share here yet · 61 systems available', diff --git a/src/voice/analystEmptyNotes.test.mjs b/src/voice/analystEmptyNotes.test.mjs index b0de16ebd5..cfacee4bf5 100644 --- a/src/voice/analystEmptyNotes.test.mjs +++ b/src/voice/analystEmptyNotes.test.mjs @@ -70,7 +70,7 @@ const cases = [ // Transit's coverage text when nothing is in view (transit/queries.js). const transitCoverage = [ - 'transit: Fly below 3,000 km to a covered region', + 'transit: Fly below 2,850 km to a covered region', 'transit: No feed here yet · 12 regions available', ]; diff --git a/src/voice/resultDisplay.js b/src/voice/resultDisplay.js index cd909d2f76..72a929b942 100644 --- a/src/voice/resultDisplay.js +++ b/src/voice/resultDisplay.js @@ -423,7 +423,7 @@ function shownNote(text) { const shown = match ? show(match) : null; if (shown) return shown; } - // A layer's empty note can be its coverage note ("Fly below 3,000 km to a + // A layer's empty note can be its coverage note ("Fly below 2,850 km to a // covered region") or its status line, English pieces joined by " · " // ("feeds 1090, 978 stale · 0 heard", "TTC 0 (95s old)"). return translateStatusMessage(text); From 433b336c2d57087986d8114735861f53d790d7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Itallo=20Brand=C3=A3o?= <45429643+IMBrandao@users.noreply.github.com> Date: Fri, 6 Nov 2026 02:50:42 -0300 Subject: [PATCH 26/61] feat(transit): add Szczecin buses and trams (ZDiTM, CC0) Keyless GTFS-Realtime feed published by ZDiTM Szczecin under CC0 1.0. Speeds are m/s (checked against vehicle movement), the file refreshes about every 20 s, and the feed carries no route ids, so vehicles take the default bus mode. Co-Authored-By: Claude Sonnet 5.5 --- DATA_SOURCES.md | 3 ++- README.md | 2 +- changelog.d/szczecin-transit.md | 3 +++ docs/CURRENT-STATE.md | 4 ++-- src/data/transitFeeds.js | 23 +++++++++++++++++++++++ src/data/transitFeeds.test.mjs | 26 ++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 changelog.d/szczecin-transit.md diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index ed0895b0ac..6532837d82 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -99,6 +99,7 @@ How to read this: | **YRT/Viva** (rtu.york.ca) | Transit layer live vehicles, York Region ON | York Region Transit realtime data, first-party York Region infrastructure under the YRT Open Data Licence v2.0, which permits commercial use and makes attribution optional. Viva route ids are named by colour from York Region’s published GTFS. | "Contains public transit Information made available under YRT’s Open Data Licence" — the licence’s own wording, given though not required | | **Burlington Transit** (opendata.burlington.ca) | Transit layer live vehicles, Burlington ON | Burlington Transit realtime data under the City of Burlington Open Data Terms of Use, which permit any lawful purpose. The terms are revocable and must travel with the data, so the credit links them. Route ids are internal keys and are joined to the City’s published GTFS. | Credit to the City of Burlington plus a link to its Open Data Terms of Use, which the licence requires | | **SMTR Rio de Janeiro** (dados.mobilidade.rio) | Transit layer live vehicles, Rio de Janeiro: municipal buses (SPPO) and the Mobi-Rio BRT, as two feeds | CC BY 4.0, stated on both data.rio catalog pages. Keyless GTFS-Realtime published by the Secretaria Municipal de Transportes, labelled beta, with a gateway limit of 5 requests a second and 60 a minute. Line names come from SMTR’s GTFS `routes.txt` (dados.mobilidade.rio/gtfs/schedule), under the same licence. | Attribution to SMTR / Prefeitura da Cidade do Rio de Janeiro under CC BY 4.0 | +| **ZDiTM Szczecin** (zditm.szczecin.pl) | Transit layer live vehicles, Szczecin, Poland: buses and trams as one feed | CC0 1.0, stated on the ZDiTM developer page: “The data are provided free of charge under the CC0 1.0 licence, for use in any context, with no prior notification required.” Keyless GTFS-Realtime; the page says one update a minute, measured at about every 20 seconds. The feed carries no route id, so every vehicle takes the default bus mode. | None required (CC0); credited to ZDiTM Szczecin as a courtesy | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | | **OpenSeaMap** (`tiles.openseamap.org`) | Sea Marks layer: raster overlay of buoys, lighthouses and ports (#10) | Chart tiles CC BY-SA 2.0; data ODbL 1.0 via OpenStreetMap | "Sea marks © OpenSeaMap contributors (CC BY-SA 2.0) · Data © OpenStreetMap contributors (ODbL)" | @@ -186,7 +187,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **Houston TranStar cameras.** Keyless. The camera list is the public `traffic.houstontranstar.org/data/layers/cctvSnapshots_json.js` catalog (~1,000 cameras across Greater Houston); frames are stills at `www.houstontranstar.org/snapshots/cctv/.jpg`, synthesized from a validated numeric id rather than taken from the payload, and only that host is registered. Cameras whose catalog id is `0` (a different, non-snapshot class) and cameras outside Greater Houston are dropped. TranStar's `dir` field is the side of the freeway the camera sits on, not the way it faces: TranStar's own map shows it as "Traffic closest to the camera is traveling …" (South → eastbound, North → westbound, West → southbound, East → northbound). That travel direction (90°, 270°, 180°, 0°) seeds the heading as a low-confidence prior with the low-confidence pose; `None` or an unknown value uses the shared id-hash fallback at low confidence. Headings are corrected with the in-app calibration gizmo. Off by default. TranStar's [Content Usage terms](https://traffic.houstontranstar.org/disclaimer.aspx) prohibit copying or distributing the site's information, and external framing or linking to specific images, without TxDOT's prior written permission; its FAQ grants permission-free use only for the RSS feeds. This project does not hold that permission for downstream installations, so the pack loads only when an operator who holds TxDOT's written permission sets `CCTV_HOUSTON_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to TranStar. Once enabled, it loads the 250 cameras nearest downtown, Uptown, the Medical Center, IAH and Galveston; `CCTV_HOUSTON_MAX_SOURCES` (8–400) changes the cap. Snapshots update about every 3 minutes, which is also the ambient still cadence. Frames are fetched from TranStar and relayed to the browser on demand, buffered only transiently per request, sent with `Cache-Control: no-store`, and not archived. - **Autostrada del Brennero (A22) webcams.** Keyless. The camera list is one request to the Open Data Hub tourism API (`tourism.api.opendatahub.com/v1/WebcamInfo?source=a22`), run by NOI Techpark in South Tyrol, which republishes Autobrennero's own list of 13 motorway webcams with coordinates and kilometre markers. Frames are the operator's stills on `www.autobrennero.it/WebCamImg/km.jpg`, refreshed about once a minute, and only the exact image for each camera's kilometre is registered. The feed names no bearing, so headings use the id-hash fallback at low confidence. The road climbs from about 20 m in the Po valley to about 1,370 m at the Brenner Pass, so each camera's ground elevation comes from a per-kilometre table sampled from the Copernicus GLO-90 DEM (via Open-Meteo's elevation API); a camera not in the table uses a 200 m prior. The Open Data Hub tags every record CC0 (`ClosedData: false`, Autobrennero as licence holder), but that tag is the aggregator's metadata and Autobrennero publishes no terms of its own for the images, so they are credited to the operator as a courtesy and are not redistributed. Frames are fetched at request time and never stored. Disable with `CCTV_A22_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All eighteen registered feeds, covering seventeen regions, are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington, YRT and Rio’s SMTR publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All nineteen registered feeds, covering eighteen regions, are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington, YRT and Rio’s SMTR publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for. - **Radio country coverage (optional).** Set `RADIO_PRIORITY_COUNTRIES=IN,PL` in the local `.env` and restart to include stations beyond the global click charts. The operator may choose up to eight unique ISO alpha-2 country codes; no key is needed. Each country adds one bounded query (at most 200 rows) and reserves up to 40 unique, usable stations inside the existing 750-station catalog. Country seeds precede specialist-tag seeds and global popularity fill; unused slots return to the shared pool. This is a coverage preference, not an exhaustive national directory or a guarantee of stations in every city. Countries with no eligible HTTPS MP3/AAC geolocated stations remain empty. An unset list preserves global selection. Country requests share the directory cache and three-worker pool; failed country queries are reported in coverage without blocking a healthy global refresh. Failed/degraded refreshes back off for one minute, with at most three mirrors per query. - **Radio Browser.** In every installation, including when `RADIO_PRIORITY_COUNTRIES` is unset, each request tries at most three mirror candidates (later fallback candidates are skipped), and failed or partial catalog refreshes back off for 60 seconds. A cold-start failure therefore continues returning 503 during that delay even if upstream recovers. `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; broad/specialist responses whose rows all fail the product's health policy do not count as successful queries. Optional priority-country outcomes are advisory: valid, in-limit responses with no eligible stations succeed as empty results, while failed or malformed country queries report unsuccessful coverage without degrading the global catalog. A usable partial cold catalog is explicitly `DEGRADED`, and non-array or empty broad/specialist payloads are rejected atomically. Individual structurally malformed rows are skipped rather than failing the whole query; the response carries their bounded `rejectedStationCount` (at most 10,000), which the client adds to its own rejected rows and reports as degraded coverage without discarding the accepted generation. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. diff --git a/README.md b/README.md index 6212f3991c..6c8de0d79a 100644 --- a/README.md +++ b/README.md @@ -444,7 +444,7 @@ Twenty-one layers and map sources. **Nineteen have a keyless path.** Some offer | 📷 **Mapped ALPR Cameras** | License-plate-reader camera locations tagged by OpenStreetMap contributors, loaded one city-sized view at a time, with **SHOW NEAREST**. Locations and tags only: no plate data, no video | OpenStreetMap (incl. DeFlock mapping) | 🟢 | | 📷 **Street Level** | Street-level photos behind one panel, one chip per provider: coverage on the streets, image cones, an embedded viewer with full-screen **EXPAND**. Mapillary, Google Street View, KartaView and Panoramax | Mapillary · Google · KartaView · Panoramax | 🟢 KartaView, Panoramax · 🟡 Mapillary token · 🔴 Google Maps key | | 📻 **Radio** | Geolocated world radio with an **analog tuner** — drag the needle across up to 750 stations and the globe flies to each broadcaster | Radio Browser / broadcasters | 🟢 | -| 🚌 **Transit** | Live buses, trams, metros, trains and ferries with delayed playback between reports, selected-vehicle trails, and mode-coloured DETECT labels — Boston, Austin, Minneapolis, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro (buses and BRT), and nine in Ontario: Toronto (surface vehicles; the subway publishes no positions), Mississauga, Hamilton, Durham Region, York Region, Guelph, Burlington, Barrie and Kingston | Operator GTFS-Realtime feeds | 🟢 | +| 🚌 **Transit** | Live buses, trams, metros, trains and ferries with delayed playback between reports, selected-vehicle trails, and mode-coloured DETECT labels — Boston, Austin, Minneapolis, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro (buses and BRT), Szczecin, and nine in Ontario: Toronto (surface vehicles; the subway publishes no positions), Mississauga, Hamilton, Durham Region, York Region, Guelph, Burlington, Barrie and Kingston | Operator GTFS-Realtime feeds | 🟢 | | 🚲 **Bikeshare** | Live station availability | GBFS | 🟢 | | 🧭 **Directions** | Click A and B on the globe for a street-following drive, walk or cycle route draped on the terrain with turn-by-turn steps — then FLY the camera along it. No key, no geocoder, no mic | OSRM on FOSSGIS servers (OpenStreetMap) | 🟢 | | ⌖ **OSM Places** | Voice place search ("hospitals in Kathmandu") from OpenStreetMap, drawn as numbered points that follow-up questions can filter. Needs your own Overpass server (`OVERPASS_UPSTREAMS`); off otherwise | diff --git a/changelog.d/szczecin-transit.md b/changelog.d/szczecin-transit.md new file mode 100644 index 0000000000..5b2411211f --- /dev/null +++ b/changelog.d/szczecin-transit.md @@ -0,0 +1,3 @@ +- Add Szczecin, Poland to the Transit layer: buses and trams from ZDiTM's + keyless GTFS-Realtime feed, published under CC0 1.0. The feed carries no + route ids, so vehicles show as buses (IMBrandao). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index abfa3fc043..85bfd2e928 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4644,9 +4644,9 @@ Transit is off by default, and share links use token `j`. The movement panel ord places Transit directly after Street Traffic and before Bike Share. Cameras and utilities retain their own groups. The layer polls registered feeds near the camera every 15 seconds, below a 3,000 km altitude -gate. Seventeen keyless regions are available: Boston, Austin, Minneapolis–St Paul, +gate. Eighteen keyless regions are available: Boston, Austin, Minneapolis–St Paul, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro -(municipal buses and the Mobi-Rio BRT, two feeds), and nine in +(municipal buses and the Mobi-Rio BRT, two feeds), Szczecin, and nine in Ontario — Toronto (TTC surface vehicles; the subway publishes no positions), MiWay, Hamilton HSR, Durham Region, YRT/Viva, Guelph, Burlington, Barrie and Kingston. Mode silhouettes diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 48ca450a19..76b2764a66 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -788,6 +788,29 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ defaultMode: 'bus', routeLabel: rioRouteLabel, }), + Object.freeze({ + id: 'zditm-szczecin', + name: 'Szczecin buses and trams', + operator: + 'Zarząd Dróg i Transportu Miejskiego w Szczecinie (ZDiTM), Szczecin', + region: 'Szczecin, Poland', + // Every vehicle in a 2026-11-05 snapshot sat between 53.34–53.55 N and + // 14.44–14.77 E, inside 20 km of this point. + center: Object.freeze({ lat: 53.44, lon: 14.56 }), + loadRadiusKm: 25, + url: 'https://www.zditm.szczecin.pl/storage/gtfs/gtfs-rt-vehicles.pb', + license: 'CC0 1.0', + licenseUrl: 'https://www.zditm.szczecin.pl/en/zditm/for-developers', + attribution: + 'Zarząd Dróg i Transportu Miejskiego w Szczecinie (ZDiTM Szczecin)', + defaultEnabled: true, + terms: Object.freeze({ + quote: + 'The data are provided free of charge under the CC0 1.0 licence, for use in any context, with no prior notification required.', + note: 'CC0 needs no credit; it is given anyway as a courtesy. ZDiTM gives no guarantee of accuracy or completeness. The developer page says the feed updates every minute; measured on 2026-11-05 the file changed about every 20 seconds, with vehicle timestamps up to 50 seconds old. Speeds are m/s: checked against vehicle movement between two snapshots. The feed carries no route id at all, so every vehicle takes the feed default mode even though the city also runs trams.', + }), + defaultMode: 'bus', + }), ]); /** diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index d6dc93eb6b..5fab7c27d0 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -552,3 +552,29 @@ test('Rio feeds are CC BY 4.0 and live', () => { 'Rio has a DATA_SOURCES row', ); }); + +test('Szczecin is CC0, live, covers the city and not Berlin', () => { + const feed = getTransitFeed('zditm-szczecin'); + assert.equal(feed.defaultEnabled, true); + assert.equal(feed.license, 'CC0 1.0'); + assert.equal( + feed.licenseUrl, + 'https://www.zditm.szczecin.pl/en/zditm/for-developers', + ); + assert.match(feed.terms.quote, /CC0 1\.0 licence/); + assert.match(feed.attribution, /ZDiTM/); + assert.equal(feed.routeLabel, undefined, 'the feed has no route ids'); + assert.equal(transitModeFor(feed, null), 'bus'); + const ids = (lat, lon) => transitFeedsInRange(lat, lon).map((f) => f.id); + assert.ok(ids(53.4285, 14.5528).includes('zditm-szczecin'), 'city centre'); + assert.ok(ids(53.5, 14.7).includes('zditm-szczecin'), 'north-east edge'); + assert.ok(!ids(52.52, 13.405).includes('zditm-szczecin'), 'Berlin'); + const sources = readFileSync( + new URL('../../DATA_SOURCES.md', import.meta.url), + 'utf8', + ); + assert.ok( + sources.split('\n').some((l) => l.startsWith('| **ZDiTM Szczecin')), + 'Szczecin has a DATA_SOURCES row', + ); +}); From 697b6b59e66291c6c690b6a77fd2030396233e03 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 6 Nov 2026 14:45:39 +0400 Subject: [PATCH 27/61] Repaint coverage rows after loads, nudges and cleared failures --- src/data/lifecycle.js | 19 +- src/data/manager.js | 4 +- src/data/manager.test.mjs | 25 ++ src/layers/bikeshare/controls.js | 15 +- src/layers/bikeshare/rowRepaint.test.mjs | 295 ++++++++++++++++++ src/layers/bikeshare/state.js | 2 +- src/layers/bikeshare/viewport.js | 13 +- .../transit/refreshErrorRepaint.test.mjs | 98 ++++++ src/layers/transit/state.js | 2 +- src/layers/transit/viewport.js | 2 +- 10 files changed, 464 insertions(+), 11 deletions(-) create mode 100644 src/layers/bikeshare/rowRepaint.test.mjs create mode 100644 src/layers/transit/refreshErrorRepaint.test.mjs diff --git a/src/data/lifecycle.js b/src/data/lifecycle.js index 6c2290c720..c019264515 100644 --- a/src/data/lifecycle.js +++ b/src/data/lifecycle.js @@ -2385,11 +2385,28 @@ export class LayerLifecycle { /** * Ask presentation to repaint layer rows now, for data that lands outside * the manager tick (Transit's proximity polls, Directions' route steps). + * @param {string} [layerId] - The layer whose row changed. */ - refreshLayerStats() { + refreshLayerStats(layerId) { + this._dropRecoveredRefreshError(layerId); this._publishActivity({ type: 'status' }); } + /** + * A tick's failure belongs to the feed it polled. Once the layer's own stats + * stop reporting one (the camera left that feed), the row stops showing it + * instead of waiting for the next tick. + */ + _dropRecoveredRefreshError(layerId) { + const entry = layerId ? this.layers.get(layerId) : null; + if (!entry?.managerRefreshError || entry.refreshing) return; + const failure = refreshFailureFromStats( + this._moduleStats(entry), + entry.module.name || layerId, + ); + if (!failure) entry.managerRefreshError = null; + } + _publishActivity(change) { for (const callback of this._activityListeners) { try { diff --git a/src/data/manager.js b/src/data/manager.js index cf7b31fae3..688fb94d23 100644 --- a/src/data/manager.js +++ b/src/data/manager.js @@ -20,8 +20,10 @@ export class DataLayerManager extends LayerLifecycle { * manager tick (camera-driven loads such as Transit's proximity polls), so a * row shows its count when the data lands instead of at the next interval. * One DOM pass; skipped while the document is hidden. + * @param {string} [layerId] - The layer whose row changed. */ - refreshLayerStats() { + refreshLayerStats(layerId) { + this._dropRecoveredRefreshError(layerId); this._refreshTogglePanel(); } diff --git a/src/data/manager.test.mjs b/src/data/manager.test.mjs index 70f705ec62..de35029791 100644 --- a/src/data/manager.test.mjs +++ b/src/data/manager.test.mjs @@ -2677,6 +2677,31 @@ test('refreshLayerStats reaches presentation through the bare lifecycle', async assert.deepEqual(changes, ['status']); }); +test('refreshLayerStats(layerId) drops a tick failure the layer no longer reports', async () => { + const { LayerLifecycle } = await import('./lifecycle.js'); + const lifecycle = new LayerLifecycle({}); + let stats = { count: 0, error: 'Feed unavailable' }; + lifecycle.register({ + id: 'feed', + name: 'Feed', + getStats: () => stats, + async update() {}, + }); + const entry = lifecycle.layers.get('feed'); + entry.enabled = true; + entry.initialized = true; + entry.managerRefreshError = 'Feed unavailable'; + + lifecycle.refreshLayerStats('feed'); + assert.equal(entry.managerRefreshError, 'Feed unavailable'); + + stats = { count: 0 }; + lifecycle.refreshLayerStats(); + assert.equal(entry.managerRefreshError, 'Feed unavailable'); + lifecycle.refreshLayerStats('feed'); + assert.equal(entry.managerRefreshError, null); +}); + test('periodic polls pause hidden, catch up once when due, and dispose visibility listeners', async (t) => { const listeners = new Set(); const doc = { diff --git a/src/layers/bikeshare/controls.js b/src/layers/bikeshare/controls.js index 78edd907b0..03bb544abf 100644 --- a/src/layers/bikeshare/controls.js +++ b/src/layers/bikeshare/controls.js @@ -70,17 +70,26 @@ export function createControls({ state: layerState, services, parts, source }) { * @returns {{ count: number, lastUpdate: number|null, loading: boolean, loadingLabel?: string, error?: string, degraded?: boolean, stale?: boolean, status?: string, statusMessage?: string }} */ getStats() { + // A city in range without points is loading even before its fetch + // starts: the row repaints on entry, ahead of beginLoading(). + const loading = + layerState._loading || + [...layerState._activeCityIds].some( + (cityId) => + !layerState._cityRuntime.has(cityId) && + !layerState._failedCityIds.has(cityId), + ); const stats = { count: layerState._count, lastUpdate: layerState._lastUpdate, - loading: layerState._loading, + 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 && + !loading && layerState._activeCityIds.size === 0 && layerState._failedCityIds.size === 0 ) { @@ -92,7 +101,7 @@ export function createControls({ state: layerState, services, parts, source }) { : `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) { + if (loading) { stats.loadingLabel = layerState._activeCityIds.size > 0 ? t('syncing {count} city feeds...', { diff --git a/src/layers/bikeshare/rowRepaint.test.mjs b/src/layers/bikeshare/rowRepaint.test.mjs new file mode 100644 index 0000000000..144ff55026 --- /dev/null +++ b/src/layers/bikeshare/rowRepaint.test.mjs @@ -0,0 +1,295 @@ +// Bike Share row repaints: entering a city, leaving it or nudging the camera +// mid-load, and leaving a failed city. +// Bike Share: after the camera settles, the last row the panel painted must +// match what the layer reports now. Each case drives the real viewport, +// ingestion, rendering and controls; the manager is a spy that records the +// row text (LayerPanel._buildMetaText) at every refreshLayerStats() call. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import * as Cesium from 'cesium'; +import { CITY_BY_ID } from './registry.js'; +import { createState } from './state.js'; +import { createControls } from './controls.js'; +import { createIngestion } from './ingestion.js'; +import { createModel } from './model.js'; +import { createViewport } from './viewport.js'; +import { createRendering } from './rendering.js'; +import { createLifecycle } from './lifecycle.js'; +import { LayerPanel, layerFeedState } from '../../ui/layerPanel.js'; + +const BOSTON_ID = 'boston-bluebikes'; +const TORONTO_ID = 'toronto-bike-share'; +const BUFFALO_ID = 'buffalo-reddy'; +const LONDON = { lat: 51.5072, lon: -0.1276 }; +const BOSTON = { lat: 42.3601, lon: -71.0589 }; +const BOSTON_NUDGED = { lat: 42.37, lon: -71.05 }; +const BETWEEN = { lat: 43.25, lon: -79.1 }; +const TORONTO_ONLY = { lat: 43.7, lon: -79.6 }; +const LOW_M = 10_000; + +globalThis.document ??= { + addEventListener() {}, + removeEventListener() {}, +}; + +function deferred() { + let resolve; + const promise = new Promise((res) => { + resolve = res; + }); + return { promise, resolve }; +} + +function makeSource() { + const cityOf = (url) => { + for (const [id, city] of CITY_BY_ID) { + if (url === city.stationInformationUrl) return { id, kind: 'info' }; + if (url === city.stationStatusUrl) return { id, kind: 'status' }; + } + throw new Error(`unexpected GBFS url ${url}`); + }; + const source = { + dead: new Set(), + /** `${cityId}:${kind}` → deferred that gates the answer. */ + gates: new Map(), + async getStations(url, { signal } = {}) { + const { id, kind } = cityOf(url); + const gate = source.gates.get(`${id}:${kind}`); + if (gate) { + await new Promise((resolve, reject) => { + gate.promise.then(resolve); + signal?.addEventListener('abort', () => + reject(Object.assign(new Error('aborted'), { name: 'AbortError' })), + ); + }); + } else { + await new Promise((resolve) => setTimeout(resolve, 1)); + } + signal?.throwIfAborted(); + if (source.dead.has(id)) throw new Error('GBFS HTTP 503'); + const city = CITY_BY_ID.get(id); + if (kind === 'info') { + return { + data: { + stations: [ + { + station_id: `${id}-1`, + name: `${id} dock`, + lat: city.centerLat, + lon: city.centerLon, + capacity: 10, + }, + ], + }, + }; + } + return { + data: { + stations: [ + { + station_id: `${id}-1`, + num_bikes_available: 3, + num_docks_available: 7, + is_installed: true, + is_renting: true, + is_returning: true, + }, + ], + }, + }; + }, + }; + return source; +} + +/** The row as the panel draws it: state chip, count, meta text. */ +const rowText = (raw) => { + const stats = { + count: 0, + lastUpdate: null, + ...raw, + loading: raw.loading === true, + }; + const meta = LayerPanel.prototype._buildMetaText({ + id: 'bikeshare', + source: 'GBFS', + enabled: true, + lifecycleState: 'enabled', + stats, + }); + return `${layerFeedState(stats)} | ${stats.count || '—'} | ${meta}`; +}; + +function makeLiveLayer() { + const source = makeSource(); + const services = { + render: { governorRequestRender() {} }, + overlays: { + setOverlayEntries() {}, + setOverlaySourceVisible() {}, + clearOverlaySource() {}, + }, + sprites: { registerSpriteCollection() {}, restoreSpriteOrder() {} }, + picking: { registerPickOwner() {}, unregisterPickOwner() {} }, + }; + 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 = { + _installClickHandler() {}, + _clearSelection() {}, + _onKeyDown() {}, + }; + parts.queries = { collectDetectableStations: () => [] }; + parts.lifecycle = createLifecycle(context); + const { methods: controls } = createControls(context); + + const camera = { ...LONDON, height: LOW_M }; + const viewer = { + camera: { + get positionCartographic() { + return Cesium.Cartographic.fromDegrees( + camera.lon, + camera.lat, + camera.height, + ); + }, + computeViewRectangle: () => undefined, + changed: { addEventListener() {}, removeEventListener() {} }, + }, + scene: { globe: {}, primitives: { add() {}, remove() {} } }, + }; + parts.lifecycle.methods.init(viewer); + + const painted = []; + controls.attachDataManager({ + refreshLayerStats() { + painted.push(rowText(controls.getStats())); + }, + }); + + return { + state, + source, + painted, + lastPainted: () => painted.at(-1), + live: () => rowText(controls.getStats()), + moveTo(place, height = LOW_M) { + Object.assign(camera, place, { height }); + return parts.viewport.runProximityCheck(); + }, + async enable() { + parts.lifecycle.methods.enable(viewer); + await settle(); + }, + }; +} + +async function settle() { + for (let i = 0; i < 5; i += 1) + await new Promise((resolve) => setTimeout(resolve, 2)); +} + +test('entering a city paints the loading row, not "never"', async () => { + const layer = makeLiveLayer(); + const info = deferred(); + layer.source.gates.set(`${BOSTON_ID}:info`, info); + await layer.enable(); + const before = layer.painted.length; + const entering = layer.moveTo(BOSTON); + assert.ok(layer.painted.length > before, 'entering repainted'); + const atEntry = layer.lastPainted(); + const liveAfter = layer.live(); + info.resolve(); + await entering; + await settle(); + assert.match(liveAfter, /syncing 1 city feeds/); + assert.match(atEntry, /^loading \|/, 'the entry repaint reads loading'); + assert.doesNotMatch(atEntry, /never/); +}); +test('re-entering a city with cached station info paints loading', async () => { + const layer = makeLiveLayer(); + await layer.enable(); + await layer.moveTo(BOSTON); + await settle(); + await layer.moveTo(LONDON); + await settle(); + const status = deferred(); + layer.source.gates.set(`${BOSTON_ID}:status`, status); + const entering = layer.moveTo(BOSTON); + const atEntry = layer.lastPainted(); + await Promise.resolve(); + await Promise.resolve(); + const liveAfter = layer.live(); + status.resolve(); + await entering; + await settle(); + assert.match(liveAfter, /syncing 1 city feeds/); + assert.match(atEntry, /^loading \|/, 'the entry repaint reads loading'); + assert.doesNotMatch(atEntry, /never/); +}); + +test('leaving a city mid-load does not leave the row on LOADING', async () => { + const layer = makeLiveLayer(); + layer.source.gates.set(`${BOSTON_ID}:info`, deferred()); + await layer.enable(); + const entering = layer.moveTo(BOSTON); + await settle(); + assert.equal(layer.state._loading, true); + + await layer.moveTo(LONDON); + await entering; + await settle(); + assert.equal(layer.state._loading, false); + assert.match(layer.live(), /No bike share here yet/); + assert.equal(layer.lastPainted(), layer.live()); +}); + +test('a camera nudge during the first load still repaints the drawn stations', async () => { + const layer = makeLiveLayer(); + const status = deferred(); + layer.source.gates.set(`${BOSTON_ID}:status`, status); + await layer.enable(); + const entering = layer.moveTo(BOSTON); + await settle(); + assert.ok(layer.state._cityRuntime.has(BOSTON_ID), 'points are drawn'); + + await layer.moveTo(BOSTON_NUDGED); + status.resolve(); + await entering; + await settle(); + assert.equal(layer.state._count, 1, 'one station on the map'); + assert.equal(layer.lastPainted(), layer.live()); +}); + +test('leaving a city whose load failed repaints the error away', async () => { + const layer = makeLiveLayer(); + layer.source.dead.add(BOSTON_ID); + await layer.enable(); + await layer.moveTo(BOSTON); + await settle(); + assert.match(layer.lastPainted(), /GBFS fetch error/i); + + await layer.moveTo(LONDON); + await settle(); + assert.match(layer.live(), /No bike share here yet/); + assert.equal(layer.lastPainted(), layer.live()); +}); + +test('leaving the failed city of two repaints DEGRADED away', async () => { + const layer = makeLiveLayer(); + layer.source.dead.add(BUFFALO_ID); + await layer.enable(); + await layer.moveTo(BETWEEN); + await settle(); + assert.match(layer.lastPainted(), /^degraded/); + + await layer.moveTo(TORONTO_ONLY); + await settle(); + assert.doesNotMatch(layer.live(), /^degraded/); + assert.equal(layer.lastPainted(), layer.live()); +}); diff --git a/src/layers/bikeshare/state.js b/src/layers/bikeshare/state.js index 518c2397aa..199c9b5ca0 100644 --- a/src/layers/bikeshare/state.js +++ b/src/layers/bikeshare/state.js @@ -19,7 +19,7 @@ export function createState({ services }) { layerState._viewer = null; - /** @type {{ refreshLayerStats?: () => void }|null} Manager that repaints the layer's row. */ + /** @type {{ refreshLayerStats?: (layerId?: string) => void }|null} Manager that repaints the layer's row. */ layerState._dataManager = null; diff --git a/src/layers/bikeshare/viewport.js b/src/layers/bikeshare/viewport.js index dbc328f61d..008c013339 100644 --- a/src/layers/bikeshare/viewport.js +++ b/src/layers/bikeshare/viewport.js @@ -121,7 +121,7 @@ export function createViewport({ state: layerState, services, parts, source }) { * prompt, station count), and the manager tick is 60 s. */ function refreshRow() { - layerState._dataManager?.refreshLayerStats?.(); + layerState._dataManager?.refreshLayerStats?.('bikeshare'); } /** Deactivate all currently active cities and clear the active set. */ @@ -232,12 +232,17 @@ export function createViewport({ state: layerState, services, parts, source }) { } } // A failure never outlives its city's range. + let failureCleared = false; for (const cityId of layerState._failedCityIds) { - if (!nextActive.has(cityId)) layerState._failedCityIds.delete(cityId); + if (!nextActive.has(cityId)) { + layerState._failedCityIds.delete(cityId); + failureCleared = true; + } } const changed = !wasGateEnabled || + failureCleared || nextActive.size !== layerState._activeCityIds.size || [...nextActive].some((cityId) => !layerState._activeCityIds.has(cityId)); layerState._activeCityIds = nextActive; @@ -259,7 +264,9 @@ export function createViewport({ state: layerState, services, parts, source }) { await Promise.all( toActivate.map((cityId) => activateCity(cityId, generation)), ); - if (generation === layerState._proximityGeneration) refreshRow(); + // Superseded loads repaint too: a newer check may have painted the row + // while this one was still loading, or found nothing to load itself. + if (layerState._enabled) refreshRow(); } /** Schedule a debounced proximity check after camera movement. */ diff --git a/src/layers/transit/refreshErrorRepaint.test.mjs b/src/layers/transit/refreshErrorRepaint.test.mjs new file mode 100644 index 0000000000..d1a5c16b8f --- /dev/null +++ b/src/layers/transit/refreshErrorRepaint.test.mjs @@ -0,0 +1,98 @@ +// Transit: a manager tick that failed over Boston must not keep its error on +// the row the coverage repaint draws after the camera leaves for London. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { createState } from './state.js'; +import { createViewport } from './viewport.js'; +import { createQueries } from './queries.js'; +import { LayerLifecycle } from '../../data/lifecycle.js'; +import { LayerPanel, layerFeedState } from '../../ui/layerPanel.js'; + +const rad = Math.PI / 180; +const LONDON = { lat: 51.5072, lon: -0.1276 }; +const BOSTON = { lat: 42.3601, lon: -71.0589 }; + +function viewer(at, height) { + return { + camera: { + positionCartographic: { + height, + latitude: at.lat * rad, + longitude: at.lon * rad, + }, + computeViewRectangle: () => undefined, + }, + scene: { globe: {} }, + }; +} + +test('leaving a feed whose tick failed repaints its error away', async () => { + const services = { + overlays: { + setOverlayEntries() {}, + setOverlaySourceVisible() {}, + clearOverlaySource() {}, + }, + render: { governorRequestRender() {} }, + }; + const state = createState({ services }); + const feedStatus = (feedId) => { + if (!state._feedStatus.has(feedId)) + state._feedStatus.set(feedId, { count: 0, error: null, loading: false }); + return state._feedStatus.get(feedId); + }; + const parts = { + ingestion: { + feedStatus, + // As pollFeed's catch does when the proxy answers 503. + pollFeed(feed) { + Object.assign(feedStatus(feed.id), { + error: `${feed.name} feed unavailable`, + loading: false, + }); + return Promise.resolve(); + }, + removeFeedVehicles() {}, + sweepAgedVehicles() {}, + }, + rendering: { requestVisibility() {}, syncRenderHold() {} }, + }; + parts.viewport = createViewport({ state, services, parts }); + const queries = createQueries({ state, parts }).methods; + state._enabled = true; + + const lifecycle = new LayerLifecycle(null); + lifecycle.register({ + id: 'transit', + name: 'Transit', + source: 'GTFS-RT', + getStats: () => queries.getStats(), + async update() {}, + }); + const entry = lifecycle.layers.get('transit'); + entry.enabled = true; + entry.lifecycleState = 'enabled'; + entry.initialized = true; + + const row = () => { + const layer = lifecycle.getAll()[0]; + return `${layerFeedState(layer.stats)} | ${LayerPanel.prototype._buildMetaText(layer)}`; + }; + const painted = []; + state._dataManager = { + refreshLayerStats(layerId) { + lifecycle.refreshLayerStats(layerId); + painted.push(row()); + }, + }; + + state._viewer = viewer(BOSTON, 4_000); + parts.viewport.runProximityCheck(); + await lifecycle.refreshLayer('transit'); + assert.match(row(), /feed unavailable/, 'the tick recorded the failure'); + + state._viewer = viewer(LONDON, 4_000); + parts.viewport.runProximityCheck(); + assert.equal(queries.getStats().status, 'zoom-in'); + assert.doesNotMatch(painted.at(-1), /feed unavailable/); +}); diff --git a/src/layers/transit/state.js b/src/layers/transit/state.js index 75b13d84b7..569298e6e9 100644 --- a/src/layers/transit/state.js +++ b/src/layers/transit/state.js @@ -112,7 +112,7 @@ export function createState({ services }) { state._cockpitVision = false; /** @type {Array<[string, EventListener]>} window listeners to remove on destroy. */ state._styleListeners = []; - /** @type {{ refreshLayerStats?: () => void }|null} */ + /** @type {{ refreshLayerStats?: (layerId?: string) => void }|null} */ state._dataManager = null; /** @type {number|null} */ state._lastUpdate = null; diff --git a/src/layers/transit/viewport.js b/src/layers/transit/viewport.js index 0e3b317d47..a62d49009c 100644 --- a/src/layers/transit/viewport.js +++ b/src/layers/transit/viewport.js @@ -126,7 +126,7 @@ export function createViewport({ state, services, parts }) { governorRequestRender('transit-proximity'); // The row's text follows the camera (coverage prompt, feed list), so it // repaints now instead of at the next 15 s manager tick. - if (changed) state._dataManager?.refreshLayerStats?.(); + if (changed) state._dataManager?.refreshLayerStats?.('transit'); } function onCameraChanged() { From 5c4918affb792bbfe4ac863031b3dcd55734a30c Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 6 Nov 2026 20:20:11 +0400 Subject: [PATCH 28/61] Tighten coverage prompt comments and docs --- .../1576-transit-bikeshare-coverage-prompt.md | 2 +- docs/CURRENT-STATE.md | 22 +++++++++---------- src/data/lifecycle.js | 5 ++--- src/layers/bikeshare/controls.js | 13 +++++------ src/layers/bikeshare/coverageStatus.test.mjs | 7 ++---- src/layers/bikeshare/rowRepaint.test.mjs | 2 -- src/layers/bikeshare/viewport.js | 5 +---- src/layers/promptRepaint.test.mjs | 6 ++--- src/layers/transit/gatePrompt.test.mjs | 6 ++--- src/layers/transit/queries.js | 5 ++--- src/layers/transit/viewport.js | 6 ++--- src/ui/statusText.js | 6 ++--- 12 files changed, 31 insertions(+), 54 deletions(-) diff --git a/changelog.d/1576-transit-bikeshare-coverage-prompt.md b/changelog.d/1576-transit-bikeshare-coverage-prompt.md index c3dcbe82a2..660c1f30b5 100644 --- a/changelog.d/1576-transit-bikeshare-coverage-prompt.md +++ b/changelog.d/1576-transit-bikeshare-coverage-prompt.md @@ -1,6 +1,6 @@ - Say why Transit and Bike Share are empty outside coverage. Over a city with no feed or system (London, Tokyo) their Layers rows read - `No feed here yet · 16 regions available` and + `No feed here yet · 17 regions available` and `No bike share here yet · 61 systems available`, or how low to fly, instead of `never`; leaving coverage clears the last-update time (German, @gekh, #1576). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 69d83d759b..13cce00500 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1975,18 +1975,16 @@ Mapped-installation zoom guidance appears in the layer row without counting as a global loading failure. Guidance statuses do not suppress independent refresh errors. -Transit and Bike Share report the same kind of guidance when no feed or system -covers the view, instead of an undated `never`. Above their altitude gates the -rows read `GTFS-RT · Fly below 2,850 km to a covered region` and -`GBFS · Fly below 48 km to a covered city`; lower down over a city neither -covers (London, Tokyo) they read `GTFS-RT · No feed here yet · N regions -available` and `GBFS · No bike share here yet · N systems available`, N being -the enabled feeds and the catalogued systems. The -chip stays ON. A Bike Share city that is loading or failed keeps its own -loading or error text. Leaving every covered feed or system clears the layer's -last-update time, so the row never dates data it no longer draws. The same -English notes are the voice analyst's empty-result notes; both surfaces show -them translated through `translateStatusMessage` (`src/ui/statusText.js`). +Transit and Bike Share say the same when no feed or system covers the view, +instead of an undated `never`. Above their altitude gates the rows read +`GTFS-RT · Fly below 2,850 km to a covered region` and +`GBFS · Fly below 48 km to a covered city`; lower, over a city neither covers +(London, Tokyo), `GTFS-RT · No feed here yet · N regions available` and +`GBFS · No bike share here yet · N systems available` (covered regions, +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`). ## Places and CCTV request bounds diff --git a/src/data/lifecycle.js b/src/data/lifecycle.js index c019264515..3ea02eca98 100644 --- a/src/data/lifecycle.js +++ b/src/data/lifecycle.js @@ -2393,9 +2393,8 @@ export class LayerLifecycle { } /** - * A tick's failure belongs to the feed it polled. Once the layer's own stats - * stop reporting one (the camera left that feed), the row stops showing it - * instead of waiting for the next tick. + * Drop a tick failure the layer's stats no longer report (the camera left + * that feed) instead of showing it until the next tick. */ _dropRecoveredRefreshError(layerId) { const entry = layerId ? this.layers.get(layerId) : null; diff --git a/src/layers/bikeshare/controls.js b/src/layers/bikeshare/controls.js index 03bb544abf..d90a62b5b5 100644 --- a/src/layers/bikeshare/controls.js +++ b/src/layers/bikeshare/controls.js @@ -15,8 +15,7 @@ export function createControls({ state: layerState, services, parts, source }) { updateInterval: STATUS_POLL_MS, /** - * Keep the manager so camera-driven coverage changes can repaint the row - * before the next status poll. + * Kept so camera moves can repaint the row before the next status poll. * @param {object} dataManager DataLayerManager instance. */ attachDataManager(dataManager) { @@ -84,18 +83,16 @@ export function createControls({ state: layerState, services, parts, source }) { lastUpdate: layerState._lastUpdate, 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. + // No system in range: the camera is too high or no system is near. A + // failed city also leaves range empty and reports its failure below. if ( layerState._enabled && !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). + // English: the analyst's empty note and the row's prompt, both shown + // 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`; diff --git a/src/layers/bikeshare/coverageStatus.test.mjs b/src/layers/bikeshare/coverageStatus.test.mjs index a9f17e73e1..004c75c945 100644 --- a/src/layers/bikeshare/coverageStatus.test.mjs +++ b/src/layers/bikeshare/coverageStatus.test.mjs @@ -1,10 +1,7 @@ // 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. +// With no system in range (London, Tokyo) the layer says why instead of +// "never", and keeps no date for data it no longer draws. // // Run with: npm test import { test } from 'node:test'; diff --git a/src/layers/bikeshare/rowRepaint.test.mjs b/src/layers/bikeshare/rowRepaint.test.mjs index 144ff55026..5f55381689 100644 --- a/src/layers/bikeshare/rowRepaint.test.mjs +++ b/src/layers/bikeshare/rowRepaint.test.mjs @@ -1,5 +1,3 @@ -// Bike Share row repaints: entering a city, leaving it or nudging the camera -// mid-load, and leaving a failed city. // Bike Share: after the camera settles, the last row the panel painted must // match what the layer reports now. Each case drives the real viewport, // ingestion, rendering and controls; the manager is a spy that records the diff --git a/src/layers/bikeshare/viewport.js b/src/layers/bikeshare/viewport.js index 008c013339..d4cc44cb6c 100644 --- a/src/layers/bikeshare/viewport.js +++ b/src/layers/bikeshare/viewport.js @@ -116,10 +116,7 @@ export function createViewport({ state: layerState, services, parts, source }) { parts.rendering.removeCityPoints(cityId); } - /** - * Repaint the layer's row now. Its text follows the camera (coverage - * prompt, station count), and the manager tick is 60 s. - */ + /** Repaint the row now: it follows the camera, the manager tick is 60 s. */ function refreshRow() { layerState._dataManager?.refreshLayerStats?.('bikeshare'); } diff --git a/src/layers/promptRepaint.test.mjs b/src/layers/promptRepaint.test.mjs index 563aaeac77..38193ca72b 100644 --- a/src/layers/promptRepaint.test.mjs +++ b/src/layers/promptRepaint.test.mjs @@ -1,7 +1,5 @@ -// When the camera changes which coverage prompt a Transit or -// Bike Share row shows, the layer asks the panel to repaint at once, instead -// of leaving the old prompt up until the manager's next tick (Transit 15 s, -// Bike Share 60 s). +// A camera move that changes a Transit or Bike Share coverage prompt repaints +// the row at once, not at the next manager tick (15 s, 60 s). import { test } from 'node:test'; import assert from 'node:assert/strict'; import { createState as createBikeState } from './bikeshare/state.js'; diff --git a/src/layers/transit/gatePrompt.test.mjs b/src/layers/transit/gatePrompt.test.mjs index 7f439fcdc6..dc4c3e8639 100644 --- a/src/layers/transit/gatePrompt.test.mjs +++ b/src/layers/transit/gatePrompt.test.mjs @@ -1,7 +1,5 @@ -// The Transit coverage prompt names the altitude the closed gate -// actually opens at. Descending over Boston to 2,900 km (below 3,000 km, above -// the 2,850 km enter threshold) loads nothing, so a prompt "Fly below 3,000 km" -// asks for something the camera has already done. +// The Transit prompt names the altitude the gate opens at: at 2,900 km over +// Boston (under 3,000 km, above the 2,850 km enter threshold) nothing loads. import { test } from 'node:test'; import assert from 'node:assert/strict'; import { createState } from './state.js'; diff --git a/src/layers/transit/queries.js b/src/layers/transit/queries.js index 2efe928d5c..7a9f2e0742 100644 --- a/src/layers/transit/queries.js +++ b/src/layers/transit/queries.js @@ -245,9 +245,8 @@ 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). + // English: the analyst's empty note and the row's prompt, both shown + // through translateStatusMessage (ui/statusText.js). const note = state._altitudeGateOpen ? `No feed here yet · ${TRANSIT_REGION_COUNT} regions available` : `Fly below ${Math.round(ACTIVATION_ENTER_ALTITUDE_M / 1000).toLocaleString('en-US')} km to a covered region`; diff --git a/src/layers/transit/viewport.js b/src/layers/transit/viewport.js index a62d49009c..38315e4ae6 100644 --- a/src/layers/transit/viewport.js +++ b/src/layers/transit/viewport.js @@ -111,8 +111,7 @@ export function createViewport({ state, services, parts }) { changed = true; } } - // 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. + // Nothing is left on the map to date. if (desired.size === 0) state._lastUpdate = null; for (const [feedId, feed] of desired) { if (!state._activeFeeds.has(feedId)) { @@ -124,8 +123,7 @@ export function createViewport({ state, services, parts }) { parts.ingestion.sweepAgedVehicles(Date.now()); parts.rendering.syncRenderHold(); governorRequestRender('transit-proximity'); - // The row's text follows the camera (coverage prompt, feed list), so it - // repaints now instead of at the next 15 s manager tick. + // Repaint now: the row follows the camera, the manager tick is 15 s. if (changed) state._dataManager?.refreshLayerStats?.('transit'); } diff --git a/src/ui/statusText.js b/src/ui/statusText.js index f4cbb59a0b..d13faff7e7 100644 --- a/src/ui/statusText.js +++ b/src/ui/statusText.js @@ -269,10 +269,8 @@ export function translateStatusLine(text) { /** Thousands separators out of an English number ("3,000" → 3000). */ const englishNumber = (text) => Number(text.replace(/,/g, '')); -// Coverage notes of a layer whose view has no feed, whole lines with a number -// in them: transit (transit/queries.js) and bikeshare (bikeshare/controls.js). -// Their " · " is part of one sentence, so they are matched before the line is -// split into pieces. Keep these in step with the producers. +// Coverage notes (transit/queries.js, bikeshare/controls.js). Their " · " is +// inside one sentence, so they match whole before the line is split. const COVERAGE_NOTE_PATTERNS = [ [ /^Fly below ([\d,]+) km to a covered region$/, From ea76fc4bc07327b9d8297aa6b2663660ca0d5947 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 6 Nov 2026 22:01:39 +0400 Subject: [PATCH 29/61] Fold duplicate coverage tests into their neighbours --- .../1576-transit-bikeshare-coverage-prompt.md | 8 +- src/data/manager.js | 12 -- src/layers/bikeshare/coverageStatus.test.mjs | 121 ------------------ src/layers/bikeshare/rowRepaint.test.mjs | 79 +++++++++++- src/layers/bikeshare/viewport.js | 4 +- src/layers/promptRepaint.test.mjs | 120 ----------------- src/layers/transit/gatePrompt.test.mjs | 64 --------- src/layers/transit/lifecycle.test.mjs | 12 ++ .../transit/refreshErrorRepaint.test.mjs | 2 + 9 files changed, 94 insertions(+), 328 deletions(-) delete mode 100644 src/layers/bikeshare/coverageStatus.test.mjs delete mode 100644 src/layers/promptRepaint.test.mjs delete mode 100644 src/layers/transit/gatePrompt.test.mjs diff --git a/changelog.d/1576-transit-bikeshare-coverage-prompt.md b/changelog.d/1576-transit-bikeshare-coverage-prompt.md index 660c1f30b5..4d13d8d3ed 100644 --- a/changelog.d/1576-transit-bikeshare-coverage-prompt.md +++ b/changelog.d/1576-transit-bikeshare-coverage-prompt.md @@ -1,6 +1,4 @@ - Say why Transit and Bike Share are empty outside coverage. Over a city with - no feed or system (London, Tokyo) their Layers rows read - `No feed here yet · 17 regions available` and - `No bike share here yet · 61 systems available`, or how low to fly, instead - of `never`; leaving coverage clears the last-update time (German, @gekh, - #1576). + no feed or system (London, Tokyo) their Layers rows say so and count the + covered regions or systems, or say how low to fly, instead of `never`; + leaving coverage clears the last-update time (German, @gekh, #1576). diff --git a/src/data/manager.js b/src/data/manager.js index 688fb94d23..5de10f665b 100644 --- a/src/data/manager.js +++ b/src/data/manager.js @@ -15,18 +15,6 @@ export class DataLayerManager extends LayerLifecycle { this._presentation.refresh(); } - /** - * Repaint the toggle panel now. For layers whose data arrives outside their - * manager tick (camera-driven loads such as Transit's proximity polls), so a - * row shows its count when the data lands instead of at the next interval. - * One DOM pass; skipped while the document is hidden. - * @param {string} [layerId] - The layer whose row changed. - */ - refreshLayerStats(layerId) { - this._dropRecoveredRefreshError(layerId); - this._refreshTogglePanel(); - } - _buildMetaText(layer) { return this._presentation.panel._buildMetaText(layer); } diff --git a/src/layers/bikeshare/coverageStatus.test.mjs b/src/layers/bikeshare/coverageStatus.test.mjs deleted file mode 100644 index 004c75c945..0000000000 --- a/src/layers/bikeshare/coverageStatus.test.mjs +++ /dev/null @@ -1,121 +0,0 @@ -// BIKESHARE COVERAGE STATUS — a view with no system says so. -// -// With no system in range (London, Tokyo) the layer says why instead of -// "never", and 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`); - } -}); diff --git a/src/layers/bikeshare/rowRepaint.test.mjs b/src/layers/bikeshare/rowRepaint.test.mjs index 5f55381689..4bfea999c4 100644 --- a/src/layers/bikeshare/rowRepaint.test.mjs +++ b/src/layers/bikeshare/rowRepaint.test.mjs @@ -1,11 +1,13 @@ -// Bike Share: after the camera settles, the last row the panel painted must -// match what the layer reports now. Each case drives the real viewport, +// Bike Share's Layers row. With no system in range it says why instead of +// "never" and keeps no date for data it no longer draws. After the camera +// settles, the last row the panel painted must match what the layer reports +// now. Each case drives the real viewport, // ingestion, rendering and controls; the manager is a spy that records the // row text (LayerPanel._buildMetaText) at every refreshLayerStats() call. import { test } from 'node:test'; import assert from 'node:assert/strict'; import * as Cesium from 'cesium'; -import { CITY_BY_ID } from './registry.js'; +import { CITY_BY_ID, GBFS_CITY_REGISTRY } from './registry.js'; import { createState } from './state.js'; import { createControls } from './controls.js'; import { createIngestion } from './ingestion.js'; @@ -175,6 +177,7 @@ function makeLiveLayer() { source, painted, lastPainted: () => painted.at(-1), + stats: () => controls.getStats(), live: () => rowText(controls.getStats()), moveTo(place, height = LOW_M) { Object.assign(camera, place, { height }); @@ -291,3 +294,73 @@ test('leaving the failed city of two repaints DEGRADED away', async () => { assert.doesNotMatch(layer.live(), /^degraded/); assert.equal(layer.lastPainted(), layer.live()); }); + +test('above the altitude gate the row says how low to fly', async () => { + const layer = makeLiveLayer(); + await layer.enable(); + await layer.moveTo(LONDON, 2_000_000); + const stats = layer.stats(); + 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 layer = makeLiveLayer(); + await layer.enable(); + const stats = layer.stats(); + 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 in range, loading, failed or a disabled layer gets no prompt', async () => { + const layer = makeLiveLayer(); + assert.equal(layer.stats().status, undefined, 'disabled'); + + const info = deferred(); + layer.source.gates.set(`${BOSTON_ID}:info`, info); + await layer.enable(); + const entering = layer.moveTo(BOSTON); + assert.equal(layer.stats().status, undefined, 'loading'); + info.resolve(); + await entering; + await settle(); + assert.equal(layer.stats().status, undefined, 'loaded'); + + // Left mid-load: range is empty, but the aborted load still owns the row. + const leaving = makeLiveLayer(); + leaving.source.gates.set(`${BOSTON_ID}:info`, deferred()); + await leaving.enable(); + const loading = leaving.moveTo(BOSTON); + await settle(); + const left = leaving.moveTo(LONDON); + assert.equal(leaving.state._activeCityIds.size, 0); + assert.equal(leaving.stats().loading, true); + assert.equal(leaving.stats().status, undefined, 'leaving mid-load'); + await Promise.all([loading, left]); + + const failed = makeLiveLayer(); + failed.source.dead.add(BOSTON_ID); + await failed.enable(); + await failed.moveTo(BOSTON); + await settle(); + assert.equal(failed.stats().status, undefined, 'failed'); + assert.equal(failed.stats().error, 'GBFS fetch error'); +}); + +test('leaving every system behind drops the date of the data it drew', async () => { + for (const height of [LOW_M, 2_000_000]) { + const layer = makeLiveLayer(); + await layer.enable(); + await layer.moveTo(BOSTON); + await settle(); + assert.ok(layer.stats().lastUpdate, 'Boston is dated'); + + await layer.moveTo(LONDON, height); + assert.equal(layer.stats().lastUpdate, null, `at ${height} m`); + } +}); diff --git a/src/layers/bikeshare/viewport.js b/src/layers/bikeshare/viewport.js index d4cc44cb6c..46b6b7d120 100644 --- a/src/layers/bikeshare/viewport.js +++ b/src/layers/bikeshare/viewport.js @@ -243,11 +243,9 @@ export function createViewport({ state: layerState, services, parts, source }) { nextActive.size !== layerState._activeCityIds.size || [...nextActive].some((cityId) => !layerState._activeCityIds.has(cityId)); layerState._activeCityIds = nextActive; - if (layerState._activeCityIds.size === 0) { + if (nextActive.size === 0) { layerState._count = 0; layerState._lastUpdate = null; - if (changed) refreshRow(); - return; } if (changed) refreshRow(); diff --git a/src/layers/promptRepaint.test.mjs b/src/layers/promptRepaint.test.mjs deleted file mode 100644 index 38193ca72b..0000000000 --- a/src/layers/promptRepaint.test.mjs +++ /dev/null @@ -1,120 +0,0 @@ -// A camera move that changes a Transit or Bike Share coverage prompt repaints -// the row at once, not at the next manager tick (15 s, 60 s). -import { test } from 'node:test'; -import assert from 'node:assert/strict'; -import { createState as createBikeState } from './bikeshare/state.js'; -import { createControls as createBikeControls } from './bikeshare/controls.js'; -import { createModel as createBikeModel } from './bikeshare/model.js'; -import { createViewport as createBikeViewport } from './bikeshare/viewport.js'; -import { createState as createTransitState } from './transit/state.js'; -import { createViewport as createTransitViewport } from './transit/viewport.js'; -import { createQueries as createTransitQueries } from './transit/queries.js'; - -const rad = Math.PI / 180; -const LONDON = { lat: 51.5072, lon: -0.1276 }; -const BOSTON = { lat: 42.3601, lon: -71.0589 }; - -const services = () => ({ - overlays: { - setOverlayEntries() {}, - setOverlaySourceVisible() {}, - clearOverlaySource() {}, - }, - render: { governorRequestRender() {} }, -}); - -function viewer(at, height) { - return { - camera: { - positionCartographic: { - height, - latitude: at.lat * rad, - longitude: at.lon * rad, - }, - computeViewRectangle: () => undefined, - }, - scene: { globe: {} }, - }; -} - -function spyManager() { - const dm = { repaints: 0 }; - dm.refreshLayerStats = () => { - dm.repaints++; - }; - return dm; -} - -test('Bike Share: flying from London into Boston repaints the prompt row', async () => { - const svc = services(); - const state = createBikeState({ services: svc }); - const parts = { - queries: { collectDetectableStations: () => [] }, - model: createBikeModel({ state, services: svc, parts: {}, source: null }), - ingestion: { - abortInFlight() {}, - loadCityStationInfo: async () => new Map(), - loadCityStationStatus: async () => new Map(), - }, - rendering: { - removeCityPoints() {}, - ensureCityPoints() {}, - applyStatusToPoints() {}, - }, - }; - parts.viewport = createBikeViewport({ - state, - services: svc, - parts, - source: null, - }); - const { methods } = createBikeControls({ - state, - services: svc, - parts, - source: {}, - }); - state._enabled = true; - const dm = spyManager(); - methods.attachDataManager(dm); - - state._viewer = viewer(LONDON, 8_000); - await parts.viewport.runProximityCheck(); - assert.equal(methods.getStats().status, 'zoom-in'); - - const before = dm.repaints; - state._viewer = viewer(BOSTON, 3_000); - await parts.viewport.runProximityCheck(); - assert.equal(methods.getStats().status, undefined, 'Boston is covered'); - assert.ok(dm.repaints > before, 'the row was asked to repaint'); -}); - -test('Transit: leaving Boston for London repaints the row', () => { - const svc = services(); - const state = createTransitState({ services: svc }); - const parts = { - ingestion: { - feedStatus: () => ({ count: 0 }), - pollFeed() {}, - removeFeedVehicles() {}, - sweepAgedVehicles() {}, - }, - rendering: { requestVisibility() {}, syncRenderHold() {} }, - }; - parts.viewport = createTransitViewport({ state, services: svc, parts }); - const queries = createTransitQueries({ state, parts }).methods; - state._enabled = true; - const dm = spyManager(); - state._dataManager = dm; - - state._viewer = viewer(BOSTON, 4_000); - parts.viewport.runProximityCheck(); - assert.ok(state._activeFeeds.size > 0, 'Boston has a feed'); - state._lastUpdate = Date.now(); - - const before = dm.repaints; - state._viewer = viewer(LONDON, 4_000); - parts.viewport.runProximityCheck(); - assert.equal(queries.getStats().status, 'zoom-in'); - assert.ok(dm.repaints > before, 'the row was asked to repaint'); -}); diff --git a/src/layers/transit/gatePrompt.test.mjs b/src/layers/transit/gatePrompt.test.mjs deleted file mode 100644 index dc4c3e8639..0000000000 --- a/src/layers/transit/gatePrompt.test.mjs +++ /dev/null @@ -1,64 +0,0 @@ -// The Transit prompt names the altitude the gate opens at: at 2,900 km over -// Boston (under 3,000 km, above the 2,850 km enter threshold) nothing loads. -import { test } from 'node:test'; -import assert from 'node:assert/strict'; -import { createState } from './state.js'; -import { createViewport } from './viewport.js'; -import { createQueries } from './queries.js'; -import { ACTIVATION_ENTER_ALTITUDE_M } from './policy.js'; - -const BOSTON = { lat: 42.3601, lon: -71.0589 }; - -function makeLayer() { - const services = { - overlays: { - setOverlayEntries() {}, - setOverlaySourceVisible() {}, - clearOverlaySource() {}, - }, - render: { governorRequestRender() {} }, - }; - const state = createState({ services }); - const polled = []; - const parts = { - ingestion: { - feedStatus: () => ({ count: 0 }), - pollFeed: (feed) => polled.push(feed.id), - removeFeedVehicles() {}, - sweepAgedVehicles() {}, - }, - rendering: { requestVisibility() {}, syncRenderHold() {} }, - }; - parts.viewport = createViewport({ state, services, parts }); - const queries = createQueries({ state, parts }).methods; - state._enabled = true; - const rad = Math.PI / 180; - state._viewer = { - camera: { - positionCartographic: { - height: 0, - latitude: BOSTON.lat * rad, - longitude: BOSTON.lon * rad, - }, - computeViewRectangle: () => undefined, - }, - scene: { globe: {} }, - }; - return { state, queries, viewport: parts.viewport, polled }; -} - -test('below the prompted altitude but above the gate, the prompt names the gate', () => { - const { state, queries, viewport, polled } = makeLayer(); - state._viewer.camera.positionCartographic.height = 2_900_000; - viewport.runProximityCheck(); - - // Nothing loads at 2,900 km: the gate opens at the enter threshold. - assert.equal(state._altitudeGateOpen, false); - assert.deepEqual(polled, []); - - const km = Math.round(ACTIVATION_ENTER_ALTITUDE_M / 1000).toLocaleString( - 'en-US', - ); - const { statusMessage } = queries.getStats(); - assert.equal(statusMessage, `Fly below ${km} km to a covered region`); -}); diff --git a/src/layers/transit/lifecycle.test.mjs b/src/layers/transit/lifecycle.test.mjs index dc18fd6f02..4711eebdf2 100644 --- a/src/layers/transit/lifecycle.test.mjs +++ b/src/layers/transit/lifecycle.test.mjs @@ -4021,3 +4021,15 @@ test('a view with no feed reads its coverage prompt, not an undated feed', async 'Fly below 2,850 km to a covered region', ); }); + +test('the prompt names the altitude the gate opens at, not 3,000 km', async (t) => { + // 2,900 km is under ACTIVATION_ALTITUDE_M but above the enter threshold. + const app = harness(t, { altitude: 2_900_000 }); + app.layer.enable(app.viewer); + await app.layer.update(); + assert.deepEqual(app.requested, [], 'nothing loads over Boston'); + assert.equal( + app.layer.getStats().statusMessage, + 'Fly below 2,850 km to a covered region', + ); +}); diff --git a/src/layers/transit/refreshErrorRepaint.test.mjs b/src/layers/transit/refreshErrorRepaint.test.mjs index d1a5c16b8f..d85a4a375f 100644 --- a/src/layers/transit/refreshErrorRepaint.test.mjs +++ b/src/layers/transit/refreshErrorRepaint.test.mjs @@ -91,8 +91,10 @@ test('leaving a feed whose tick failed repaints its error away', async () => { await lifecycle.refreshLayer('transit'); assert.match(row(), /feed unavailable/, 'the tick recorded the failure'); + const before = painted.length; state._viewer = viewer(LONDON, 4_000); parts.viewport.runProximityCheck(); assert.equal(queries.getStats().status, 'zoom-in'); + assert.ok(painted.length > before, 'leaving Boston repainted the row'); assert.doesNotMatch(painted.at(-1), /feed unavailable/); }); From b86c650428db01c0b09fadda54eabbf523ca506b Mon Sep 17 00:00:00 2001 From: Enzo Abyie Date: Fri, 6 Nov 2026 20:14:03 -0500 Subject: [PATCH 30/61] i18n(fr): typography, terminology and wording fixes --- src/i18n/locales/fr.json | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 738800324d..485d3a93ac 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -1018,11 +1018,11 @@ "Longitudes must be within ±180°": "Les longitudes doivent être comprises entre −180° et +180°", "Select one side of the dateline": "Ne traversez pas la ligne de changement de date", "Box must enclose an area": "La zone doit délimiter une surface", - "Add the full Starlink broadband shell (thousands of extra points)": "Ajouter toute la constellation Starlink (des milliers de points en plus)", - "Loading the Starlink shell…": "Chargement de la constellation Starlink…", + "Add the full Starlink broadband shell (thousands of extra points)": "Ajouter toute la couche de la constellation Starlink (des milliers de points en plus)", + "Loading the Starlink shell…": "Chargement de la couche de la constellation Starlink…", "Starlink {detail} — click to retry": "Starlink {detail} — cliquer pour réessayer", "load failed": "échec du chargement", - "Showing the full Starlink shell — click for the core catalog only": "Constellation Starlink complète affichée — cliquer pour le catalogue de base seulement", + "Showing the full Starlink shell — click for the core catalog only": "Couche complète de la constellation Starlink affichée — cliquer pour le catalogue de base seulement", "DENSE ···": "DENSE ···", "DENSE ✕": "DENSE ✕", "DENSE": "DENSE", @@ -1105,7 +1105,7 @@ "Hybrid": "Hybride", "Lines": "Lignes", "Dots": "Points", - "Road lines colored by live flow: green to red": "Routes colorées selon le trafic en direct : du vert au rouge", + "Road lines colored by live flow: green to red": "Routes colorées selon le trafic en direct : du vert au rouge", "Moving dots colored by live flow": "Points mobiles colorés selon le trafic en direct", "Moving dots": "Points mobiles", "TomTom key unavailable": "Clé TomTom indisponible", @@ -1121,7 +1121,7 @@ "LIVE · Roads: {source} · No flow roads in view": "DIRECT · Routes : {source} · Aucune route avec flux dans la vue", "LIVE · Roads: {source} · Flow {percent}%": "DIRECT · Routes : {source} · Flux {percent} %", "SIMULATED · Roads: {source} · Flow {percent}%": "SIMULÉ · Routes : {source} · Flux {percent} %", - "STALE · Roads: {source} · Flow: cached TomTom tiles": "OBSOLÈTE · Routes : {source} · Flux : tuiles TomTom en cache", + "STALE · Roads: {source} · Flow: cached TomTom tiles": "OBSOLÈTE · Routes : {source} · Flux : tuiles TomTom en cache", "Syncing flow · Roads: OpenStreetMap · Flow: TomTom · Unmatched: simulated": "Synchro du flux · Routes : OpenStreetMap · Flux : TomTom · Non appariées : simulées", "LIVE · Roads: OpenStreetMap · Flow: TomTom · {percent}% cov · Unmatched: simulated": "DIRECT · Routes : OpenStreetMap · Flux : TomTom · couv. {percent} % · Non appariées : simulées", "LIVE · Roads: OpenStreetMap · Flow: TomTom · {percent}% cov": "DIRECT · Routes : OpenStreetMap · Flux : TomTom · couv. {percent} %", @@ -1218,7 +1218,7 @@ "Contiguous US · gaps ≠ no rain": "États-Unis contigus · lacunes ≠ absence de pluie", "Americas + Pacific · not individual strikes": "Amériques + Pacifique · pas des impacts individuels", "Color: strikes/km²/min ×10³": "Couleur : impacts/km²/min ×10³", - "Color: {units}": "Couleur : {units}", + "Color: {units}": "Couleur : {units}", "RADAR · {units}": "RADAR · {units}", "60°S–60°N · typically 2–3 h delayed": "60°S–60°N · retard habituel de 2 à 3 h", "North America · infrared imagery": "Amérique du Nord · imagerie infrarouge", @@ -1350,7 +1350,7 @@ "{label} is unavailable": "{label} est indisponible", "This map stack": "Ce fond de carte", "{label} unavailable: {hint}": "{label} indisponible : {hint}", - "Google 3D tiles unavailable — check the key's API restrictions, quota, or network": "Tuiles Google 3D indisponibles — vérifiez les restrictions d'API de la clé, le quota ou le réseau", + "Google 3D tiles unavailable — check the key's API restrictions, quota, or network": "Google 3D Tiles indisponible — vérifiez les restrictions d'API de la clé, le quota ou le réseau", "Needs {envVars} — add it in Provider Settings — or a Cesium ion token for the ion-hosted route": "Nécessite {envVars} — à ajouter dans les paramètres des fournisseurs — ou un jeton Cesium ion pour la variante hébergée par ion", "Exit cockpit to fly to a camera": "Quittez le cockpit pour rejoindre une caméra", "Exit cockpit to fly to a location": "Quittez le cockpit pour rejoindre un lieu", @@ -1489,7 +1489,7 @@ "Apply details": "Appliquer les détails", "Select a scene first": "Sélectionnez d'abord une scène", "Share selected scene": "Partager la scène sélectionnée", - "Scene JSON preserves authored settings and attribution. It does not include asset files. Bundles include only pack files you choose here or previously imported bundle files.": "Le JSON de scène conserve les réglages de l'auteur et l'attribution. Il n'inclut pas les fichiers de ressources. Les archives n'incluent que les fichiers de paquets choisis ici ou ceux d'archives déjà importées.", + "Scene JSON preserves authored settings and attribution. It does not include asset files. Bundles include only pack files you choose here or previously imported bundle files.": "Le JSON de scène conserve les paramètres de l'auteur et l'attribution. Il n'inclut pas les fichiers de ressources. Les archives n'incluent que les fichiers de paquets choisis ici ou ceux d'archives déjà importées.", "Download scene JSON": "Télécharger le JSON de scène", "Choose data-pack files": "Choisir des fichiers de paquet de données", "Or choose a data-pack folder": "Ou choisir un dossier de paquet de données", @@ -2574,7 +2574,7 @@ "{layer} is enabled on the {source} feed, but no airborne aircraft is loaded in the {place} view yet": "La couche {layer} est activée sur le flux {source}, mais aucun aéronef en vol n'est encore chargé dans la vue {place}", "{layer} is enabled, but no airborne aircraft is loaded in the {place} view yet": "La couche {layer} est activée, mais aucun aéronef en vol n'est encore chargé dans la vue {place}", "{layer} is enabled, but its aircraft feed is unavailable": "La couche {layer} est activée, mais son flux d'aéronefs est indisponible", - "{layer} is enabled, but its destination refresh did not complete": "La couche {layer} est activée, mais son actualisation à destination ne s'est pas terminée", + "{layer} is enabled, but its destination refresh did not complete": "La couche {layer} est activée, mais l'actualisation de ses destinations ne s'est pas terminée", "{layer} is enabled, but {source} is unavailable": "La couche {layer} est activée, mais {source} est indisponible", "Could not arrive at {place}": "Impossible d'atteindre {place}", "{name} is no longer loaded": "{name} n'est plus chargé", @@ -2810,7 +2810,7 @@ "AVAILABLE MISSIONS": "MISSIONS DISPONIBLES", "SELECT A MISSION TO INSPECT": "CHOISIR UNE MISSION À EXAMINER", "LOADING 30-DAY MISSION INDEX": "CHARGEMENT DE L'INDEX DES MISSIONS À 30 JOURS", - "Space Missions unavailable: the mission index could not load. Try again later.": "Missions spatiales indisponibles : impossible de charger l’index des missions. Réessayez plus tard.", + "Space Missions unavailable: the mission index could not load. Try again later.": "Missions spatiales indisponibles : impossible de charger l'index des missions. Réessayez plus tard.", "30-DAY MISSION INDEX UNAVAILABLE": "INDEX DES MISSIONS À 30 JOURS INDISPONIBLE", "TAB PREVIEWS · ENTER / SPACE SELECTS": "TAB APERÇU · ENTER / SPACE SÉLECTIONNE", "Internet radio and local SDR": "Radio Internet et SDR local", @@ -2831,7 +2831,7 @@ "Radio volume": "Volume de la radio", "STATION SITE": "SITE DE LA STATION", "DIRECTORY: RADIO BROWSER": "ANNUAIRE : RADIO BROWSER", - "Audio connects directly to the broadcaster when you press play, choose a station on the globe or ask voice to play. Your IP is visible to that broadcaster.": "Le flux audio se connecte directement au diffuseur dès que vous lancez la lecture, choisissez une station sur le globe ou la demandez par la voix. Votre IP est visible par ce diffuseur.", + "Audio connects directly to the broadcaster when you press play, choose a station on the globe or ask voice to play. Your IP is visible to that broadcaster.": "Le flux audio se connecte directement au diffuseur lorsque vous lancez la lecture, que vous choisissez une station sur le globe ou que vous demandez sa lecture à la voix. Votre IP est visible par ce diffuseur.", "Local RTL-SDR receiver": "Récepteur RTL-SDR local", "LOCAL RTL-SDR": "RTL-SDR LOCAL", "Chrome/Edge · WebUSB · one local tuner shared by FM and the Local ADS-B layer.": "Chrome/Edge · WebUSB · un seul tuner local partagé entre la FM et la couche ADS-B local.", @@ -3194,7 +3194,7 @@ "The provider refused access for this key. Check the key's project, region or permissions.": "Le fournisseur a refusé l'accès pour cette clé. Vérifiez le projet, la région ou les autorisations de la clé.", "The provider account is out of credit. Check its billing, or choose another AI Provider in Settings.": "Le compte du fournisseur n'a plus de crédit. Vérifiez la facturation ou choisissez un autre fournisseur d'IA dans les paramètres.", "SIGHTING": "OBSERVATION", - "Show {name} sighting": "Afficher l’observation de {name}", + "Show {name} sighting": "Afficher l'observation de {name}", "seen {age} ago": "vu il y a {age}", "observed {age} ago": "observé il y a {age}", "Be Whale Wise": "Respectez les cétacés", @@ -3232,7 +3232,7 @@ "Cetacean": "Cétacé", "Wildlife Sightings": "Observations naturalistes", "Exit cockpit to fly to a sighting": "Quittez le cockpit pour rejoindre une observation", - "Exit cockpit to fly to a sighting area": "Quittez le cockpit pour rejoindre une zone d’observation", + "Exit cockpit to fly to a sighting area": "Quittez le cockpit pour rejoindre une zone d'observation", "Wildlife": "Faune et flore", "Zoom in for local sightings": "Zoomez pour les observations locales", "Loading photo...": "Chargement de la photo…", @@ -3242,18 +3242,18 @@ "Acartia": "Acartia", "CC BY 4.0": "CC BY 4.0", "{count} sightings in view": "{count} observations dans la vue", - "Close sighting": "Fermer l’observation", - "Wildlife observed within 48 h (whales 7 d). Color and badge glyph show the taxon group. Sensitive species are shown only as 0.2° cells; Salish Sea marine mammal reports via Acartia are rounded to 0.01°. Not a census.": "Faune observée au cours des dernières 48 h (cétacés 7 jours). La couleur et le pictogramme du badge indiquent le groupe taxonomique. Les espèces sensibles sont limitées à des cellules de 0,2° ; les signalements de mammifères marins Acartia en mer des Salish sont arrondis à 0,01°. Pas un recensement.", + "Close sighting": "Fermer l'observation", + "Wildlife observed within 48 h (whales 7 d). Color and badge glyph show the taxon group. Sensitive species are shown only as 0.2° cells; Salish Sea marine mammal reports via Acartia are rounded to 0.01°. Not a census.": "Faune observée au cours des dernières 48 h (cétacés 7 jours). La couleur et le pictogramme du badge indiquent le groupe taxonomique. Les espèces sensibles sont limitées à des cellules de 0,2° ; les signalements de mammifères marins Acartia en mer des Salish sont arrondis à 0,01°. Pas un recensement.", "Open {name} on iNaturalist": "Ouvrir {name} sur iNaturalist", "Open {name} on Acartia": "Ouvrir {name} sur Acartia", "iNaturalist": "iNaturalist", "iNaturalist contributors · licences per record": "Contributeurs iNaturalist · licences par observation", "iNaturalist contributors · Acartia {count} (Salish Sea) · licences per record": "Contributeurs iNaturalist · Acartia {count} (mer des Salish) · licences par observation", - "{days}d": "{days}j", + "{days}d": "{days} j", "All markers": "Tous les marqueurs", "Show markers of every age": "Afficher les marqueurs de tout âge", - "Maximum event age: {days}d; undated markers are kept": "Ancienneté maximale : {days} j ; marqueurs sans date conservés", + "Maximum event age: {days}d; undated markers are kept": "Ancienneté maximale : {days} j ; marqueurs sans date conservés", "event age filter|All": "Tous", "Event age": "Ancienneté", - "Event age: {days}d · undated kept": "Ancienneté : {days} j · marqueurs sans date conservés" + "Event age: {days}d · undated kept": "Ancienneté : {days} j · marqueurs sans date conservés" } From 36c29d6ab49ada6ae6b89f912a10d6640e96ded5 Mon Sep 17 00:00:00 2001 From: Enzo Abyie Date: Fri, 6 Nov 2026 20:14:15 -0500 Subject: [PATCH 31/61] changelog: french catalog review --- changelog.d/1611-fr-catalog-review.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog.d/1611-fr-catalog-review.md diff --git a/changelog.d/1611-fr-catalog-review.md b/changelog.d/1611-fr-catalog-review.md new file mode 100644 index 0000000000..dad3020923 --- /dev/null +++ b/changelog.d/1611-fr-catalog-review.md @@ -0,0 +1,2 @@ +- French catalog review: missing narrow no-break spaces, apostrophes, one + mistranslated message and the Starlink shell wording (abiyeenzo, #1611). From c5bdcdf37f575543deea0424a46db1b221046e8c Mon Sep 17 00:00:00 2001 From: daika Date: Sun, 8 Nov 2026 04:02:47 +0700 Subject: [PATCH 32/61] chore(format): adopt responseCompression.test.mjs into the format scope --- scripts/format-scope.json | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/format-scope.json b/scripts/format-scope.json index b23ab75b0f..6c5354aa27 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -1120,6 +1120,7 @@ "src/sky/starrySky.test.mjs", "src/tooling/skyAssets.test.mjs", "src/tooling/skyAssets.paintOut.test.mjs", + "src/tooling/responseCompression.test.mjs", "scripts/qa-anime-sky.mjs", "scripts/qa-sky-model-lighting.mjs", "server/providers/overpass/requestAdmission.test.mjs", From e0ba12e5a9db5835c6cfed2ace11aefaea47ada6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Itallo=20Brand=C3=A3o?= <45429643+IMBrandao@users.noreply.github.com> Date: Sat, 7 Nov 2026 19:38:24 -0300 Subject: [PATCH 33/61] feat(transit): add Lisbon's Carris Metropolitana buses Keyless GTFS-Realtime feed from Carris Metropolitana, documented in the operator's public API repository. No licence is stated for the realtime endpoint (the static GTFS is CC BY 4.0), so it is credited as a courtesy on the same basis as the Metro Transit and OVapi feeds. The feed publishes km/h, so a new `speedUnit` registry field lets the proxy convert to m/s. Route ids wrap the GTFS route id in an area prefix and are read as the line number. Co-Authored-By: Claude Opus 5.5 --- DATA_SOURCES.md | 3 +- README.md | 2 +- changelog.d/szczecin-lisbon-transit.md | 6 ++++ changelog.d/szczecin-transit.md | 3 -- docs/CURRENT-STATE.md | 4 +-- src/data/transitFeeds.js | 39 ++++++++++++++++++++++++++ src/data/transitFeeds.test.mjs | 33 ++++++++++++++++++++++ src/data/transitProxy.js | 6 +++- src/data/transitProxy.test.mjs | 21 ++++++++++++++ 9 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 changelog.d/szczecin-lisbon-transit.md delete mode 100644 changelog.d/szczecin-transit.md diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 6532837d82..2dc33dad5d 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -100,6 +100,7 @@ How to read this: | **Burlington Transit** (opendata.burlington.ca) | Transit layer live vehicles, Burlington ON | Burlington Transit realtime data under the City of Burlington Open Data Terms of Use, which permit any lawful purpose. The terms are revocable and must travel with the data, so the credit links them. Route ids are internal keys and are joined to the City’s published GTFS. | Credit to the City of Burlington plus a link to its Open Data Terms of Use, which the licence requires | | **SMTR Rio de Janeiro** (dados.mobilidade.rio) | Transit layer live vehicles, Rio de Janeiro: municipal buses (SPPO) and the Mobi-Rio BRT, as two feeds | CC BY 4.0, stated on both data.rio catalog pages. Keyless GTFS-Realtime published by the Secretaria Municipal de Transportes, labelled beta, with a gateway limit of 5 requests a second and 60 a minute. Line names come from SMTR’s GTFS `routes.txt` (dados.mobilidade.rio/gtfs/schedule), under the same licence. | Attribution to SMTR / Prefeitura da Cidade do Rio de Janeiro under CC BY 4.0 | | **ZDiTM Szczecin** (zditm.szczecin.pl) | Transit layer live vehicles, Szczecin, Poland: buses and trams as one feed | CC0 1.0, stated on the ZDiTM developer page: “The data are provided free of charge under the CC0 1.0 licence, for use in any context, with no prior notification required.” Keyless GTFS-Realtime; the page says one update a minute, measured at about every 20 seconds. The feed carries no route id, so every vehicle takes the default bus mode. | None required (CC0); credited to ZDiTM Szczecin as a courtesy | +| **Carris Metropolitana** (api.carrismetropolitana.pt) | Transit layer live vehicles, Lisbon Metropolitan Area, Portugal | Keyless GTFS-Realtime documented in the operator’s public API repository (github.com/carrismetropolitana/api). No licence is stated for the realtime endpoint; the operator’s static GTFS is CC BY 4.0. Included on the same basis as the Metro Transit and OVapi feeds and credited as a courtesy; it can be switched off if Carris objects. Speeds are published in km/h and converted to m/s by the proxy. Route ids are read as the line number per the operator’s `/v2/routes`. | Courtesy credit to Carris Metropolitana | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | | **OpenSeaMap** (`tiles.openseamap.org`) | Sea Marks layer: raster overlay of buoys, lighthouses and ports (#10) | Chart tiles CC BY-SA 2.0; data ODbL 1.0 via OpenStreetMap | "Sea marks © OpenSeaMap contributors (CC BY-SA 2.0) · Data © OpenStreetMap contributors (ODbL)" | @@ -187,7 +188,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **Houston TranStar cameras.** Keyless. The camera list is the public `traffic.houstontranstar.org/data/layers/cctvSnapshots_json.js` catalog (~1,000 cameras across Greater Houston); frames are stills at `www.houstontranstar.org/snapshots/cctv/.jpg`, synthesized from a validated numeric id rather than taken from the payload, and only that host is registered. Cameras whose catalog id is `0` (a different, non-snapshot class) and cameras outside Greater Houston are dropped. TranStar's `dir` field is the side of the freeway the camera sits on, not the way it faces: TranStar's own map shows it as "Traffic closest to the camera is traveling …" (South → eastbound, North → westbound, West → southbound, East → northbound). That travel direction (90°, 270°, 180°, 0°) seeds the heading as a low-confidence prior with the low-confidence pose; `None` or an unknown value uses the shared id-hash fallback at low confidence. Headings are corrected with the in-app calibration gizmo. Off by default. TranStar's [Content Usage terms](https://traffic.houstontranstar.org/disclaimer.aspx) prohibit copying or distributing the site's information, and external framing or linking to specific images, without TxDOT's prior written permission; its FAQ grants permission-free use only for the RSS feeds. This project does not hold that permission for downstream installations, so the pack loads only when an operator who holds TxDOT's written permission sets `CCTV_HOUSTON_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to TranStar. Once enabled, it loads the 250 cameras nearest downtown, Uptown, the Medical Center, IAH and Galveston; `CCTV_HOUSTON_MAX_SOURCES` (8–400) changes the cap. Snapshots update about every 3 minutes, which is also the ambient still cadence. Frames are fetched from TranStar and relayed to the browser on demand, buffered only transiently per request, sent with `Cache-Control: no-store`, and not archived. - **Autostrada del Brennero (A22) webcams.** Keyless. The camera list is one request to the Open Data Hub tourism API (`tourism.api.opendatahub.com/v1/WebcamInfo?source=a22`), run by NOI Techpark in South Tyrol, which republishes Autobrennero's own list of 13 motorway webcams with coordinates and kilometre markers. Frames are the operator's stills on `www.autobrennero.it/WebCamImg/km.jpg`, refreshed about once a minute, and only the exact image for each camera's kilometre is registered. The feed names no bearing, so headings use the id-hash fallback at low confidence. The road climbs from about 20 m in the Po valley to about 1,370 m at the Brenner Pass, so each camera's ground elevation comes from a per-kilometre table sampled from the Copernicus GLO-90 DEM (via Open-Meteo's elevation API); a camera not in the table uses a 200 m prior. The Open Data Hub tags every record CC0 (`ClosedData: false`, Autobrennero as licence holder), but that tag is the aggregator's metadata and Autobrennero publishes no terms of its own for the images, so they are credited to the operator as a courtesy and are not redistributed. Frames are fetched at request time and never stored. Disable with `CCTV_A22_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All nineteen registered feeds, covering eighteen regions, are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington, YRT and Rio’s SMTR publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All twenty registered feeds, covering nineteen regions, are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington, YRT and Rio’s SMTR publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for. - **Radio country coverage (optional).** Set `RADIO_PRIORITY_COUNTRIES=IN,PL` in the local `.env` and restart to include stations beyond the global click charts. The operator may choose up to eight unique ISO alpha-2 country codes; no key is needed. Each country adds one bounded query (at most 200 rows) and reserves up to 40 unique, usable stations inside the existing 750-station catalog. Country seeds precede specialist-tag seeds and global popularity fill; unused slots return to the shared pool. This is a coverage preference, not an exhaustive national directory or a guarantee of stations in every city. Countries with no eligible HTTPS MP3/AAC geolocated stations remain empty. An unset list preserves global selection. Country requests share the directory cache and three-worker pool; failed country queries are reported in coverage without blocking a healthy global refresh. Failed/degraded refreshes back off for one minute, with at most three mirrors per query. - **Radio Browser.** In every installation, including when `RADIO_PRIORITY_COUNTRIES` is unset, each request tries at most three mirror candidates (later fallback candidates are skipped), and failed or partial catalog refreshes back off for 60 seconds. A cold-start failure therefore continues returning 503 during that delay even if upstream recovers. `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; broad/specialist responses whose rows all fail the product's health policy do not count as successful queries. Optional priority-country outcomes are advisory: valid, in-limit responses with no eligible stations succeed as empty results, while failed or malformed country queries report unsuccessful coverage without degrading the global catalog. A usable partial cold catalog is explicitly `DEGRADED`, and non-array or empty broad/specialist payloads are rejected atomically. Individual structurally malformed rows are skipped rather than failing the whole query; the response carries their bounded `rejectedStationCount` (at most 10,000), which the client adds to its own rejected rows and reports as degraded coverage without discarding the accepted generation. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. diff --git a/README.md b/README.md index 6c8de0d79a..fff61fd9f4 100644 --- a/README.md +++ b/README.md @@ -444,7 +444,7 @@ Twenty-one layers and map sources. **Nineteen have a keyless path.** Some offer | 📷 **Mapped ALPR Cameras** | License-plate-reader camera locations tagged by OpenStreetMap contributors, loaded one city-sized view at a time, with **SHOW NEAREST**. Locations and tags only: no plate data, no video | OpenStreetMap (incl. DeFlock mapping) | 🟢 | | 📷 **Street Level** | Street-level photos behind one panel, one chip per provider: coverage on the streets, image cones, an embedded viewer with full-screen **EXPAND**. Mapillary, Google Street View, KartaView and Panoramax | Mapillary · Google · KartaView · Panoramax | 🟢 KartaView, Panoramax · 🟡 Mapillary token · 🔴 Google Maps key | | 📻 **Radio** | Geolocated world radio with an **analog tuner** — drag the needle across up to 750 stations and the globe flies to each broadcaster | Radio Browser / broadcasters | 🟢 | -| 🚌 **Transit** | Live buses, trams, metros, trains and ferries with delayed playback between reports, selected-vehicle trails, and mode-coloured DETECT labels — Boston, Austin, Minneapolis, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro (buses and BRT), Szczecin, and nine in Ontario: Toronto (surface vehicles; the subway publishes no positions), Mississauga, Hamilton, Durham Region, York Region, Guelph, Burlington, Barrie and Kingston | Operator GTFS-Realtime feeds | 🟢 | +| 🚌 **Transit** | Live buses, trams, metros, trains and ferries with delayed playback between reports, selected-vehicle trails, and mode-coloured DETECT labels — Boston, Austin, Minneapolis, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro (buses and BRT), Szczecin, Lisbon, and nine in Ontario: Toronto (surface vehicles; the subway publishes no positions), Mississauga, Hamilton, Durham Region, York Region, Guelph, Burlington, Barrie and Kingston | Operator GTFS-Realtime feeds | 🟢 | | 🚲 **Bikeshare** | Live station availability | GBFS | 🟢 | | 🧭 **Directions** | Click A and B on the globe for a street-following drive, walk or cycle route draped on the terrain with turn-by-turn steps — then FLY the camera along it. No key, no geocoder, no mic | OSRM on FOSSGIS servers (OpenStreetMap) | 🟢 | | ⌖ **OSM Places** | Voice place search ("hospitals in Kathmandu") from OpenStreetMap, drawn as numbered points that follow-up questions can filter. Needs your own Overpass server (`OVERPASS_UPSTREAMS`); off otherwise | diff --git a/changelog.d/szczecin-lisbon-transit.md b/changelog.d/szczecin-lisbon-transit.md new file mode 100644 index 0000000000..103657e8fd --- /dev/null +++ b/changelog.d/szczecin-lisbon-transit.md @@ -0,0 +1,6 @@ +- Add Szczecin, Poland and the Lisbon Metropolitan Area to the Transit layer. + Szczecin's buses and trams come from ZDiTM's keyless feed under CC0 1.0; it + carries no route ids, so vehicles show as buses. Lisbon's buses come from + Carris Metropolitana's keyless feed, which states no licence of its own and + is credited as a courtesy like Metro Transit and OVapi; its km/h speeds are + converted to m/s and its route ids read as the line number (IMBrandao). diff --git a/changelog.d/szczecin-transit.md b/changelog.d/szczecin-transit.md deleted file mode 100644 index 5b2411211f..0000000000 --- a/changelog.d/szczecin-transit.md +++ /dev/null @@ -1,3 +0,0 @@ -- Add Szczecin, Poland to the Transit layer: buses and trams from ZDiTM's - keyless GTFS-Realtime feed, published under CC0 1.0. The feed carries no - route ids, so vehicles show as buses (IMBrandao). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 85bfd2e928..b5820c6b5c 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4644,9 +4644,9 @@ Transit is off by default, and share links use token `j`. The movement panel ord places Transit directly after Street Traffic and before Bike Share. Cameras and utilities retain their own groups. The layer polls registered feeds near the camera every 15 seconds, below a 3,000 km altitude -gate. Eighteen keyless regions are available: Boston, Austin, Minneapolis–St Paul, +gate. Nineteen keyless regions are available: Boston, Austin, Minneapolis–St Paul, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro -(municipal buses and the Mobi-Rio BRT, two feeds), Szczecin, and nine in +(municipal buses and the Mobi-Rio BRT, two feeds), Szczecin, the Lisbon Metropolitan Area, and nine in Ontario — Toronto (TTC surface vehicles; the subway publishes no positions), MiWay, Hamilton HSR, Durham Region, YRT/Viva, Guelph, Burlington, Barrie and Kingston. Mode silhouettes diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 76b2764a66..7515b84171 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -389,6 +389,19 @@ function rioRouteLabel(routeId) { : routeId; } +/** + * Carris Metropolitana realtime route ids wrap the GTFS route id in an + * operator-area prefix and keep its pattern suffix: `[LA77N]1708_0` is GTFS + * route `1708_0`, whose `short_name` (the number on the bus) is `1708`, per + * the operator's own `/v2/routes` API. Anything else passes through. + * @param {string|null} routeId + * @returns {string|null} + */ +function carrisMetropolitanaRouteLabel(routeId) { + const match = /^\[[A-Z0-9]+\](\d{4})_\d+$/.exec(routeId ?? ''); + return match ? match[1] : routeId; +} + /** * Registry of feeds. Order is presentation order in the stats/credit text. * `loadRadiusKm` is the distance from `center` inside which the feed is polled. @@ -398,7 +411,10 @@ function rioRouteLabel(routeId) { * url: string, headers?: Record, * license: string, licenseUrl: string, attribution: string, * defaultMode: string, routeMode?: (routeId: string|null) => string, + * speedUnit?: 'km/h', * }>>} + * `speedUnit` marks a feed that publishes km/h where the spec requires m/s; + * the proxy converts it before the snapshot leaves the server. */ export const TRANSIT_FEED_REGISTRY = Object.freeze([ Object.freeze({ @@ -811,6 +827,29 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ }), defaultMode: 'bus', }), + Object.freeze({ + id: 'carris-metropolitana-lisboa', + name: 'Carris Metropolitana', + operator: 'Carris Metropolitana (TML), Lisbon Metropolitan Area', + region: 'Lisbon Metropolitan Area, Portugal', + // Every vehicle in a 2026-11-07 snapshot, from Mafra to Setúbal, sat + // between 38.47–39.00 N and 9.47–8.79 W, inside 40 km of this point. + center: Object.freeze({ lat: 38.73, lon: -9.13 }), + loadRadiusKm: 45, + url: 'https://api.carrismetropolitana.pt/v2/vehicles.pb', + license: 'No separate licence for the realtime feed', + licenseUrl: 'https://github.com/carrismetropolitana/api', + attribution: 'Carris Metropolitana', + defaultEnabled: true, + terms: Object.freeze({ + quote: + 'GET /vehicles.pb — Returns vehicle locations in Protobuf format, following the GTFS-RT Vehicle Locations standard.', + note: 'The operator publishes this feed keyless and documented for developers in its public API repository, but states no licence for the realtime endpoint; its static GTFS (github.com/carrismetropolitana/gtfs) is CC BY 4.0. Credited as a courtesy, on the same basis as the Metro Transit and OVapi feeds; switch it off if Carris objects. The quote above is the API README, not a licence. `/vehicles.pb` answers with a 307 to `/v2/vehicles.pb`, so the registry points at the target. Speeds are km/h, not the m/s the spec requires: 2026-11-07 readings of 31–33 matched 6–9 m/s of measured movement, so the proxy converts them. Vehicle reports arrive every 30–50 seconds. Route ids are the GTFS route id inside an area prefix and are read as the line number.', + }), + defaultMode: 'bus', + routeLabel: carrisMetropolitanaRouteLabel, + speedUnit: 'km/h', + }), ]); /** diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index 5fab7c27d0..0e3d4ab374 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -578,3 +578,36 @@ test('Szczecin is CC0, live, covers the city and not Berlin', () => { 'Szczecin has a DATA_SOURCES row', ); }); + +test('Carris Metropolitana covers Lisbon from Mafra to Setúbal, not Porto', () => { + const feed = getTransitFeed('carris-metropolitana-lisboa'); + assert.equal(feed.defaultEnabled, true); + assert.equal(feed.url, 'https://api.carrismetropolitana.pt/v2/vehicles.pb'); + assert.equal(feed.speedUnit, 'km/h'); + assert.match(feed.terms.note, /no licence for the realtime endpoint/); + const ids = (lat, lon) => transitFeedsInRange(lat, lon).map((f) => f.id); + for (const [place, lat, lon] of [ + ['Lisbon', 38.7223, -9.1393], + ['Mafra', 38.9369, -9.3277], + ['Setúbal', 38.5244, -8.8882], + ]) { + assert.ok(ids(lat, lon).includes(feed.id), place); + } + assert.ok(!ids(41.1579, -8.6291).includes(feed.id), 'Porto'); + const sources = readFileSync( + new URL('../../DATA_SOURCES.md', import.meta.url), + 'utf8', + ); + assert.ok( + sources.split('\n').some((l) => l.startsWith('| **Carris Metropolitana')), + 'Lisbon has a DATA_SOURCES row', + ); +}); + +test('Carris Metropolitana route ids read as the line number on the bus', () => { + const feed = getTransitFeed('carris-metropolitana-lisboa'); + assert.equal(transitRouteLabel(feed, '[LA77N]1708_0'), '1708'); + assert.equal(transitRouteLabel(feed, '[BNA17]2772_1'), '2772'); + assert.equal(transitRouteLabel(feed, 'unexpected'), 'unexpected'); + assert.equal(transitRouteLabel(feed, null), null); +}); diff --git a/src/data/transitProxy.js b/src/data/transitProxy.js index 458240e9d9..68280d1325 100644 --- a/src/data/transitProxy.js +++ b/src/data/transitProxy.js @@ -257,7 +257,11 @@ export function buildTransitSnapshot(feed, bytes, now = Date.now()) { truncated: decoded.truncated, count: decoded.vehicles.length, vehicles: repairVehicleTimestamps( - decoded.vehicles, + feed.speedUnit === 'km/h' + ? decoded.vehicles.map((v) => + v.speedMps === null ? v : { ...v, speedMps: v.speedMps / 3.6 }, + ) + : decoded.vehicles, decoded.timestamp, Math.floor(now / 1000), ), diff --git a/src/data/transitProxy.test.mjs b/src/data/transitProxy.test.mjs index f03ea2e308..7c173cb5fd 100644 --- a/src/data/transitProxy.test.mjs +++ b/src/data/transitProxy.test.mjs @@ -294,6 +294,27 @@ test('Rio speeds pass through as the m/s they are published in', () => { assert.equal(rio.vehicles[0].speedMps, 10); }); +test('Carris Metropolitana km/h speeds leave the proxy as m/s', () => { + // 2026-11-07: readings of 31-33 matched 6-9 m/s of measured movement. + const bytes = encodeFeed({ + entities: [ + { id: 'moving', lat: 38.72, lon: -9.14, speed: 36 }, + { id: 'parked', lat: 38.73, lon: -9.15 }, + ], + }); + const feed = getTransitFeed('carris-metropolitana-lisboa'); + const lisbon = buildTransitSnapshot(feed, bytes, 1); + const byId = Object.fromEntries(lisbon.vehicles.map((v) => [v.id, v])); + assert.ok(Math.abs(byId.moving.speedMps - 10) < 1e-6); + assert.equal(byId.parked.speedMps, null, 'no speed stays no speed'); + const szczecin = buildTransitSnapshot( + getTransitFeed('zditm-szczecin'), + encodeFeed({ entities: [{ id: 'm', lat: 53.43, lon: 14.55, speed: 10 }] }), + 1, + ); + assert.equal(szczecin.vehicles[0].speedMps, 10, 'm/s feeds are untouched'); +}); + test('conditional-request validators and gzip ride along with feed identification', () => { const entur = getTransitFeed('entur-norway'); const plain = transitUpstreamHeaders(entur); From 71b694ab6245dc91ec20562acd2394ba65c8edd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Itallo=20Brand=C3=A3o?= <45429643+IMBrandao@users.noreply.github.com> Date: Sun, 8 Nov 2026 02:50:32 -0300 Subject: [PATCH 34/61] feat(transit): add 32 more keyless cities across Europe, Asia, Oceania and North America MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prague, Warsaw, Kraków (buses and trams), Poznań, Gdańsk, Rzeszów, Vilnius, Bucharest, Cluj-Napoca, Iași, Rome, Turin, Venice (buses and waterbuses), Bordeaux, Montpellier, Rouen, Toulon, Le Havre, Tours, Málaga, Lisbon's city Carris, Sendai, Johor Bahru, Kota Bharu, Adelaide, Atlanta, Denver, Edmonton, Halifax and Victoria. Each entry records its licence, or that none is stated and the Metro Transit/OVapi basis it ships on. Montpellier and Toulon publish km/h and are converted. Route ids are read as the rider-facing line; Prague, Bordeaux and Le Havre trams and Venice waterbuses take their own mode. Adelaide needs `Accept: */*` to get binary protobuf. Every feed was fetched through the dev proxy on 2026-11-08. Co-Authored-By: Claude Opus 5.5 --- DATA_SOURCES.md | 34 +- README.md | 2 +- changelog.d/szczecin-lisbon-transit.md | 6 - changelog.d/transit-more-cities.md | 11 + docs/CURRENT-STATE.md | 4 +- src/data/transitFeeds.js | 636 +++++++++++++++++++++++++ src/data/transitFeeds.test.mjs | 108 +++++ src/data/transitProxy.test.mjs | 10 + 8 files changed, 801 insertions(+), 10 deletions(-) delete mode 100644 changelog.d/szczecin-lisbon-transit.md create mode 100644 changelog.d/transit-more-cities.md diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 2dc33dad5d..5ef902c0ce 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -101,6 +101,38 @@ How to read this: | **SMTR Rio de Janeiro** (dados.mobilidade.rio) | Transit layer live vehicles, Rio de Janeiro: municipal buses (SPPO) and the Mobi-Rio BRT, as two feeds | CC BY 4.0, stated on both data.rio catalog pages. Keyless GTFS-Realtime published by the Secretaria Municipal de Transportes, labelled beta, with a gateway limit of 5 requests a second and 60 a minute. Line names come from SMTR’s GTFS `routes.txt` (dados.mobilidade.rio/gtfs/schedule), under the same licence. | Attribution to SMTR / Prefeitura da Cidade do Rio de Janeiro under CC BY 4.0 | | **ZDiTM Szczecin** (zditm.szczecin.pl) | Transit layer live vehicles, Szczecin, Poland: buses and trams as one feed | CC0 1.0, stated on the ZDiTM developer page: “The data are provided free of charge under the CC0 1.0 licence, for use in any context, with no prior notification required.” Keyless GTFS-Realtime; the page says one update a minute, measured at about every 20 seconds. The feed carries no route id, so every vehicle takes the default bus mode. | None required (CC0); credited to ZDiTM Szczecin as a courtesy | | **Carris Metropolitana** (api.carrismetropolitana.pt) | Transit layer live vehicles, Lisbon Metropolitan Area, Portugal | Keyless GTFS-Realtime documented in the operator’s public API repository (github.com/carrismetropolitana/api). No licence is stated for the realtime endpoint; the operator’s static GTFS is CC BY 4.0. Included on the same basis as the Metro Transit and OVapi feeds and credited as a courtesy; it can be switched off if Carris objects. Speeds are published in km/h and converted to m/s by the proxy. Route ids are read as the line number per the operator’s `/v2/routes`. | Courtesy credit to Carris Metropolitana | +| **Prague PID** (api.golemio.cz) | Transit layer live vehicles, Prague and Central Bohemia, Czechia | CC BY (https://pid.cz/o-systemu/opendata/). Stated: “Data, která lze stáhnout přímo zde z webu, jsou stejně jako celý obsah webu opatřena licencí CC-BY” The PID open-data page lists this realtime feed and licenses the data it publishes under CC BY, crediting the author and any changes. The same page says data served from other sources follows that source’s licence; the feed is served by Golemio, the city’s data platform, which states none of its own. Keyless since the catalogue moved it off the X-Access-Token endpoint. Speeds are m/s, checked against movement on 2026-11-07. Route ids are `L` plus the line number; lines below 100 are trams. | Pražská integrovaná doprava (PID) / Golemio | +| **Warsaw buses and trams** (mkuran.pl) | Transit layer live vehicles, Warsaw, Poland | Warsaw Open Data Project Usage Terms (https://mkuran.pl/gtfs/). Stated: “The City Hall requires a credit by providing the name Miasto Stołeczne Warszawa, data download date (use the timestamp from the FeedHeader) and link to http://api.um.warszawa.pl.” Positions come from the Warsaw City Hall API, repackaged as GTFS-RT by Mikołaj Kuranowski’s unofficial feed. The credit names the city and its API; the download date it asks for is the feed timestamp the layer already shows with each snapshot. Vehicle timestamps ran about two minutes old on 2026-11-07, which the delayed playback absorbs. | Miasto Stołeczne Warszawa (api.um.warszawa.pl) | +| **Bordeaux TBM** (bdx.mecatran.com) | Transit layer live vehicles, Bordeaux, France | Licence Ouverte / Etalab 2.0 (https://transport.data.gouv.fr/datasets/offres-de-services-bus-tram-et-scolaire-au-format-gtfs-netex-gtfs-rt-siri-lite). The quote is the licence field of the national access point’s dataset record (fr-lo is the Licence Ouverte), which asks only for credit. The `apiKey` in the URL is not a credential: it is the same fixed string printed in the open-data listing for everyone. Speeds are m/s. Trams run on lettered lines A–D; numbered lines are buses. | Bordeaux Métropole (TBM) | +| **Sendai City Bus** (api-public.odpt.org) | Transit layer live vehicles, Sendai, Japan | CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Served by the Open Data Challenge for Public Transportation (ODPT) public API, which needs no key for this feed; the catalogue records CC BY 4.0 as its licence. Vehicle timestamps ran about two minutes old on 2026-11-07. Speeds are m/s. | 仙台市交通局 (Sendai City Transportation Bureau) / ODPT | +| **Poznań buses and trams** (ztm.poznan.pl) | Transit layer live vehicles, Poznań, Poland | ZTM Poznań open-data terms (https://www.ztm.poznan.pl/otwarte-dane/dla-deweloperow/). Stated: “Treści udostępniane są bezwnioskowo i bezpłatnie, na zasadach powszechnego dostępu i stanowią źródło informacji.” Reuse is free on three conditions: name the source, give the date of the last update, and say the data were processed. The credit names ZTM and says processed; the snapshot timestamp is the update date. The feed carries no bearing, so heading comes from movement between fixes. | Zarząd Transportu Miejskiego w Poznaniu (processed) | +| **Gdańsk buses and trams** (ckan2.multimediagdansk.pl) | Transit layer live vehicles, Gdańsk, Poland | CC BY 4.0 (https://dane.gov.pl/pl/dataset/38599,rozklady-jazdy-i-lokalizacja-przystankow-gtfs-rt). The national catalogue (dane.gov.pl) lists this dataset under CC BY 4.0. No bearing; heading comes from movement. Speeds are m/s. | Zarząd Transportu Miejskiego w Gdańsku | +| **Edmonton Transit Service** (gtfs.edmonton.ca) | Transit layer live vehicles, Edmonton, AB | City of Edmonton Open Data Agreement (https://www.edmonton.ca/transportation/Web-version2.1-OpenDataAgreement.pdf). The agreement is the same municipal template as Mississauga and Burlington: a licence to use, modify and distribute for any lawful purpose, in any medium. It was read from search excerpts; the PDF itself would not extract here. Route ids are zero-padded. Speeds are m/s. | Contains information licensed under the Open Data Agreement – City of Edmonton | +| **Halifax Transit** (gtfs.halifax.ca) | Transit layer live vehicles, Halifax, NS | Halifax Open Data Licence (https://www.halifax.ca/home/open-data/open-data-licence). The catalogue points at Halifax’s open-data licence; the licence page renders only in a browser and was not quoted. Speeds are m/s. | Halifax Regional Municipality (Halifax Transit) | +| **Victoria Regional Transit** (bct.tmix.se) | Transit layer live vehicles, Victoria, BC | BC Transit Open Data Terms of Use (https://www.bctransit.com/open-data/terms-of-use). Stated: “BC Transit grants you a limited, revocable and non-exclusive license to use, reproduce, and redistribute the Data in accordance with these Terms.” The grant is revocable, like the Ontario municipal templates. Route ids carry a `-VIC` system suffix. Speeds are m/s. | BC Transit | +| **Montpellier TaM** (gtfsproxy.e-tam.fr) | Transit layer live vehicles, Montpellier, France | ODbL (https://transport.data.gouv.fr/datasets/offre-de-transport-tam-en-temps-reel-gtfs-rt-urbain-et-suburbain). The quote is the dataset record’s licence field. ODbL asks for credit and share-alike on a derived database; the layer redistributes no database, it draws the positions. Speeds are km/h: readings ran 3.3 times the measured movement on 2026-11-07, so the proxy converts them. | Montpellier Méditerranée Métropole (TaM) | +| **Kraków buses** (gtfs.ztp.krakow.pl) | Transit layer live vehicles, Kraków, Poland | No licence stated (https://gtfs.ztp.krakow.pl/). ZTP publishes this feed keyless on its own GTFS server and lists it in the Mobility Database, but states no licence there or on dane.gov.pl. Shipped on the same basis as Metro Transit and OVapi; switch it off if ZTP objects. | Zarząd Transportu Publicznego w Krakowie | +| **Kraków trams** (gtfs.ztp.krakow.pl) | Transit layer live vehicles, Kraków, Poland | No licence stated (https://gtfs.ztp.krakow.pl/). Same server and basis as the bus feed. | Zarząd Transportu Publicznego w Krakowie | +| **Vilnius public transport** (stops.lt) | Transit layer live vehicles, Vilnius, Lithuania | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2383). Published keyless by the city transport agency on stops.lt; no licence found. Shipped on the same basis as Metro Transit and OVapi. Answered 522 once on 2026-11-07 and normally since. | SĮ Susisiekimo paslaugos (stops.lt) | +| **Bucharest public transport** (gtfs.tpbi.ro) | Transit layer live vehicles, Bucharest, Romania | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2104). Keyless public endpoint from the metropolitan transport authority; no licence found. Same basis as Metro Transit and OVapi. | TPBI (Transport Public București–Ilfov) | +| **Rome public transport** (romamobilita.it) | Transit layer live vehicles, Rome, Italy | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-1776). Keyless file on the agency’s own site; the catalogue’s older `/sites/default/files/` path now 404s. No licence found; same basis as Metro Transit and OVapi. Fewer than one vehicle in five carries a bearing, so most headings come from movement. | Roma Servizi per la Mobilità | +| **Turin GTT** (percorsieorari.gtt.to.it) | Transit layer live vehicles, Turin, Italy | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2696). Official keyless endpoint; no licence found. Same basis as Metro Transit and OVapi. Route ids append `U` for urban lines. | Gruppo Torinese Trasporti (GTT) | +| **Venice ACTV buses** (tpl.actv.it) | Transit layer live vehicles, Venice, Italy | ACTV open-data catalogue (https://actv.avmspa.it/it/content/catalogo-dei-dati-metadati-e-banche-dati-actv). ACTV lists this feed in its own open-data catalogue; that page would not render for a script, so its licence is not quoted. Same basis as Metro Transit and OVapi. Route ids append a two-letter network code (`_UM`, `_ES`, `_UN`). | ACTV S.p.A. | +| **Venice ACTV waterbuses** (tpl.actv.it) | Transit layer live vehicles, Venice, Italy | ACTV open-data catalogue (https://actv.avmspa.it/it/content/catalogo-dei-dati-metadati-e-banche-dati-actv). Same catalogue and basis as the ACTV bus feed. | ACTV S.p.A. | +| **Adelaide Metro** (gtfs.adelaidemetro.com.au) | Transit layer live vehicles, Adelaide, SA | No licence stated for the realtime feed (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-1772). Official keyless endpoint; the state catalogue page refused automated reads, so no licence is quoted. Same basis as Metro Transit and OVapi. Speeds are m/s. The server picks its encoding from Accept, hence the override. | Adelaide Metro | +| **MARTA buses** (gtfs-rt.itsmarta.com) | Transit layer live vehicles, Atlanta, GA | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-1601). Official keyless endpoint; no licence found. Same basis as Metro Transit and OVapi. Speeds are m/s. | MARTA | +| **Denver RTD** (open-data.rtd-denver.com) | Transit layer live vehicles, Denver, CO | RTD GTFS-realtime licence agreement (https://www.rtd-denver.com/business-center/open-spatial-data/gtfs-realtime-license-agreement). RTD links a licence agreement for its realtime feeds; the page refused automated reads (403), so it is not quoted. The feed itself is keyless. Speeds are m/s. | Regional Transportation District (RTD) | +| **Cluj-Napoca CTP** (cluj-rt-feed.gtfs.ro) | Transit layer live vehicles, Cluj-Napoca, Romania | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2614). Keyless; no licence found. Same basis as Metro Transit and OVapi. | Compania de Transport Public Cluj-Napoca | +| **Iași CTP** (iasi-rt-feed.gtfs.ro) | Transit layer live vehicles, Iași, Romania | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2118). Keyless; no licence found. Same basis as Metro Transit and OVapi. | Compania de Transport Public Iași | +| **Rzeszów city transport** (mpkrzeszow.pl) | Transit layer live vehicles, Rzeszów, Poland | MPK Rzeszów open data (https://www.mpkrzeszow.pl/otwartedane/). Listed on the operator’s open-data page, which names no licence. No bearing; heading comes from movement. | MPK Rzeszów | +| **Málaga EMT** (gtfs.emtmalaga.es) | Transit layer live vehicles, Málaga, Spain | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2213). Keyless; no licence found. Same basis as Metro Transit and OVapi. No bearing; heading comes from movement. | EMT Málaga | +| **Carris (Lisbon city)** (gateway.carris.pt) | Transit layer live vehicles, Lisbon, Portugal | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2930). Keyless official gateway; no licence found. Same basis as Metro Transit and OVapi. Carries neither bearing nor speed, and vehicle reports run about a minute old. Route ids append a variant. | Carris | +| **BAS.MY Johor Bahru** (api.data.gov.my) | Transit layer live vehicles, Johor Bahru, Malaysia | No licence stated for the feed (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-3174). Served keyless by Malaysia’s national open-data API; no licence for the feed was found. Same basis as Metro Transit and OVapi. Without the trailing slash the API redirects. Route ids append an operator code. | BAS.MY / data.gov.my | +| **BAS.MY Kota Bharu** (api.data.gov.my) | Transit layer live vehicles, Kota Bharu, Malaysia | No licence stated for the feed (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-3169). Same API and basis as Johor Bahru. | BAS.MY / data.gov.my | +| **Rouen Astuce** (gtfs.bus-tracker.fr) | Transit layer live vehicles, Rouen, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/donnees-statiques-et-temps-reel-du-reseau-astuce-metropole-rouen-normandie). The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); this registry reads it through bus-tracker.fr, an unofficial relay that merges the city’s networks into one GTFS-RT file. Route ids carry the network prefix (`TCAR:`). | Métropole Rouen Normandie (Astuce) / bus-tracker.fr | +| **Toulon Mistral** (feed-rdtpm-toulon.ratpdev.com) | Transit layer live vehicles, Toulon, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/reseau-de-transport-urbain-de-la-metropole-toulon-provence-mediterranee). Dataset record’s licence field quoted. Speeds are km/h: readings ran 3.5 times the measured movement on 2026-11-07, so the proxy converts them. Route ids are zero-padded. | Métropole Toulon Provence Méditerranée (Mistral) | +| **Le Havre LiA** (gtfs.bus-tracker.fr) | Transit layer live vehicles, Le Havre, France | ODbL (https://transport.data.gouv.fr/datasets/reseau-de-transport-en-commun-lia-gtfs-siri). The network publishes under ODbL (dataset record quoted); read through the bus-tracker.fr relay, which converts its SIRI feed to GTFS-RT. The layer draws positions and redistributes no database. Lines A and B are the tramway. | Le Havre Seine Métropole (LiA) / bus-tracker.fr | +| **Tours Fil Bleu** (data.filbleu.fr) | Transit layer live vehicles, Tours, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/fil-bleu-syndicat-des-mobilites-gtfs-gtfs-rt). Dataset record’s licence field quoted. | Fil Bleu – Syndicat des Mobilités de Touraine | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | | **OpenSeaMap** (`tiles.openseamap.org`) | Sea Marks layer: raster overlay of buoys, lighthouses and ports (#10) | Chart tiles CC BY-SA 2.0; data ODbL 1.0 via OpenStreetMap | "Sea marks © OpenSeaMap contributors (CC BY-SA 2.0) · Data © OpenStreetMap contributors (ODbL)" | @@ -188,7 +220,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **Houston TranStar cameras.** Keyless. The camera list is the public `traffic.houstontranstar.org/data/layers/cctvSnapshots_json.js` catalog (~1,000 cameras across Greater Houston); frames are stills at `www.houstontranstar.org/snapshots/cctv/.jpg`, synthesized from a validated numeric id rather than taken from the payload, and only that host is registered. Cameras whose catalog id is `0` (a different, non-snapshot class) and cameras outside Greater Houston are dropped. TranStar's `dir` field is the side of the freeway the camera sits on, not the way it faces: TranStar's own map shows it as "Traffic closest to the camera is traveling …" (South → eastbound, North → westbound, West → southbound, East → northbound). That travel direction (90°, 270°, 180°, 0°) seeds the heading as a low-confidence prior with the low-confidence pose; `None` or an unknown value uses the shared id-hash fallback at low confidence. Headings are corrected with the in-app calibration gizmo. Off by default. TranStar's [Content Usage terms](https://traffic.houstontranstar.org/disclaimer.aspx) prohibit copying or distributing the site's information, and external framing or linking to specific images, without TxDOT's prior written permission; its FAQ grants permission-free use only for the RSS feeds. This project does not hold that permission for downstream installations, so the pack loads only when an operator who holds TxDOT's written permission sets `CCTV_HOUSTON_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to TranStar. Once enabled, it loads the 250 cameras nearest downtown, Uptown, the Medical Center, IAH and Galveston; `CCTV_HOUSTON_MAX_SOURCES` (8–400) changes the cap. Snapshots update about every 3 minutes, which is also the ambient still cadence. Frames are fetched from TranStar and relayed to the browser on demand, buffered only transiently per request, sent with `Cache-Control: no-store`, and not archived. - **Autostrada del Brennero (A22) webcams.** Keyless. The camera list is one request to the Open Data Hub tourism API (`tourism.api.opendatahub.com/v1/WebcamInfo?source=a22`), run by NOI Techpark in South Tyrol, which republishes Autobrennero's own list of 13 motorway webcams with coordinates and kilometre markers. Frames are the operator's stills on `www.autobrennero.it/WebCamImg/km.jpg`, refreshed about once a minute, and only the exact image for each camera's kilometre is registered. The feed names no bearing, so headings use the id-hash fallback at low confidence. The road climbs from about 20 m in the Po valley to about 1,370 m at the Brenner Pass, so each camera's ground elevation comes from a per-kilometre table sampled from the Copernicus GLO-90 DEM (via Open-Meteo's elevation API); a camera not in the table uses a 200 m prior. The Open Data Hub tags every record CC0 (`ClosedData: false`, Autobrennero as licence holder), but that tag is the aggregator's metadata and Autobrennero publishes no terms of its own for the images, so they are credited to the operator as a courtesy and are not redistributed. Frames are fetched at request time and never stored. Disable with `CCTV_A22_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All twenty registered feeds, covering nineteen regions, are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington, YRT and Rio’s SMTR publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All fifty-two registered feeds, covering forty-nine regions, are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington, YRT and Rio’s SMTR publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for. - **Radio country coverage (optional).** Set `RADIO_PRIORITY_COUNTRIES=IN,PL` in the local `.env` and restart to include stations beyond the global click charts. The operator may choose up to eight unique ISO alpha-2 country codes; no key is needed. Each country adds one bounded query (at most 200 rows) and reserves up to 40 unique, usable stations inside the existing 750-station catalog. Country seeds precede specialist-tag seeds and global popularity fill; unused slots return to the shared pool. This is a coverage preference, not an exhaustive national directory or a guarantee of stations in every city. Countries with no eligible HTTPS MP3/AAC geolocated stations remain empty. An unset list preserves global selection. Country requests share the directory cache and three-worker pool; failed country queries are reported in coverage without blocking a healthy global refresh. Failed/degraded refreshes back off for one minute, with at most three mirrors per query. - **Radio Browser.** In every installation, including when `RADIO_PRIORITY_COUNTRIES` is unset, each request tries at most three mirror candidates (later fallback candidates are skipped), and failed or partial catalog refreshes back off for 60 seconds. A cold-start failure therefore continues returning 503 during that delay even if upstream recovers. `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; broad/specialist responses whose rows all fail the product's health policy do not count as successful queries. Optional priority-country outcomes are advisory: valid, in-limit responses with no eligible stations succeed as empty results, while failed or malformed country queries report unsuccessful coverage without degrading the global catalog. A usable partial cold catalog is explicitly `DEGRADED`, and non-array or empty broad/specialist payloads are rejected atomically. Individual structurally malformed rows are skipped rather than failing the whole query; the response carries their bounded `rejectedStationCount` (at most 10,000), which the client adds to its own rejected rows and reports as degraded coverage without discarding the accepted generation. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. diff --git a/README.md b/README.md index fff61fd9f4..f8b280c6df 100644 --- a/README.md +++ b/README.md @@ -444,7 +444,7 @@ Twenty-one layers and map sources. **Nineteen have a keyless path.** Some offer | 📷 **Mapped ALPR Cameras** | License-plate-reader camera locations tagged by OpenStreetMap contributors, loaded one city-sized view at a time, with **SHOW NEAREST**. Locations and tags only: no plate data, no video | OpenStreetMap (incl. DeFlock mapping) | 🟢 | | 📷 **Street Level** | Street-level photos behind one panel, one chip per provider: coverage on the streets, image cones, an embedded viewer with full-screen **EXPAND**. Mapillary, Google Street View, KartaView and Panoramax | Mapillary · Google · KartaView · Panoramax | 🟢 KartaView, Panoramax · 🟡 Mapillary token · 🔴 Google Maps key | | 📻 **Radio** | Geolocated world radio with an **analog tuner** — drag the needle across up to 750 stations and the globe flies to each broadcaster | Radio Browser / broadcasters | 🟢 | -| 🚌 **Transit** | Live buses, trams, metros, trains and ferries with delayed playback between reports, selected-vehicle trails, and mode-coloured DETECT labels — Boston, Austin, Minneapolis, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro (buses and BRT), Szczecin, Lisbon, and nine in Ontario: Toronto (surface vehicles; the subway publishes no positions), Mississauga, Hamilton, Durham Region, York Region, Guelph, Burlington, Barrie and Kingston | Operator GTFS-Realtime feeds | 🟢 | +| 🚌 **Transit** | Live buses, trams, metros, trains and ferries with delayed playback between reports, selected-vehicle trails, and mode-coloured DETECT labels — Boston, Austin, Minneapolis, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro (buses and BRT), Szczecin, Lisbon (Carris Metropolitana and the city’s Carris), Prague, Warsaw, Kraków, Poznań, Gdańsk, Rzeszów, Vilnius, Bucharest, Cluj-Napoca, Iași, Rome, Turin, Venice (buses and waterbuses), Bordeaux, Montpellier, Rouen, Toulon, Le Havre, Tours, Málaga, Sendai, Johor Bahru, Kota Bharu, Adelaide, Atlanta, Denver, Edmonton, Halifax, Victoria, and nine in Ontario: Toronto (surface vehicles; the subway publishes no positions), Mississauga, Hamilton, Durham Region, York Region, Guelph, Burlington, Barrie and Kingston | Operator GTFS-Realtime feeds | 🟢 | | 🚲 **Bikeshare** | Live station availability | GBFS | 🟢 | | 🧭 **Directions** | Click A and B on the globe for a street-following drive, walk or cycle route draped on the terrain with turn-by-turn steps — then FLY the camera along it. No key, no geocoder, no mic | OSRM on FOSSGIS servers (OpenStreetMap) | 🟢 | | ⌖ **OSM Places** | Voice place search ("hospitals in Kathmandu") from OpenStreetMap, drawn as numbered points that follow-up questions can filter. Needs your own Overpass server (`OVERPASS_UPSTREAMS`); off otherwise | diff --git a/changelog.d/szczecin-lisbon-transit.md b/changelog.d/szczecin-lisbon-transit.md deleted file mode 100644 index 103657e8fd..0000000000 --- a/changelog.d/szczecin-lisbon-transit.md +++ /dev/null @@ -1,6 +0,0 @@ -- Add Szczecin, Poland and the Lisbon Metropolitan Area to the Transit layer. - Szczecin's buses and trams come from ZDiTM's keyless feed under CC0 1.0; it - carries no route ids, so vehicles show as buses. Lisbon's buses come from - Carris Metropolitana's keyless feed, which states no licence of its own and - is credited as a courtesy like Metro Transit and OVapi; its km/h speeds are - converted to m/s and its route ids read as the line number (IMBrandao). diff --git a/changelog.d/transit-more-cities.md b/changelog.d/transit-more-cities.md new file mode 100644 index 0000000000..3e72ebebb7 --- /dev/null +++ b/changelog.d/transit-more-cities.md @@ -0,0 +1,11 @@ +- Add 34 keyless feeds to the Transit layer, the first in Central and Eastern + Europe, Italy, Spain, France, Japan and Malaysia: Szczecin, Lisbon (Carris + Metropolitana and the city's Carris), Prague, Warsaw, Kraków, Poznań, + Gdańsk, Rzeszów, Vilnius, Bucharest, Cluj-Napoca, Iași, Rome, Turin, Venice + (buses and waterbuses), Bordeaux, Montpellier, Rouen, Toulon, Le Havre, + Tours, Málaga, Sendai, Johor Bahru, Kota Bharu, Adelaide, Atlanta, Denver, + Edmonton, Halifax and Victoria. Each feed records its licence, or that none + is stated, in the registry and DATA_SOURCES.md. Speeds published in km/h + (Lisbon, Montpellier, Toulon) are converted to m/s by the proxy; route ids + read as the line on the vehicle; Prague, Bordeaux and Le Havre trams and + Venice waterbuses take their own mode (IMBrandao). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index b5820c6b5c..f9f1f8d302 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4644,9 +4644,9 @@ Transit is off by default, and share links use token `j`. The movement panel ord places Transit directly after Street Traffic and before Bike Share. Cameras and utilities retain their own groups. The layer polls registered feeds near the camera every 15 seconds, below a 3,000 km altitude -gate. Nineteen keyless regions are available: Boston, Austin, Minneapolis–St Paul, +gate. Forty-nine keyless regions are available: Boston, Austin, Minneapolis–St Paul, Helsinki, the Netherlands, Norway, South East Queensland, Rio de Janeiro -(municipal buses and the Mobi-Rio BRT, two feeds), Szczecin, the Lisbon Metropolitan Area, and nine in +(municipal buses and the Mobi-Rio BRT, two feeds), Szczecin, the Lisbon Metropolitan Area and the city of Lisbon, Prague and Central Bohemia, Warsaw, Kraków (buses and trams, two feeds), Poznań, Gdańsk, Rzeszów, Vilnius, Bucharest, Cluj-Napoca, Iași, Rome, Turin, Venice (buses and waterbuses, two feeds), Bordeaux, Montpellier, Rouen, Toulon, Le Havre, Tours, Málaga, Sendai, Johor Bahru, Kota Bharu, Adelaide, Atlanta, Denver, Edmonton, Halifax, Victoria, and nine in Ontario — Toronto (TTC surface vehicles; the subway publishes no positions), MiWay, Hamilton HSR, Durham Region, YRT/Viva, Guelph, Burlington, Barrie and Kingston. Mode silhouettes diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 7515b84171..5ac28d5dad 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -402,6 +402,86 @@ function carrisMetropolitanaRouteLabel(routeId) { return match ? match[1] : routeId; } +/** + * Route ids that wrap the rider-facing line in a fixed prefix, suffix or + * zero-padding. The returned function yields the captured line, or the id + * unchanged when it does not match the operator's pattern. + * @param {RegExp} pattern One capture group: the line a rider would say. + * @returns {(routeId: string|null) => string|null} + */ +function routeIdPattern(pattern) { + return (routeId) => { + const match = pattern.exec(routeId ?? ''); + return match ? match[1] : routeId; + }; +} + +/** Prague PID: `L125` is line 125. */ +const pidRouteLabel = routeIdPattern(/^L(\d+)$/); +/** Zero-padded numbers (Edmonton `005`, Toulon `0002`, Bordeaux `01`). */ +const unpaddedRouteLabel = routeIdPattern(/^0+(\d+\w*)$/); +/** Turin GTT appends `U` (urban) to the line: `10NU` is night line 10N. */ +const gttRouteLabel = routeIdPattern(/^(\w+?)U$/); +/** Venice ACTV appends the network: `5.1_UN` is waterbus line 5.1, `53E_ES` bus 53E. */ +const actvRouteLabel = routeIdPattern(/^(.+)_[A-Z]{2}$/); +/** BC Transit appends the system: `95-VIC` is Victoria route 95. */ +const bcTransitRouteLabel = routeIdPattern(/^(.+)-VIC$/); +/** Carris (Lisbon city) appends a variant: `172_1` is route 172. */ +const carrisRouteLabel = routeIdPattern(/^(\w+)_\d+$/); +/** bus-tracker.fr prefixes the network: `TCAR:93` is Rouen line 93. */ +const busTrackerRouteLabel = routeIdPattern(/^[A-Z]+:(.+)$/); +/** BAS.MY Johor appends a fixed operator code: `J33CWLMYJB` is route J33. */ +const mybasJohorRouteLabel = routeIdPattern(/^(.+?)CWLMYJB$/); + +/** + * Le Havre LiA runs its two tram lines as A and B; every other line is a bus. + * @param {string|null} routeId + * @returns {string} + */ +function liaRouteMode(routeId) { + if (!routeId) return 'unknown'; + return /^(?:[A-Z]+:)?[AB]$/.test(routeId) ? 'tram' : 'bus'; +} + +/** + * Prague PID numbers its day and night trams below 100 and its buses from 100 + * up; anything else (rail, ferries, the funicular) is left unresolved. + * @param {string|null} routeId + * @returns {string} + */ +function pidRouteMode(routeId) { + const match = /^L(\d+)$/.exec(routeId ?? ''); + if (!match) return 'unknown'; + return Number(match[1]) < 100 ? 'tram' : 'bus'; +} + +/** + * Bordeaux TBM runs trams on lettered lines A–D; every numbered line is a bus. + * @param {string|null} routeId + * @returns {string} + */ +function tbmRouteMode(routeId) { + if (!routeId) return 'unknown'; + return /^[A-D]$/.test(routeId) ? 'tram' : 'bus'; +} + +/** + * A registry entry, frozen with its centre and terms, and switched on. + * @param {object} fields + * @returns {Readonly} + */ +function transitFeed(fields) { + return Object.freeze({ + defaultEnabled: true, + ...fields, + center: Object.freeze({ ...fields.center }), + terms: Object.freeze({ ...fields.terms }), + ...(fields.headers + ? { headers: Object.freeze({ ...fields.headers }) } + : {}), + }); +} + /** * Registry of feeds. Order is presentation order in the stats/credit text. * `loadRadiusKm` is the distance from `center` inside which the feed is polled. @@ -850,6 +930,562 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ routeLabel: carrisMetropolitanaRouteLabel, speedUnit: 'km/h', }), + transitFeed({ + id: 'pid-praha', + name: 'Prague PID', + operator: 'Pražská integrovaná doprava (PID), via Golemio', + region: 'Prague and Central Bohemia, Czechia', + // PID reaches across Central Bohemia: on 2026-11-08, 95% of 923 vehicles + // sat within 58 km of Prague, the farthest at 98 km. + center: { lat: 50.08, lon: 14.45 }, + loadRadiusKm: 60, + url: 'https://api.golemio.cz/v2/vehiclepositions/gtfsrt/vehicle_positions.pb', + license: 'CC BY', + licenseUrl: 'https://pid.cz/o-systemu/opendata/', + attribution: 'Pražská integrovaná doprava (PID) / Golemio', + terms: { + quote: + 'Data, která lze stáhnout přímo zde z webu, jsou stejně jako celý obsah webu opatřena licencí CC-BY', + note: 'The PID open-data page lists this realtime feed and licenses the data it publishes under CC BY, crediting the author and any changes. The same page says data served from other sources follows that source’s licence; the feed is served by Golemio, the city’s data platform, which states none of its own. Keyless since the catalogue moved it off the X-Access-Token endpoint. Speeds are m/s, checked against movement on 2026-11-07. Route ids are `L` plus the line number; lines below 100 are trams.', + }, + defaultMode: 'bus', + routeLabel: pidRouteLabel, + routeMode: pidRouteMode, + }), + transitFeed({ + id: 'ztm-warszawa', + name: 'Warsaw buses and trams', + operator: 'Miasto Stołeczne Warszawa, relayed by mkuran.pl', + region: 'Warsaw, Poland', + center: { lat: 52.25, lon: 21.02 }, + loadRadiusKm: 30, + url: 'https://mkuran.pl/gtfs/warsaw/vehicles.pb', + license: 'Warsaw Open Data Project Usage Terms', + licenseUrl: 'https://mkuran.pl/gtfs/', + attribution: 'Miasto Stołeczne Warszawa (api.um.warszawa.pl)', + terms: { + quote: + 'The City Hall requires a credit by providing the name Miasto Stołeczne Warszawa, data download date (use the timestamp from the FeedHeader) and link to http://api.um.warszawa.pl.', + note: 'Positions come from the Warsaw City Hall API, repackaged as GTFS-RT by Mikołaj Kuranowski’s unofficial feed. The credit names the city and its API; the download date it asks for is the feed timestamp the layer already shows with each snapshot. Vehicle timestamps ran about two minutes old on 2026-11-07, which the delayed playback absorbs.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'tbm-bordeaux', + name: 'Bordeaux TBM', + operator: 'Transports Bordeaux Métropole (TBM), Bordeaux Métropole', + region: 'Bordeaux, France', + center: { lat: 44.85, lon: -0.65 }, + loadRadiusKm: 20, + url: 'https://bdx.mecatran.com/utw/ws/gtfsfeed/vehicles/bordeaux?apiKey=opendata-bordeaux-metropole-flux-gtfs-rt', + license: 'Licence Ouverte / Etalab 2.0', + licenseUrl: + 'https://transport.data.gouv.fr/datasets/offres-de-services-bus-tram-et-scolaire-au-format-gtfs-netex-gtfs-rt-siri-lite', + attribution: 'Bordeaux Métropole (TBM)', + terms: { + quote: 'licence: fr-lo', + note: 'The quote is the licence field of the national access point’s dataset record (fr-lo is the Licence Ouverte), which asks only for credit. The `apiKey` in the URL is not a credential: it is the same fixed string printed in the open-data listing for everyone. Speeds are m/s. Trams run on lettered lines A–D; numbered lines are buses.', + }, + defaultMode: 'bus', + routeLabel: unpaddedRouteLabel, + routeMode: tbmRouteMode, + }), + transitFeed({ + id: 'sendai-city-bus', + name: 'Sendai City Bus', + operator: 'Sendai City Transportation Bureau (仙台市交通局), via ODPT', + region: 'Sendai, Japan', + center: { lat: 38.27, lon: 140.82 }, + loadRadiusKm: 22, + url: 'https://api-public.odpt.org/api/v4/gtfs/realtime/odpt_SendaiMunicipal_bus_realtime_information_vehicle', + license: 'CC BY 4.0', + licenseUrl: 'https://creativecommons.org/licenses/by/4.0/', + attribution: '仙台市交通局 (Sendai City Transportation Bureau) / ODPT', + terms: { + quote: 'https://creativecommons.org/licenses/by/4.0/', + note: 'Served by the Open Data Challenge for Public Transportation (ODPT) public API, which needs no key for this feed; the catalogue records CC BY 4.0 as its licence. Vehicle timestamps ran about two minutes old on 2026-11-07. Speeds are m/s.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'ztm-poznan', + name: 'Poznań buses and trams', + operator: 'Zarząd Transportu Miejskiego w Poznaniu (ZTM Poznań)', + region: 'Poznań, Poland', + center: { lat: 52.39, lon: 16.92 }, + loadRadiusKm: 20, + url: 'https://www.ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile/?file=vehicle_positions.pb', + license: 'ZTM Poznań open-data terms', + licenseUrl: 'https://www.ztm.poznan.pl/otwarte-dane/dla-deweloperow/', + attribution: 'Zarząd Transportu Miejskiego w Poznaniu (processed)', + terms: { + quote: + 'Treści udostępniane są bezwnioskowo i bezpłatnie, na zasadach powszechnego dostępu i stanowią źródło informacji.', + note: 'Reuse is free on three conditions: name the source, give the date of the last update, and say the data were processed. The credit names ZTM and says processed; the snapshot timestamp is the update date. The feed carries no bearing, so heading comes from movement between fixes.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'ztm-gdansk', + name: 'Gdańsk buses and trams', + operator: 'Zarząd Transportu Miejskiego w Gdańsku (ZTM Gdańsk)', + region: 'Gdańsk, Poland', + center: { lat: 54.35, lon: 18.6 }, + loadRadiusKm: 20, + url: 'https://ckan2.multimediagdansk.pl/gtfs-rt?feed=vehiclePositions', + license: 'CC BY 4.0', + licenseUrl: + 'https://dane.gov.pl/pl/dataset/38599,rozklady-jazdy-i-lokalizacja-przystankow-gtfs-rt', + attribution: 'Zarząd Transportu Miejskiego w Gdańsku', + terms: { + note: 'The national catalogue (dane.gov.pl) lists this dataset under CC BY 4.0. No bearing; heading comes from movement. Speeds are m/s.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'ets-edmonton', + name: 'Edmonton Transit Service', + operator: 'City of Edmonton (Edmonton Transit Service)', + region: 'Edmonton, AB', + center: { lat: 53.53, lon: -113.52 }, + loadRadiusKm: 25, + url: 'https://gtfs.edmonton.ca/TMGTFSRealTimeWebService/Vehicle/VehiclePositions.pb', + license: 'City of Edmonton Open Data Agreement', + licenseUrl: + 'https://www.edmonton.ca/transportation/Web-version2.1-OpenDataAgreement.pdf', + attribution: + 'Contains information licensed under the Open Data Agreement – City of Edmonton', + terms: { + note: 'The agreement is the same municipal template as Mississauga and Burlington: a licence to use, modify and distribute for any lawful purpose, in any medium. It was read from search excerpts; the PDF itself would not extract here. Route ids are zero-padded. Speeds are m/s.', + }, + defaultMode: 'bus', + routeLabel: unpaddedRouteLabel, + }), + transitFeed({ + id: 'halifax-transit', + name: 'Halifax Transit', + operator: 'Halifax Regional Municipality (Halifax Transit)', + region: 'Halifax, NS', + center: { lat: 44.7, lon: -63.6 }, + loadRadiusKm: 22, + url: 'https://gtfs.halifax.ca/realtime/Vehicle/VehiclePositions.pb', + license: 'Halifax Open Data Licence', + licenseUrl: 'https://www.halifax.ca/home/open-data/open-data-licence', + attribution: 'Halifax Regional Municipality (Halifax Transit)', + terms: { + note: 'The catalogue points at Halifax’s open-data licence; the licence page renders only in a browser and was not quoted. Speeds are m/s.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'bc-transit-victoria', + name: 'Victoria Regional Transit', + operator: 'BC Transit (Victoria Regional Transit System)', + region: 'Victoria, BC', + center: { lat: 48.53, lon: -123.43 }, + loadRadiusKm: 28, + url: 'https://bct.tmix.se/gtfs-realtime/vehicleupdates.pb?operatorIds=48', + license: 'BC Transit Open Data Terms of Use', + licenseUrl: 'https://www.bctransit.com/open-data/terms-of-use', + attribution: 'BC Transit', + terms: { + quote: + 'BC Transit grants you a limited, revocable and non-exclusive license to use, reproduce, and redistribute the Data in accordance with these Terms.', + note: 'The grant is revocable, like the Ontario municipal templates. Route ids carry a `-VIC` system suffix. Speeds are m/s.', + }, + defaultMode: 'bus', + routeLabel: bcTransitRouteLabel, + }), + transitFeed({ + id: 'tam-montpellier', + name: 'Montpellier TaM', + operator: 'Montpellier Méditerranée Métropole (TaM)', + region: 'Montpellier, France', + center: { lat: 43.61, lon: 3.87 }, + loadRadiusKm: 20, + url: 'https://gtfsproxy.e-tam.fr/COMMON/VehiclePosition.pb', + license: 'ODbL', + licenseUrl: + 'https://transport.data.gouv.fr/datasets/offre-de-transport-tam-en-temps-reel-gtfs-rt-urbain-et-suburbain', + attribution: 'Montpellier Méditerranée Métropole (TaM)', + terms: { + quote: 'licence: odc-odbl', + note: 'The quote is the dataset record’s licence field. ODbL asks for credit and share-alike on a derived database; the layer redistributes no database, it draws the positions. Speeds are km/h: readings ran 3.3 times the measured movement on 2026-11-07, so the proxy converts them.', + }, + defaultMode: 'bus', + speedUnit: 'km/h', + }), + transitFeed({ + id: 'ztp-krakow-bus', + name: 'Kraków buses', + operator: 'Zarząd Transportu Publicznego w Krakowie (ZTP Kraków)', + region: 'Kraków, Poland', + center: { lat: 50.06, lon: 19.94 }, + loadRadiusKm: 22, + url: 'https://gtfs.ztp.krakow.pl/VehiclePositions_A.pb', + license: 'No licence stated', + licenseUrl: 'https://gtfs.ztp.krakow.pl/', + attribution: 'Zarząd Transportu Publicznego w Krakowie', + terms: { + note: 'ZTP publishes this feed keyless on its own GTFS server and lists it in the Mobility Database, but states no licence there or on dane.gov.pl. Shipped on the same basis as Metro Transit and OVapi; switch it off if ZTP objects.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'ztp-krakow-tram', + name: 'Kraków trams', + operator: 'Zarząd Transportu Publicznego w Krakowie (ZTP Kraków)', + region: 'Kraków, Poland', + center: { lat: 50.06, lon: 19.94 }, + loadRadiusKm: 22, + url: 'https://gtfs.ztp.krakow.pl/VehiclePositions_T.pb', + license: 'No licence stated', + licenseUrl: 'https://gtfs.ztp.krakow.pl/', + attribution: 'Zarząd Transportu Publicznego w Krakowie', + terms: { note: 'Same server and basis as the bus feed.' }, + defaultMode: 'tram', + }), + transitFeed({ + id: 'vilnius-transport', + name: 'Vilnius public transport', + operator: 'SĮ Susisiekimo paslaugos, Vilnius', + region: 'Vilnius, Lithuania', + center: { lat: 54.69, lon: 25.28 }, + loadRadiusKm: 20, + url: 'https://www.stops.lt/vilnius/vehicle_positions.pb', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2383', + attribution: 'SĮ Susisiekimo paslaugos (stops.lt)', + terms: { + note: 'Published keyless by the city transport agency on stops.lt; no licence found. Shipped on the same basis as Metro Transit and OVapi. Answered 522 once on 2026-11-07 and normally since.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'tpbi-bucuresti', + name: 'Bucharest public transport', + operator: 'Asociația de Dezvoltare Intercomunitară TPBI, Bucharest–Ilfov', + region: 'Bucharest, Romania', + center: { lat: 44.43, lon: 26.1 }, + loadRadiusKm: 25, + url: 'https://gtfs.tpbi.ro/api/gtfs-rt/vehiclePositions', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2104', + attribution: 'TPBI (Transport Public București–Ilfov)', + terms: { + note: 'Keyless public endpoint from the metropolitan transport authority; no licence found. Same basis as Metro Transit and OVapi.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'roma-mobilita', + name: 'Rome public transport', + operator: 'Roma Servizi per la Mobilità', + region: 'Rome, Italy', + center: { lat: 41.89, lon: 12.5 }, + loadRadiusKm: 35, + url: 'https://romamobilita.it/wp-content/uploads/shared/rome_rtgtfs_vehicle_positions_feed.pb', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-1776', + attribution: 'Roma Servizi per la Mobilità', + terms: { + note: 'Keyless file on the agency’s own site; the catalogue’s older `/sites/default/files/` path now 404s. No licence found; same basis as Metro Transit and OVapi. Fewer than one vehicle in five carries a bearing, so most headings come from movement.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'gtt-torino', + name: 'Turin GTT', + operator: 'Gruppo Torinese Trasporti (GTT)', + region: 'Turin, Italy', + center: { lat: 45.07, lon: 7.68 }, + loadRadiusKm: 20, + url: 'https://percorsieorari.gtt.to.it/das_gtfsrt/vehicle_position.aspx', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2696', + attribution: 'Gruppo Torinese Trasporti (GTT)', + terms: { + note: 'Official keyless endpoint; no licence found. Same basis as Metro Transit and OVapi. Route ids append `U` for urban lines.', + }, + defaultMode: 'bus', + routeLabel: gttRouteLabel, + }), + transitFeed({ + id: 'actv-venezia-bus', + name: 'Venice ACTV buses', + operator: 'Azienda del Consorzio Trasporti Veneziano (ACTV)', + region: 'Venice, Italy', + center: { lat: 45.4, lon: 12.2 }, + loadRadiusKm: 38, + url: 'https://tpl.actv.it/aut/GTFSRT/vehiclePositions', + license: 'ACTV open-data catalogue', + licenseUrl: + 'https://actv.avmspa.it/it/content/catalogo-dei-dati-metadati-e-banche-dati-actv', + attribution: 'ACTV S.p.A.', + terms: { + note: 'ACTV lists this feed in its own open-data catalogue; that page would not render for a script, so its licence is not quoted. Same basis as Metro Transit and OVapi. Route ids append a two-letter network code (`_UM`, `_ES`, `_UN`).', + }, + defaultMode: 'bus', + routeLabel: actvRouteLabel, + }), + transitFeed({ + id: 'actv-venezia-waterbus', + name: 'Venice ACTV waterbuses', + operator: 'Azienda del Consorzio Trasporti Veneziano (ACTV) Navigazione', + region: 'Venice, Italy', + center: { lat: 45.43, lon: 12.33 }, + loadRadiusKm: 15, + url: 'https://tpl.actv.it/nav/GTFSRT/vehiclePositions', + license: 'ACTV open-data catalogue', + licenseUrl: + 'https://actv.avmspa.it/it/content/catalogo-dei-dati-metadati-e-banche-dati-actv', + attribution: 'ACTV S.p.A.', + terms: { note: 'Same catalogue and basis as the ACTV bus feed.' }, + defaultMode: 'ferry', + routeLabel: actvRouteLabel, + }), + transitFeed({ + id: 'adelaide-metro', + name: 'Adelaide Metro', + operator: 'Adelaide Metro (Government of South Australia)', + region: 'Adelaide, SA', + center: { lat: -34.93, lon: 138.6 }, + loadRadiusKm: 35, + url: 'https://gtfs.adelaidemetro.com.au/v1/realtime/vehicle_positions', + // Any Accept naming a protobuf type gets base64 text labelled JSON; only + // */* returns the binary feed (checked 2026-11-08). + headers: { Accept: '*/*' }, + license: 'No licence stated for the realtime feed', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-1772', + attribution: 'Adelaide Metro', + terms: { + note: 'Official keyless endpoint; the state catalogue page refused automated reads, so no licence is quoted. Same basis as Metro Transit and OVapi. Speeds are m/s. The server picks its encoding from Accept, hence the override.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'marta-atlanta', + name: 'MARTA buses', + operator: 'Metropolitan Atlanta Rapid Transit Authority (MARTA)', + region: 'Atlanta, GA', + center: { lat: 33.78, lon: -84.39 }, + loadRadiusKm: 35, + url: 'https://gtfs-rt.itsmarta.com/TMGTFSRealTimeWebService/vehicle/vehiclepositions.pb', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-1601', + attribution: 'MARTA', + terms: { + note: 'Official keyless endpoint; no licence found. Same basis as Metro Transit and OVapi. Speeds are m/s.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'rtd-denver', + name: 'Denver RTD', + operator: 'Regional Transportation District (RTD), Denver', + region: 'Denver, CO', + center: { lat: 39.75, lon: -104.99 }, + loadRadiusKm: 55, + url: 'https://open-data.rtd-denver.com/files/gtfs-rt/rtd/VehiclePosition.pb', + license: 'RTD GTFS-realtime licence agreement', + licenseUrl: + 'https://www.rtd-denver.com/business-center/open-spatial-data/gtfs-realtime-license-agreement', + attribution: 'Regional Transportation District (RTD)', + terms: { + note: 'RTD links a licence agreement for its realtime feeds; the page refused automated reads (403), so it is not quoted. The feed itself is keyless. Speeds are m/s.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'ctp-cluj', + name: 'Cluj-Napoca CTP', + operator: 'Compania de Transport Public Cluj-Napoca', + region: 'Cluj-Napoca, Romania', + center: { lat: 46.77, lon: 23.59 }, + loadRadiusKm: 15, + url: 'https://cluj-rt-feed.gtfs.ro/vehiclePositions', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2614', + attribution: 'Compania de Transport Public Cluj-Napoca', + terms: { + note: 'Keyless; no licence found. Same basis as Metro Transit and OVapi.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'ctp-iasi', + name: 'Iași CTP', + operator: 'Compania de Transport Public Iași', + region: 'Iași, Romania', + center: { lat: 47.16, lon: 27.59 }, + loadRadiusKm: 15, + url: 'https://iasi-rt-feed.gtfs.ro/vehiclePositions', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2118', + attribution: 'Compania de Transport Public Iași', + terms: { + note: 'Keyless; no licence found. Same basis as Metro Transit and OVapi.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'mpk-rzeszow', + name: 'Rzeszów city transport', + operator: 'Rzeszowski Transport Miejski (MPK Rzeszów)', + region: 'Rzeszów, Poland', + center: { lat: 50.04, lon: 22.0 }, + loadRadiusKm: 15, + url: 'https://www.mpkrzeszow.pl/gtfs/rt/gtfsrt.pb', + license: 'MPK Rzeszów open data', + licenseUrl: 'https://www.mpkrzeszow.pl/otwartedane/', + attribution: 'MPK Rzeszów', + terms: { + note: 'Listed on the operator’s open-data page, which names no licence. No bearing; heading comes from movement.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'emt-malaga', + name: 'Málaga EMT', + operator: 'Empresa Malagueña de Transportes (EMT)', + region: 'Málaga, Spain', + center: { lat: 36.72, lon: -4.42 }, + loadRadiusKm: 15, + url: 'https://gtfs.emtmalaga.es/GTFSRTapi/api/vehicleposition', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2213', + attribution: 'EMT Málaga', + terms: { + note: 'Keyless; no licence found. Same basis as Metro Transit and OVapi. No bearing; heading comes from movement.', + }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'carris-lisboa', + name: 'Carris (Lisbon city)', + operator: 'Carris – Companhia Carris de Ferro de Lisboa', + region: 'Lisbon, Portugal', + center: { lat: 38.74, lon: -9.15 }, + loadRadiusKm: 15, + url: 'https://gateway.carris.pt/gateway/gtfs/api/v2.11/GTFS/realtime/vehiclepositions', + license: 'No licence stated', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2930', + attribution: 'Carris', + terms: { + note: 'Keyless official gateway; no licence found. Same basis as Metro Transit and OVapi. Carries neither bearing nor speed, and vehicle reports run about a minute old. Route ids append a variant.', + }, + defaultMode: 'bus', + routeLabel: carrisRouteLabel, + }), + transitFeed({ + id: 'mybas-johor', + name: 'BAS.MY Johor Bahru', + operator: 'BAS.MY, via data.gov.my', + region: 'Johor Bahru, Malaysia', + center: { lat: 1.51, lon: 103.75 }, + loadRadiusKm: 35, + url: 'https://api.data.gov.my/gtfs-realtime/vehicle-position/mybas-johor/', + license: 'No licence stated for the feed', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-3174', + attribution: 'BAS.MY / data.gov.my', + terms: { + note: 'Served keyless by Malaysia’s national open-data API; no licence for the feed was found. Same basis as Metro Transit and OVapi. Without the trailing slash the API redirects. Route ids append an operator code.', + }, + defaultMode: 'bus', + routeLabel: mybasJohorRouteLabel, + }), + transitFeed({ + id: 'mybas-kota-bharu', + name: 'BAS.MY Kota Bharu', + operator: 'BAS.MY, via data.gov.my', + region: 'Kota Bharu, Malaysia', + // Routes run south into Kelantan: 95% of vehicles within 58 km on 2026-11-08. + center: { lat: 6.06, lon: 102.22 }, + loadRadiusKm: 60, + url: 'https://api.data.gov.my/gtfs-realtime/vehicle-position/mybas-kota-bharu/', + license: 'No licence stated for the feed', + licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-3169', + attribution: 'BAS.MY / data.gov.my', + terms: { note: 'Same API and basis as Johor Bahru.' }, + defaultMode: 'bus', + }), + transitFeed({ + id: 'astuce-rouen', + name: 'Rouen Astuce', + operator: 'Métropole Rouen Normandie (Astuce), relayed by bus-tracker.fr', + region: 'Rouen, France', + center: { lat: 49.44, lon: 1.1 }, + loadRadiusKm: 20, + url: 'https://gtfs.bus-tracker.fr/gtfs-rt/tcar/?tcar=1&tae=1&tni=1', + license: 'Licence Ouverte 2.0', + licenseUrl: + 'https://transport.data.gouv.fr/datasets/donnees-statiques-et-temps-reel-du-reseau-astuce-metropole-rouen-normandie', + attribution: 'Métropole Rouen Normandie (Astuce) / bus-tracker.fr', + terms: { + quote: 'licence: lov2', + note: 'The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); this registry reads it through bus-tracker.fr, an unofficial relay that merges the city’s networks into one GTFS-RT file. Route ids carry the network prefix (`TCAR:`).', + }, + defaultMode: 'bus', + routeLabel: busTrackerRouteLabel, + }), + transitFeed({ + id: 'mpm-toulon', + name: 'Toulon Mistral', + operator: 'Métropole Toulon Provence Méditerranée (réseau Mistral)', + region: 'Toulon, France', + center: { lat: 43.12, lon: 5.94 }, + loadRadiusKm: 18, + url: 'https://feed-rdtpm-toulon.ratpdev.com/VehiclePosition/GTFS-RT', + license: 'Licence Ouverte 2.0', + licenseUrl: + 'https://transport.data.gouv.fr/datasets/reseau-de-transport-urbain-de-la-metropole-toulon-provence-mediterranee', + attribution: 'Métropole Toulon Provence Méditerranée (Mistral)', + terms: { + quote: 'licence: lov2', + note: 'Dataset record’s licence field quoted. Speeds are km/h: readings ran 3.5 times the measured movement on 2026-11-07, so the proxy converts them. Route ids are zero-padded.', + }, + defaultMode: 'bus', + routeLabel: unpaddedRouteLabel, + speedUnit: 'km/h', + }), + transitFeed({ + id: 'lia-le-havre', + name: 'Le Havre LiA', + operator: 'Le Havre Seine Métropole (LiA), relayed by bus-tracker.fr', + region: 'Le Havre, France', + center: { lat: 49.49, lon: 0.11 }, + loadRadiusKm: 18, + url: 'https://gtfs.bus-tracker.fr/gtfs-rt/lia/vehicle-positions', + license: 'ODbL', + licenseUrl: + 'https://transport.data.gouv.fr/datasets/reseau-de-transport-en-commun-lia-gtfs-siri', + attribution: 'Le Havre Seine Métropole (LiA) / bus-tracker.fr', + terms: { + quote: 'licence: odc-odbl', + note: 'The network publishes under ODbL (dataset record quoted); read through the bus-tracker.fr relay, which converts its SIRI feed to GTFS-RT. The layer draws positions and redistributes no database. Lines A and B are the tramway.', + }, + defaultMode: 'bus', + routeLabel: busTrackerRouteLabel, + routeMode: liaRouteMode, + }), + transitFeed({ + id: 'filbleu-tours', + name: 'Tours Fil Bleu', + operator: 'Syndicat des Mobilités de Touraine (Fil Bleu)', + region: 'Tours, France', + center: { lat: 47.39, lon: 0.69 }, + loadRadiusKm: 18, + url: 'https://data.filbleu.fr/ws-tr/gtfs-rt/opendata/vehicle-positions', + license: 'Licence Ouverte 2.0', + licenseUrl: + 'https://transport.data.gouv.fr/datasets/fil-bleu-syndicat-des-mobilites-gtfs-gtfs-rt', + attribution: 'Fil Bleu – Syndicat des Mobilités de Touraine', + terms: { + quote: 'licence: lov2', + note: 'Dataset record’s licence field quoted.', + }, + defaultMode: 'bus', + }), ]); /** diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index 0e3d4ab374..8afe6ea8b5 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -611,3 +611,111 @@ test('Carris Metropolitana route ids read as the line number on the bus', () => assert.equal(transitRouteLabel(feed, 'unexpected'), 'unexpected'); assert.equal(transitRouteLabel(feed, null), null); }); + +// The 2026-11 batch: one landmark per feed, inside its own radius. +const NEW_CITY_LANDMARKS = { + 'pid-praha': [50.0875, 14.4213], + 'ztm-warszawa': [52.2297, 21.0122], + 'tbm-bordeaux': [44.8378, -0.5792], + 'sendai-city-bus': [38.2602, 140.8824], + 'ztm-poznan': [52.4064, 16.9252], + 'ztm-gdansk': [54.352, 18.6466], + 'ets-edmonton': [53.5461, -113.4938], + 'halifax-transit': [44.6488, -63.5752], + 'bc-transit-victoria': [48.4284, -123.3656], + 'tam-montpellier': [43.6108, 3.8767], + 'ztp-krakow-bus': [50.0614, 19.9366], + 'ztp-krakow-tram': [50.0614, 19.9366], + 'vilnius-transport': [54.6872, 25.2797], + 'tpbi-bucuresti': [44.4268, 26.1025], + 'roma-mobilita': [41.9028, 12.4964], + 'gtt-torino': [45.0703, 7.6869], + 'actv-venezia-bus': [45.4408, 12.3155], + 'actv-venezia-waterbus': [45.4408, 12.3155], + 'adelaide-metro': [-34.9285, 138.6007], + 'marta-atlanta': [33.749, -84.388], + 'rtd-denver': [39.7392, -104.9903], + 'ctp-cluj': [46.7712, 23.6236], + 'ctp-iasi': [47.1585, 27.6014], + 'mpk-rzeszow': [50.0412, 21.9991], + 'emt-malaga': [36.7213, -4.4214], + 'carris-lisboa': [38.7223, -9.1393], + 'mybas-johor': [1.4927, 103.7414], + 'mybas-kota-bharu': [6.1254, 102.2381], + 'astuce-rouen': [49.4432, 1.0999], + 'mpm-toulon': [43.1242, 5.928], + 'lia-le-havre': [49.4944, 0.1079], + 'filbleu-tours': [47.3941, 0.6848], +}; + +test('every city in the 2026-11 batch is live, licensed and covers its own centre', () => { + for (const [id, [lat, lon]] of Object.entries(NEW_CITY_LANDMARKS)) { + const feed = getTransitFeed(id); + assert.ok(feed, `${id} is routable`); + assert.ok( + publicTransitCatalog().some((f) => f.id === id), + `${id} is offered to the browser`, + ); + assert.ok(feed.terms?.note, `${id} records the basis it ships on`); + assert.ok( + transitFeedsInRange(lat, lon).some((f) => f.id === id), + `${id} covers its city`, + ); + } + // A feed's radius stays local: Warsaw is not polled for Kraków. + assert.ok( + !transitFeedsInRange(50.0614, 19.9366).some((f) => f.id === 'ztm-warszawa'), + ); +}); + +test('feeds with no stated licence say so and name the basis they ship on', () => { + for (const feed of TRANSIT_FEED_REGISTRY.filter((f) => + /^No licence stated/.test(f.license), + )) { + assert.match( + feed.terms.note, + /Metro Transit and OVapi|Same .*basis/, + `${feed.id} names its basis`, + ); + } +}); + +test('route ids in the 2026-11 batch read as the line on the vehicle', () => { + const label = (id, routeId) => transitRouteLabel(getTransitFeed(id), routeId); + assert.equal(label('pid-praha', 'L135'), '135'); + assert.equal(label('ets-edmonton', '009'), '9'); + assert.equal(label('mpm-toulon', '0002'), '2'); + assert.equal(label('gtt-torino', '10NU'), '10N'); + assert.equal(label('actv-venezia-waterbus', '5.1_UN'), '5.1'); + assert.equal(label('actv-venezia-bus', '53E_ES'), '53E'); + assert.equal(label('bc-transit-victoria', '95-VIC'), '95'); + assert.equal(label('carris-lisboa', '172_1'), '172'); + assert.equal(label('astuce-rouen', 'TCAR:93'), '93'); + assert.equal(label('mybas-johor', 'J33CWLMYJB'), 'J33'); + // Unmatched and absent ids pass through untouched. + assert.equal(label('pid-praha', 'S4'), 'S4'); + assert.equal(label('gtt-torino', null), null); +}); + +test('trams, waterbuses and buses are told apart where the ids allow it', () => { + const mode = (id, routeId) => transitModeFor(getTransitFeed(id), routeId); + assert.equal(mode('pid-praha', 'L22'), 'tram'); + assert.equal(mode('pid-praha', 'L135'), 'bus'); + assert.equal(mode('tbm-bordeaux', 'A'), 'tram'); + assert.equal(mode('tbm-bordeaux', '16'), 'bus'); + assert.equal(mode('lia-le-havre', 'B'), 'tram'); + assert.equal(mode('lia-le-havre', '3'), 'bus'); + assert.equal(mode('ztp-krakow-tram', null), 'tram'); + assert.equal(mode('actv-venezia-waterbus', '1_UN'), 'ferry'); +}); + +test('feeds that publish km/h are marked for conversion, and only those', () => { + const kmh = TRANSIT_FEED_REGISTRY.filter((f) => f.speedUnit === 'km/h') + .map((f) => f.id) + .sort(); + assert.deepEqual(kmh, [ + 'carris-metropolitana-lisboa', + 'mpm-toulon', + 'tam-montpellier', + ]); +}); diff --git a/src/data/transitProxy.test.mjs b/src/data/transitProxy.test.mjs index 7c173cb5fd..1c9f6679fe 100644 --- a/src/data/transitProxy.test.mjs +++ b/src/data/transitProxy.test.mjs @@ -396,3 +396,13 @@ test('client history validates response bounds, epochs and cancellation through { name: 'AbortError' }, ); }); + +test('Adelaide asks for */* because a protobuf Accept gets base64 text back', () => { + const headers = transitUpstreamHeaders(getTransitFeed('adelaide-metro')); + assert.equal(headers.Accept, '*/*'); + // Every other feed keeps the protobuf-first Accept. + assert.match( + transitUpstreamHeaders(getTransitFeed('mbta')).Accept, + /protobuf/, + ); +}); From 923287eb92df38b24df9ff2b5b2f1913e5a638ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Itallo=20Brand=C3=A3o?= <45429643+IMBrandao@users.noreply.github.com> Date: Sun, 8 Nov 2026 02:56:19 -0300 Subject: [PATCH 35/61] chore(changelog): name the transit fragment after PR #1628 Co-Authored-By: Claude Opus 5.5 --- .../{transit-more-cities.md => 1628-transit-more-cities.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog.d/{transit-more-cities.md => 1628-transit-more-cities.md} (100%) diff --git a/changelog.d/transit-more-cities.md b/changelog.d/1628-transit-more-cities.md similarity index 100% rename from changelog.d/transit-more-cities.md rename to changelog.d/1628-transit-more-cities.md From e631839a4eee48bbcccc9fb39cd05dff5e4b5d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Itallo=20Brand=C3=A3o?= <45429643+IMBrandao@users.noreply.github.com> Date: Sun, 8 Nov 2026 03:08:40 -0300 Subject: [PATCH 36/61] fix(transit): quote Halifax's Open Government Licence The licence page refuses automated requests; its text was read in a browser. Credit now uses the licence's own attribution statement. Co-Authored-By: Claude Opus 5.5 --- DATA_SOURCES.md | 2 +- src/data/transitFeeds.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 68f58b0671..6a963c653f 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -112,7 +112,7 @@ How to read this: | **Poznań buses and trams** (ztm.poznan.pl) | Transit layer live vehicles, Poznań, Poland | ZTM Poznań open-data terms (https://www.ztm.poznan.pl/otwarte-dane/dla-deweloperow/). Stated: “Treści udostępniane są bezwnioskowo i bezpłatnie, na zasadach powszechnego dostępu i stanowią źródło informacji.” Reuse is free on three conditions: name the source, give the date of the last update, and say the data were processed. The credit names ZTM and says processed; the snapshot timestamp is the update date. The feed carries no bearing, so heading comes from movement between fixes. | Zarząd Transportu Miejskiego w Poznaniu (processed) | | **Gdańsk buses and trams** (ckan2.multimediagdansk.pl) | Transit layer live vehicles, Gdańsk, Poland | CC BY 4.0 (https://dane.gov.pl/pl/dataset/38599,rozklady-jazdy-i-lokalizacja-przystankow-gtfs-rt). The national catalogue (dane.gov.pl) lists this dataset under CC BY 4.0. No bearing; heading comes from movement. Speeds are m/s. | Zarząd Transportu Miejskiego w Gdańsku | | **Edmonton Transit Service** (gtfs.edmonton.ca) | Transit layer live vehicles, Edmonton, AB | City of Edmonton Open Data Agreement (https://www.edmonton.ca/transportation/Web-version2.1-OpenDataAgreement.pdf). The agreement is the same municipal template as Mississauga and Burlington: a licence to use, modify and distribute for any lawful purpose, in any medium. It was read from search excerpts; the PDF itself would not extract here. Route ids are zero-padded. Speeds are m/s. | Contains information licensed under the Open Data Agreement – City of Edmonton | -| **Halifax Transit** (gtfs.halifax.ca) | Transit layer live vehicles, Halifax, NS | Halifax Open Data Licence (https://www.halifax.ca/home/open-data/open-data-licence). The catalogue points at Halifax’s open-data licence; the licence page renders only in a browser and was not quoted. Speeds are m/s. | Halifax Regional Municipality (Halifax Transit) | +| **Halifax Transit** (gtfs.halifax.ca) | Transit layer live vehicles, Halifax, NS | Open Government Licence – Halifax v1.0 (https://www.halifax.ca/home/open-data/open-data-license), modelled on OGL – Canada 2.0. Stated: “The information provider grants you a worldwide, royalty-free, perpetual, non-exclusive licence to use the Information, including for commercial purposes, subject to the terms below.” No logos or implied endorsement. Speeds are m/s. | Contains information licenced under the Open Government Licence – Halifax | | **Victoria Regional Transit** (bct.tmix.se) | Transit layer live vehicles, Victoria, BC | BC Transit Open Data Terms of Use (https://www.bctransit.com/open-data/terms-of-use). Stated: “BC Transit grants you a limited, revocable and non-exclusive license to use, reproduce, and redistribute the Data in accordance with these Terms.” The grant is revocable, like the Ontario municipal templates. Route ids carry a `-VIC` system suffix. Speeds are m/s. | BC Transit | | **Montpellier TaM** (gtfsproxy.e-tam.fr) | Transit layer live vehicles, Montpellier, France | ODbL (https://transport.data.gouv.fr/datasets/offre-de-transport-tam-en-temps-reel-gtfs-rt-urbain-et-suburbain). The quote is the dataset record’s licence field. ODbL asks for credit and share-alike on a derived database; the layer redistributes no database, it draws the positions. Speeds are km/h: readings ran 3.3 times the measured movement on 2026-11-07, so the proxy converts them. | Montpellier Méditerranée Métropole (TaM) | | **Kraków buses** (gtfs.ztp.krakow.pl) | Transit layer live vehicles, Kraków, Poland | No licence stated (https://gtfs.ztp.krakow.pl/). ZTP publishes this feed keyless on its own GTFS server and lists it in the Mobility Database, but states no licence there or on dane.gov.pl. Shipped on the same basis as Metro Transit and OVapi; switch it off if ZTP objects. | Zarząd Transportu Publicznego w Krakowie | diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 5ac28d5dad..bb2642d07c 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -1069,11 +1069,14 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ center: { lat: 44.7, lon: -63.6 }, loadRadiusKm: 22, url: 'https://gtfs.halifax.ca/realtime/Vehicle/VehiclePositions.pb', - license: 'Halifax Open Data Licence', - licenseUrl: 'https://www.halifax.ca/home/open-data/open-data-licence', - attribution: 'Halifax Regional Municipality (Halifax Transit)', + license: 'Open Government Licence – Halifax', + licenseUrl: 'https://www.halifax.ca/home/open-data/open-data-license', + attribution: + 'Contains information licenced under the Open Government Licence – Halifax', terms: { - note: 'The catalogue points at Halifax’s open-data licence; the licence page renders only in a browser and was not quoted. Speeds are m/s.', + quote: + 'The information provider grants you a worldwide, royalty-free, perpetual, non-exclusive licence to use the Information, including for commercial purposes, subject to the terms below.', + note: 'Version 1.0, modelled on the Open Government Licence – Canada 2.0. The attribution is the licence’s own standard statement, with a link to the licence where possible. Logos and crests are excluded and no endorsement may be implied, so the credit stays plain text. The page refuses automated requests (403); its text was read in a browser on 2026-11-08. Speeds are m/s.', }, defaultMode: 'bus', }), From 9f2dfdf8208efdd831b0f0743edb12f76774c809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Valdez?= <762946+avaldini@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:34:33 +0000 Subject: [PATCH 37/61] fix(voice): send OpenAI Realtime tool schemas the API accepts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenAI Realtime now answers 400 invalid_function_parameters for a whole session whose tool schema uses Unicode property classes, as resolve_area's area-id pattern does, so voice never connects ("Failed to create Realtime token"). The session sends its tools through chatSchema, the filter typed chat adopted in #1616, which leaves out only \p{…} patterns; area ids are still checked against the action's own contract before the tool runs. Fixes #1618 --- server/providers/openai/chat.js | 2 +- server/providers/openai/realtime.js | 17 +++++++++++- src/tooling/localServices.test.mjs | 41 ++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/server/providers/openai/chat.js b/server/providers/openai/chat.js index 6ca4648d68..b0f7fe2112 100644 --- a/server/providers/openai/chat.js +++ b/server/providers/openai/chat.js @@ -69,7 +69,7 @@ function validMessages(messages) { * 400 for a whole request whose tool uses Unicode property classes (`\p{L}`), * as `resolve_area`'s area ids do. Every argument is still checked against * the action's own contract before the tool runs, so the model loses a hint, - * not a rule. Realtime voice accepts these patterns and keeps them. + * not a rule. Realtime voice refuses them too now (#1618) and uses this as well. */ export function chatSchema(schema) { if (Array.isArray(schema)) return schema.map(chatSchema); diff --git a/server/providers/openai/realtime.js b/server/providers/openai/realtime.js index 73ac8d2cf0..4412eb331b 100644 --- a/server/providers/openai/realtime.js +++ b/server/providers/openai/realtime.js @@ -14,6 +14,7 @@ import { } from './constants.js'; import { realtimeInstructions } from './instructions.js'; import { GEV_REALTIME_TOOLS, offeredTools } from './tools.js'; +import { chatSchema } from './chat.js'; import { resolveOverpassUpstreams } from '../overpass/constants.js'; import { preferCodexOAuth, @@ -128,6 +129,19 @@ function createRealtimeOAuthLoginHandler({ }; } +/** + * The tools one Realtime session is offered, as OpenAI accepts them: it now + * refuses a whole session whose tool schema uses `\p{…}` patterns (#1618), as + * Chat Completions did (#1616), so voice drops the same pattern hints chat does. + */ +function realtimeSessionTools(tools, { overpass = false } = {}) { + return offeredTools(tools, { overpass }).map((tool) => + tool.parameters + ? { ...tool, parameters: chatSchema(tool.parameters) } + : tool, + ); +} + function createRealtimeTokenHandler({ annotationGuidance, endpoint = 'https://api.openai.com/v1/realtime/client_secrets', @@ -303,7 +317,7 @@ function createRealtimeTokenHandler({ output: { voice }, }, instructions: realtimeInstructions(annotationGuidance, { overpass }), - tools: offeredTools(tools, { overpass }), + tools: realtimeSessionTools(tools, { overpass }), tool_choice: 'auto', }, }; @@ -370,4 +384,5 @@ export { createRealtimeOAuthLoginHandler, createRealtimeOAuthStatusHandler, createRealtimeTokenHandler, + realtimeSessionTools, }; diff --git a/src/tooling/localServices.test.mjs b/src/tooling/localServices.test.mjs index 84a2f69261..7a69b5e7fa 100644 --- a/src/tooling/localServices.test.mjs +++ b/src/tooling/localServices.test.mjs @@ -20,12 +20,9 @@ import { import { openAiRealtimeProxy } from 'gods-eye-view/server/providers/openai'; import { keySetupEndpoint } from 'gods-eye-view/server/standalone/key-setup'; import { realtimeInstructions } from '../../server/providers/openai/instructions.js'; -import { - GEV_REALTIME_TOOLS, - offeredTools, - realtimeTools, -} from '../../server/providers/openai/tools.js'; +import { GEV_REALTIME_TOOLS } from '../../server/providers/openai/tools.js'; import { createDebugLogHandler } from '../../server/providers/openai/debug-log.js'; +import { realtimeSessionTools } from '../../server/providers/openai/realtime.js'; import { attachVoiceResult } from '../voice/speech.js'; import { sanitizeDebugValue } from '../voice/realtimeDiagnostics.js'; import { standaloneVoiceTools } from '../../server/standalone/voiceTools.js'; @@ -199,7 +196,10 @@ test('Realtime handler preserves tools and default instructions, isolates suppli sent.at(-1).session.instructions, realtimeInstructions(guidance), ); - assert.deepEqual(sent.at(-1).session.tools, realtimeTools()); + assert.deepEqual( + sent.at(-1).session.tools, + realtimeSessionTools(GEV_REALTIME_TOOLS), + ); } assert.notEqual(sent[0].session.instructions, sent[1].session.instructions); assert.equal(sent[0].session.instructions, sent[2].session.instructions); @@ -607,7 +607,10 @@ test('osm_query is offered only when an operator configured Overpass', async (t) assert.doesNotMatch(plain.instructions, /osm_query/); assert.ok(names(plain).includes('resolve_area')); assert.ok(names(plain).includes('find_imagery')); - assert.deepEqual(configured.tools, GEV_REALTIME_TOOLS); + assert.deepEqual( + configured.tools, + realtimeSessionTools(GEV_REALTIME_TOOLS, { overpass: true }), + ); assert.match(configured.instructions, /osm_query/); assert.equal( configured.instructions, @@ -656,7 +659,7 @@ test('Realtime sessions carry supplied tools, and the standalone voice adds the ); assert.equal(response.status, 200); // Without an operator Overpass, osm_query is left out of the session. - assert.deepEqual(sent.at(-1).session.tools, offeredTools(tools)); + assert.deepEqual(sent.at(-1).session.tools, realtimeSessionTools(tools)); assert.ok( !sent.at(-1).session.tools.some(({ name }) => name === 'osm_query'), ); @@ -740,6 +743,26 @@ test('key setup writes only the supplied application root, retains request guard assert.equal(existsSync(path.join(untouched, '.env')), false); }); +test('Realtime sessions leave out the Unicode property patterns OpenAI refuses (#1618)', async (t) => { + // OpenAI answers 400 invalid_function_parameters for a whole Realtime session + // whose tool schema uses `\p{…}`, as resolve_area's area ids do, so voice + // never connects. The session drops only those patterns, as typed chat does. + env(t, 'OPENAI_API_KEY', 'fixture-upstream-secret'); + env(t, 'GEV_RATELIMIT_OPENAI_PER_MIN', undefined); + const sent = []; + t.mock.method(globalThis, 'fetch', async (_url, options) => { + sent.push(JSON.parse(options.body).session); + return Response.json({ value: 'fixture-ephemeral' }); + }); + const response = await request( + install(openAiRealtimeProxy({})).get('/api/realtime/token'), + ); + assert.equal(response.status, 200); + const { tools } = sent.at(-1); + assert.ok(tools.some(({ name }) => name === 'resolve_area')); + assert.doesNotMatch(JSON.stringify(tools), /\\\\[pP]\{/); +}); + test('Realtime service configuration selects compatible endpoint/model without forwarding request model IDs or keys', async () => { const handler = install( openAiRealtimeProxy({ @@ -757,7 +780,7 @@ test('Realtime service configuration selects compatible endpoint/model without f assert.equal(payload.session.model, 'configured-model'); assert.deepEqual( payload.session.tools, - realtimeTools({ overpass: false }), + realtimeSessionTools(GEV_REALTIME_TOOLS), ); return Response.json({ value: 'short-lived-fixture' }); }, From d52c719ef645657aea470b8c6aa3b2f2bd791c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Valdez?= <762946+avaldini@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:52:24 +0000 Subject: [PATCH 38/61] docs(changelog): OpenAI Realtime voice tool patterns (#1638) --- changelog.d/1638-openai-realtime-tool-patterns.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog.d/1638-openai-realtime-tool-patterns.md diff --git a/changelog.d/1638-openai-realtime-tool-patterns.md b/changelog.d/1638-openai-realtime-tool-patterns.md new file mode 100644 index 0000000000..20e1671128 --- /dev/null +++ b/changelog.d/1638-openai-realtime-tool-patterns.md @@ -0,0 +1,5 @@ +- Voice on OpenAI connects again: OpenAI Realtime refused every session, so + the mic failed with "Failed to create Realtime token", because + `resolve_area`'s area-id pattern uses Unicode classes it no longer accepts. + Voice leaves those patterns out, as typed chat does; area ids are still + checked before the tool runs (avaldini, #1638). From da6b63b6fdd95df533d7fbfce2ae0a3b65b1d21a Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 16:45:11 +0400 Subject: [PATCH 39/61] docs(tools): tighten the heading-wrap changelog, comments and overview --- changelog.d/1524-tools-heading-wrap.md | 7 +++---- docs/CURRENT-STATE.md | 4 +--- src/tools/queries/environment.js | 2 +- src/tools/queries/space.test.mjs | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/changelog.d/1524-tools-heading-wrap.md b/changelog.d/1524-tools-heading-wrap.md index 2a630f600a..3647bf9a84 100644 --- a/changelog.d/1524-tools-heading-wrap.md +++ b/changelog.d/1524-tools-heading-wrap.md @@ -1,4 +1,3 @@ -- The agent and voice query tools report a direction that rounds to 360 as 0: - vessel course and heading, aircraft course, transit bearing, camera heading - and satellite azimuths now round through the shared heading helper the - layers use, which wraps into 0–359 (@quanticsoul4772, #1524). +- The agent and voice query tools wrap whole-degree directions into 0–359, so + a vessel course or heading, aircraft course, transit bearing, camera heading + or satellite azimuth that rounds to 360 reads 0 (@quanticsoul4772, #1524). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 57daf7849d..0ffb49ea87 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -398,9 +398,7 @@ perimeters, terrain height, military installations and map features, plus a combined situation brief, military awareness around a point, the app's heads-up display caption, and a link that opens the app over an area. Tools reuse the layers' portable source factories, take a shared `area` argument (place name, bounding box, or point and radius) and cap -lists at 25 rows by default. Their whole-degree directions round through -`roundHeadingDegrees`, listed with the heading readouts below. -`aircraft_in_area` and `vessels_in_area` can also +lists at 25 rows by default. `aircraft_in_area` and `vessels_in_area` can also count every match by a field (`group_by`: airline, read from the ICAO designator in the callsign, or operator, country or type for aircraft; type or destination for ships; the ten largest groups, then other and unknown counts; diff --git a/src/tools/queries/environment.js b/src/tools/queries/environment.js index 0af696e369..1f5800d53a 100644 --- a/src/tools/queries/environment.js +++ b/src/tools/queries/environment.js @@ -71,7 +71,7 @@ function weatherRow(weather) { precipitation_mm: weather.precipitationMm ?? null, cloud_cover_pct: weather.cloudCoverPct ?? null, wind_kph: weather.windKph ?? null, - // Raw Open-Meteo value, like the fields above; it reports north as 360. + // Raw Open-Meteo value, so north reads 360. wind_direction_deg: weather.windDirectionDeg ?? null, visibility_m: weather.visibilityM ?? null, }; diff --git a/src/tools/queries/space.test.mjs b/src/tools/queries/space.test.mjs index 41394e3051..cb12dfcbe0 100644 --- a/src/tools/queries/space.test.mjs +++ b/src/tools/queries/space.test.mjs @@ -305,8 +305,8 @@ test('satellite azimuths that round to 360 read as 0', async () => { tools: coreTools, services: { satellites: satellites(), clock: CLOCK }, }); - // These points are chosen so the ISS's raw azimuths fall just below 360°; - // pin that first, so the test cannot pass on a raw value already near 0. + // At these points the ISS's raw azimuths fall just below 360°; check that + // first so the test cannot pass on a raw value near 0. const [, line1, line2] = TLE.split('\n'); const iss = twoline2satrec(line1, line2); const nearNorth = (deg) => deg > 359.5 && deg < 360; From 394f3216f8ec6dc828bd1f836d1dae24444d7479 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 17:06:56 +0400 Subject: [PATCH 40/61] Drop the sub-acre rounding comment --- src/layers/perimeters/cards.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/layers/perimeters/cards.js b/src/layers/perimeters/cards.js index a6cb3ac4d9..4c73d5733a 100644 --- a/src/layers/perimeters/cards.js +++ b/src/layers/perimeters/cards.js @@ -159,8 +159,6 @@ export function buildIncidentCard(row, nowMs, { link = null } = {}) { // the known cause, behavior and complexity values and the wording around them. const facts = []; if (Number.isFinite(row.acres)) { - // WFIGS reports sizes to the hundredth of an acre; a fire under one acre - // keeps them rather than reading "0 ac". const acres = row.acres < 1 ? Math.round(row.acres * 100) / 100 : Math.round(row.acres); facts.push( From 7a053c640d53e6453715d29dc71e4916d7e97db3 Mon Sep 17 00:00:00 2001 From: Said Turksever Date: Mon, 9 Nov 2026 13:50:14 +0000 Subject: [PATCH 41/61] =?UTF-8?q?fix(transit):=20real=20route-id=20modes?= =?UTF-8?q?=20for=20Prague,=20Bordeaux=20and=20Rouen;=20dated=20Warsaw/Poz?= =?UTF-8?q?na=C5=84=20credits;=20data.gov.my=20refresh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Prague PID: map route-id ranges from PID's GTFS (metro L991-993, S/R trains L1000s/L1100s, P ferries L1800s, trolleybuses 50-59, X lines, funicular LD) instead of 'below 100 is a tram, rest bus'. - Bordeaux TBM: trams ride numbered ids 59-62/163/164 (A-F), boats 951-953; the old letter match never fired. - Rouen Astuce: TCAR:90 Metro as tram, TCAR:99 Calypso as ferry; Le Havre FUNI. - Warsaw and Poznan: credit carries the data date (and Warsaw links its API), as their terms require. - data.gov.my feeds: CC BY 4.0, refreshMs 30 s to stay under 4 requests/min; proxy honours per-feed refreshMs. - Denver: quote the RTD agreement; tests use the feeds' real route ids. --- DATA_SOURCES.md | 16 +-- changelog.d/1628-transit-more-cities.md | 7 +- src/data/dataCredits.js | 28 +++- src/data/dataCredits.test.mjs | 28 +++- src/data/transitFeeds.js | 168 ++++++++++++++++++------ src/data/transitFeeds.test.mjs | 57 +++++++- src/data/transitProxy.js | 19 ++- src/data/transitProxy.test.mjs | 12 ++ src/layers/transit/ingestion.js | 8 +- src/sources/transitService.js | 3 +- 10 files changed, 287 insertions(+), 59 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 6a963c653f..a302235fde 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -105,11 +105,11 @@ How to read this: | **SMTR Rio de Janeiro** (dados.mobilidade.rio) | Transit layer live vehicles, Rio de Janeiro: municipal buses (SPPO) and the Mobi-Rio BRT, as two feeds | CC BY 4.0, stated on both data.rio catalog pages. Keyless GTFS-Realtime published by the Secretaria Municipal de Transportes, labelled beta, with a gateway limit of 5 requests a second and 60 a minute. Line names come from SMTR’s GTFS `routes.txt` (dados.mobilidade.rio/gtfs/schedule), under the same licence. | Attribution to SMTR / Prefeitura da Cidade do Rio de Janeiro under CC BY 4.0 | | **ZDiTM Szczecin** (zditm.szczecin.pl) | Transit layer live vehicles, Szczecin, Poland: buses and trams as one feed | CC0 1.0, stated on the ZDiTM developer page: “The data are provided free of charge under the CC0 1.0 licence, for use in any context, with no prior notification required.” Keyless GTFS-Realtime; the page says one update a minute, measured at about every 20 seconds. The feed carries no route id, so every vehicle takes the default bus mode. | None required (CC0); credited to ZDiTM Szczecin as a courtesy | | **Carris Metropolitana** (api.carrismetropolitana.pt) | Transit layer live vehicles, Lisbon Metropolitan Area, Portugal | Keyless GTFS-Realtime documented in the operator’s public API repository (github.com/carrismetropolitana/api). No licence is stated for the realtime endpoint; the operator’s static GTFS is CC BY 4.0. Included on the same basis as the Metro Transit and OVapi feeds and credited as a courtesy; it can be switched off if Carris objects. Speeds are published in km/h and converted to m/s by the proxy. Route ids are read as the line number per the operator’s `/v2/routes`. | Courtesy credit to Carris Metropolitana | -| **Prague PID** (api.golemio.cz) | Transit layer live vehicles, Prague and Central Bohemia, Czechia | CC BY (https://pid.cz/o-systemu/opendata/). Stated: “Data, která lze stáhnout přímo zde z webu, jsou stejně jako celý obsah webu opatřena licencí CC-BY” The PID open-data page lists this realtime feed and licenses the data it publishes under CC BY, crediting the author and any changes. The same page says data served from other sources follows that source’s licence; the feed is served by Golemio, the city’s data platform, which states none of its own. Keyless since the catalogue moved it off the X-Access-Token endpoint. Speeds are m/s, checked against movement on 2026-11-07. Route ids are `L` plus the line number; lines below 100 are trams. | Pražská integrovaná doprava (PID) / Golemio | -| **Warsaw buses and trams** (mkuran.pl) | Transit layer live vehicles, Warsaw, Poland | Warsaw Open Data Project Usage Terms (https://mkuran.pl/gtfs/). Stated: “The City Hall requires a credit by providing the name Miasto Stołeczne Warszawa, data download date (use the timestamp from the FeedHeader) and link to http://api.um.warszawa.pl.” Positions come from the Warsaw City Hall API, repackaged as GTFS-RT by Mikołaj Kuranowski’s unofficial feed. The credit names the city and its API; the download date it asks for is the feed timestamp the layer already shows with each snapshot. Vehicle timestamps ran about two minutes old on 2026-11-07, which the delayed playback absorbs. | Miasto Stołeczne Warszawa (api.um.warszawa.pl) | -| **Bordeaux TBM** (bdx.mecatran.com) | Transit layer live vehicles, Bordeaux, France | Licence Ouverte / Etalab 2.0 (https://transport.data.gouv.fr/datasets/offres-de-services-bus-tram-et-scolaire-au-format-gtfs-netex-gtfs-rt-siri-lite). The quote is the licence field of the national access point’s dataset record (fr-lo is the Licence Ouverte), which asks only for credit. The `apiKey` in the URL is not a credential: it is the same fixed string printed in the open-data listing for everyone. Speeds are m/s. Trams run on lettered lines A–D; numbered lines are buses. | Bordeaux Métropole (TBM) | +| **Prague PID** (api.golemio.cz) | Transit layer live vehicles, Prague and Central Bohemia, Czechia | CC BY (https://pid.cz/o-systemu/opendata/). Stated: “Data, která lze stáhnout přímo zde z webu, jsou stejně jako celý obsah webu opatřena licencí CC-BY” The PID open-data page lists this realtime feed and licenses the data it publishes under CC BY, crediting the author and any changes. The same page says data served from other sources follows that source’s licence; the feed is served by Golemio, the city’s data platform, which states none of its own. Keyless since the catalogue moved it off the X-Access-Token endpoint. Speeds are m/s, checked against movement on 2026-11-07. Route ids are `L` plus a number whose range gives the mode and the line (metro `L991` is A, train `L1004` is S4, ferry `L1801` is P1), read from PID’s GTFS routes.txt. | Pražská integrovaná doprava (PID) / Golemio | +| **Warsaw buses and trams** (mkuran.pl) | Transit layer live vehicles, Warsaw, Poland | Warsaw Open Data Project Usage Terms (https://mkuran.pl/gtfs/). Stated: “The City Hall requires a credit by providing the name Miasto Stołeczne Warszawa, data download date (use the timestamp from the FeedHeader) and link to http://api.um.warszawa.pl.” Positions come from the Warsaw City Hall API, repackaged as GTFS-RT by Mikołaj Kuranowski’s unofficial feed. The credit names the city, links its API and carries the date of the feed timestamp, the three things the terms ask for. Vehicle timestamps ran about two minutes old on 2026-11-07, which the delayed playback absorbs. | Miasto Stołeczne Warszawa (api.um.warszawa.pl) | +| **Bordeaux TBM** (bdx.mecatran.com) | Transit layer live vehicles, Bordeaux, France | Licence Ouverte / Etalab 2.0 (https://transport.data.gouv.fr/datasets/offres-de-services-bus-tram-et-scolaire-au-format-gtfs-netex-gtfs-rt-siri-lite). The quote is the licence field of the national access point’s dataset record (fr-lo is the Licence Ouverte), which asks only for credit. The `apiKey` in the URL is not a credential: it is the same fixed string printed in the open-data listing for everyone. Speeds are m/s. The trams (A–F) and BAT³ boats ride numbered route ids (tram A is `59`), mapped from TBM’s static GTFS; other numbered lines are buses. | Bordeaux Métropole (TBM) | | **Sendai City Bus** (api-public.odpt.org) | Transit layer live vehicles, Sendai, Japan | CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Served by the Open Data Challenge for Public Transportation (ODPT) public API, which needs no key for this feed; the catalogue records CC BY 4.0 as its licence. Vehicle timestamps ran about two minutes old on 2026-11-07. Speeds are m/s. | 仙台市交通局 (Sendai City Transportation Bureau) / ODPT | -| **Poznań buses and trams** (ztm.poznan.pl) | Transit layer live vehicles, Poznań, Poland | ZTM Poznań open-data terms (https://www.ztm.poznan.pl/otwarte-dane/dla-deweloperow/). Stated: “Treści udostępniane są bezwnioskowo i bezpłatnie, na zasadach powszechnego dostępu i stanowią źródło informacji.” Reuse is free on three conditions: name the source, give the date of the last update, and say the data were processed. The credit names ZTM and says processed; the snapshot timestamp is the update date. The feed carries no bearing, so heading comes from movement between fixes. | Zarząd Transportu Miejskiego w Poznaniu (processed) | +| **Poznań buses and trams** (ztm.poznan.pl) | Transit layer live vehicles, Poznań, Poland | ZTM Poznań open-data terms (https://www.ztm.poznan.pl/otwarte-dane/dla-deweloperow/). Stated: “Treści udostępniane są bezwnioskowo i bezpłatnie, na zasadach powszechnego dostępu i stanowią źródło informacji.” Reuse is free on three conditions: name the source, give the date of the last update, and say the data were processed. The credit names ZTM, says processed, and carries the date of the feed timestamp as the update date. The feed carries no bearing, so heading comes from movement between fixes. | Zarząd Transportu Miejskiego w Poznaniu (processed) | | **Gdańsk buses and trams** (ckan2.multimediagdansk.pl) | Transit layer live vehicles, Gdańsk, Poland | CC BY 4.0 (https://dane.gov.pl/pl/dataset/38599,rozklady-jazdy-i-lokalizacja-przystankow-gtfs-rt). The national catalogue (dane.gov.pl) lists this dataset under CC BY 4.0. No bearing; heading comes from movement. Speeds are m/s. | Zarząd Transportu Miejskiego w Gdańsku | | **Edmonton Transit Service** (gtfs.edmonton.ca) | Transit layer live vehicles, Edmonton, AB | City of Edmonton Open Data Agreement (https://www.edmonton.ca/transportation/Web-version2.1-OpenDataAgreement.pdf). The agreement is the same municipal template as Mississauga and Burlington: a licence to use, modify and distribute for any lawful purpose, in any medium. It was read from search excerpts; the PDF itself would not extract here. Route ids are zero-padded. Speeds are m/s. | Contains information licensed under the Open Data Agreement – City of Edmonton | | **Halifax Transit** (gtfs.halifax.ca) | Transit layer live vehicles, Halifax, NS | Open Government Licence – Halifax v1.0 (https://www.halifax.ca/home/open-data/open-data-license), modelled on OGL – Canada 2.0. Stated: “The information provider grants you a worldwide, royalty-free, perpetual, non-exclusive licence to use the Information, including for commercial purposes, subject to the terms below.” No logos or implied endorsement. Speeds are m/s. | Contains information licenced under the Open Government Licence – Halifax | @@ -125,15 +125,15 @@ How to read this: | **Venice ACTV waterbuses** (tpl.actv.it) | Transit layer live vehicles, Venice, Italy | ACTV open-data catalogue (https://actv.avmspa.it/it/content/catalogo-dei-dati-metadati-e-banche-dati-actv). Same catalogue and basis as the ACTV bus feed. | ACTV S.p.A. | | **Adelaide Metro** (gtfs.adelaidemetro.com.au) | Transit layer live vehicles, Adelaide, SA | No licence stated for the realtime feed (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-1772). Official keyless endpoint; the state catalogue page refused automated reads, so no licence is quoted. Same basis as Metro Transit and OVapi. Speeds are m/s. The server picks its encoding from Accept, hence the override. | Adelaide Metro | | **MARTA buses** (gtfs-rt.itsmarta.com) | Transit layer live vehicles, Atlanta, GA | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-1601). Official keyless endpoint; no licence found. Same basis as Metro Transit and OVapi. Speeds are m/s. | MARTA | -| **Denver RTD** (open-data.rtd-denver.com) | Transit layer live vehicles, Denver, CO | RTD GTFS-realtime licence agreement (https://www.rtd-denver.com/business-center/open-spatial-data/gtfs-realtime-license-agreement). RTD links a licence agreement for its realtime feeds; the page refused automated reads (403), so it is not quoted. The feed itself is keyless. Speeds are m/s. | Regional Transportation District (RTD) | +| **Denver RTD** (open-data.rtd-denver.com) | Transit layer live vehicles, Denver, CO | RTD GTFS-realtime licence agreement (https://www.rtd-denver.com/business-center/open-spatial-data/gtfs-realtime-license-agreement). Stated: “RTD hereby grants you non-exclusive, limited and revocable rights to use, reproduce, and redistribute the Data”. Read 2026-11-09: a click-through agreement that RTD may change without notice; it permits redistribution, asks for no credit wording, and bars RTD trademarks from use with the data, so the credit stays plain text. The feed itself is keyless. Speeds are m/s. | Regional Transportation District (RTD) | | **Cluj-Napoca CTP** (cluj-rt-feed.gtfs.ro) | Transit layer live vehicles, Cluj-Napoca, Romania | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2614). Keyless; no licence found. Same basis as Metro Transit and OVapi. | Compania de Transport Public Cluj-Napoca | | **Iași CTP** (iasi-rt-feed.gtfs.ro) | Transit layer live vehicles, Iași, Romania | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2118). Keyless; no licence found. Same basis as Metro Transit and OVapi. | Compania de Transport Public Iași | | **Rzeszów city transport** (mpkrzeszow.pl) | Transit layer live vehicles, Rzeszów, Poland | MPK Rzeszów open data (https://www.mpkrzeszow.pl/otwartedane/). Listed on the operator’s open-data page, which names no licence. No bearing; heading comes from movement. | MPK Rzeszów | | **Málaga EMT** (gtfs.emtmalaga.es) | Transit layer live vehicles, Málaga, Spain | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2213). Keyless; no licence found. Same basis as Metro Transit and OVapi. No bearing; heading comes from movement. | EMT Málaga | | **Carris (Lisbon city)** (gateway.carris.pt) | Transit layer live vehicles, Lisbon, Portugal | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2930). Keyless official gateway; no licence found. Same basis as Metro Transit and OVapi. Carries neither bearing nor speed, and vehicle reports run about a minute old. Route ids append a variant. | Carris | -| **BAS.MY Johor Bahru** (api.data.gov.my) | Transit layer live vehicles, Johor Bahru, Malaysia | No licence stated for the feed (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-3174). Served keyless by Malaysia’s national open-data API; no licence for the feed was found. Same basis as Metro Transit and OVapi. Without the trailing slash the API redirects. Route ids append an operator code. | BAS.MY / data.gov.my | -| **BAS.MY Kota Bharu** (api.data.gov.my) | Transit layer live vehicles, Kota Bharu, Malaysia | No licence stated for the feed (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-3169). Same API and basis as Johor Bahru. | BAS.MY / data.gov.my | -| **Rouen Astuce** (gtfs.bus-tracker.fr) | Transit layer live vehicles, Rouen, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/donnees-statiques-et-temps-reel-du-reseau-astuce-metropole-rouen-normandie). The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); this registry reads it through bus-tracker.fr, an unofficial relay that merges the city’s networks into one GTFS-RT file. Route ids carry the network prefix (`TCAR:`). | Métropole Rouen Normandie (Astuce) / bus-tracker.fr | +| **BAS.MY Johor Bahru** (api.data.gov.my) | Transit layer live vehicles, Johor Bahru, Malaysia | CC BY 4.0 (https://developer.data.gov.my/realtime-api/gtfs-realtime). Stated: “All GTFS Realtime feeds are licensed under CC BY 4.0.” Served keyless by Malaysia’s national open-data API, which caps GTFS Realtime at 4 requests a minute and refreshes positions every 30 seconds, so the proxy caches this feed for 30 seconds. Without the trailing slash the API redirects. Route ids append an operator code. | BAS.MY / data.gov.my | +| **BAS.MY Kota Bharu** (api.data.gov.my) | Transit layer live vehicles, Kota Bharu, Malaysia | CC BY 4.0 (https://developer.data.gov.my/realtime-api/gtfs-realtime). Same API, licence and rate limit as Johor Bahru. | BAS.MY / data.gov.my | +| **Rouen Astuce** (gtfs.bus-tracker.fr) | Transit layer live vehicles, Rouen, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/donnees-statiques-et-temps-reel-du-reseau-astuce-metropole-rouen-normandie). The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); this registry reads it through bus-tracker.fr, an unofficial relay that merges the city’s networks into one GTFS-RT file. Route ids carry the network prefix (`TCAR:`); line 90 is the Métro (a street-running light rail, drawn as a tram) and 99 the Calypso boat. | Métropole Rouen Normandie (Astuce) / bus-tracker.fr | | **Toulon Mistral** (feed-rdtpm-toulon.ratpdev.com) | Transit layer live vehicles, Toulon, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/reseau-de-transport-urbain-de-la-metropole-toulon-provence-mediterranee). Dataset record’s licence field quoted. Speeds are km/h: readings ran 3.5 times the measured movement on 2026-11-07, so the proxy converts them. Route ids are zero-padded. | Métropole Toulon Provence Méditerranée (Mistral) | | **Le Havre LiA** (gtfs.bus-tracker.fr) | Transit layer live vehicles, Le Havre, France | ODbL (https://transport.data.gouv.fr/datasets/reseau-de-transport-en-commun-lia-gtfs-siri). The network publishes under ODbL (dataset record quoted); read through the bus-tracker.fr relay, which converts its SIRI feed to GTFS-RT. The layer draws positions and redistributes no database. Lines A and B are the tramway. | Le Havre Seine Métropole (LiA) / bus-tracker.fr | | **Tours Fil Bleu** (data.filbleu.fr) | Transit layer live vehicles, Tours, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/fil-bleu-syndicat-des-mobilites-gtfs-gtfs-rt). Dataset record’s licence field quoted. | Fil Bleu – Syndicat des Mobilités de Touraine | diff --git a/changelog.d/1628-transit-more-cities.md b/changelog.d/1628-transit-more-cities.md index 3e72ebebb7..24e55817ed 100644 --- a/changelog.d/1628-transit-more-cities.md +++ b/changelog.d/1628-transit-more-cities.md @@ -7,5 +7,8 @@ Edmonton, Halifax and Victoria. Each feed records its licence, or that none is stated, in the registry and DATA_SOURCES.md. Speeds published in km/h (Lisbon, Montpellier, Toulon) are converted to m/s by the proxy; route ids - read as the line on the vehicle; Prague, Bordeaux and Le Havre trams and - Venice waterbuses take their own mode (IMBrandao). + read as the line on the vehicle; Prague metro, trains, trams and ferries, + Bordeaux trams and boats, the Rouen Métro, Le Havre trams and Venice + waterbuses take their own mode. The Warsaw and Poznań credits carry the + data date their terms ask for, and the data.gov.my feeds are fetched at + most twice a minute to stay inside the API's rate limit (IMBrandao). diff --git a/src/data/dataCredits.js b/src/data/dataCredits.js index 82184b6dd3..e0b70558c7 100644 --- a/src/data/dataCredits.js +++ b/src/data/dataCredits.js @@ -660,20 +660,40 @@ export const OSM_PLACES_CREDIT = { /** * Per-feed transit credit, registered the first time that feed's vehicles * render (see `src/data/transitFeeds.js` for the license of each). - * @param {{ id: string, attribution: string, license: string, licenseUrl: string }} feed + * + * Two optional registry fields serve licences that ask for more than a name: + * `sourceUrl` links the attribution to the publisher (Warsaw asks for a link + * to its API), and `creditDated` adds the UTC date of the data, from the feed + * header or else the fetch time (Warsaw and Poznań ask for the download or + * update date). A dated credit is keyed by its date, so a new day registers a + * new line instead of keeping yesterday's. + * @param {{ id: string, attribution: string, license: string, licenseUrl: string, + * sourceUrl?: string, creditDated?: boolean }} feed + * @param {{ feedTimestamp?: number|null, fetchedAt?: number|null }} [snapshot] + * `feedTimestamp` in epoch seconds, `fetchedAt` in epoch ms. * @returns {{ key: string, html: string }} */ -export function transitFeedCredit(feed) { +export function transitFeedCredit(feed, snapshot = null) { const escape = (text) => String(text) .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"'); + const source = feed.sourceUrl + ? `${escape(feed.attribution)}` + : escape(feed.attribution); + const dataMs = Number.isFinite(snapshot?.feedTimestamp) + ? snapshot.feedTimestamp * 1000 + : snapshot?.fetchedAt; + const date = + feed.creditDated === true && Number.isFinite(dataMs) && dataMs > 0 + ? new Date(dataMs).toISOString().slice(0, 10) + : null; return { - key: `transit-${feed.id}`, + key: date ? `transit-${feed.id}-${date}` : `transit-${feed.id}`, html: - `Transit (${escape(feed.attribution)}): ` + + `Transit (${source}${date ? `, data of ${date}` : ''}): ` + `${escape(feed.license)}`, }; } diff --git a/src/data/dataCredits.test.mjs b/src/data/dataCredits.test.mjs index 79305ad6f9..3a83d04d70 100644 --- a/src/data/dataCredits.test.mjs +++ b/src/data/dataCredits.test.mjs @@ -1,6 +1,11 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; -import { DATA_CREDITS, NYC_DOT_DISCLAIMER } from './dataCredits.js'; +import { + DATA_CREDITS, + NYC_DOT_DISCLAIMER, + transitFeedCredit, +} from './dataCredits.js'; +import { getTransitFeed } from './transitFeeds.js'; test('every credit carries a unique key and some markup to render', () => { const keys = DATA_CREDITS.map((entry) => entry.key); @@ -167,3 +172,24 @@ test('the PR #1506 camera packs are credited with their sources and terms', () = /href="https:\/\/www\.river\.go\.jp\//, ); }); + +test('Warsaw and Poznań credits carry the data date their licences ask for', () => { + const warsaw = getTransitFeed('ztm-warszawa'); + // 2026-11-09T06:00:00Z as a GTFS-RT header timestamp (seconds). + const credit = transitFeedCredit(warsaw, { feedTimestamp: 1_794_204_000 }); + assert.match(credit.html, /, data of 2026-11-09\)/); + assert.match(credit.html, /href="http:\/\/api\.um\.warszawa\.pl"/); + assert.equal(credit.key, 'transit-ztm-warszawa-2026-11-09'); + // Without a feed timestamp the fetch time is the download date. + const poznan = transitFeedCredit(getTransitFeed('ztm-poznan'), { + feedTimestamp: null, + fetchedAt: Date.UTC(2026, 10, 10, 12), + }); + assert.match(poznan.html, /data of 2026-11-10/); + // Undated feeds keep one credit line for the session. + const mbta = transitFeedCredit(getTransitFeed('mbta'), { + feedTimestamp: 1_794_204_000, + }); + assert.equal(mbta.key, 'transit-mbta'); + assert.doesNotMatch(mbta.html, /data of/); +}); diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index bb2642d07c..7f2d79a024 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -416,8 +416,6 @@ function routeIdPattern(pattern) { }; } -/** Prague PID: `L125` is line 125. */ -const pidRouteLabel = routeIdPattern(/^L(\d+)$/); /** Zero-padded numbers (Edmonton `005`, Toulon `0002`, Bordeaux `01`). */ const unpaddedRouteLabel = routeIdPattern(/^0+(\d+\w*)$/); /** Turin GTT appends `U` (urban) to the line: `10NU` is night line 10N. */ @@ -434,35 +432,110 @@ const busTrackerRouteLabel = routeIdPattern(/^[A-Z]+:(.+)$/); const mybasJohorRouteLabel = routeIdPattern(/^(.+?)CWLMYJB$/); /** - * Le Havre LiA runs its two tram lines as A and B; every other line is a bus. + * Le Havre LiA runs its two tram lines as A and B and the funicular as + * `FUNI`; every other line is a bus. * @param {string|null} routeId * @returns {string} */ function liaRouteMode(routeId) { if (!routeId) return 'unknown'; + if (routeId === 'FUNI') return 'rail'; return /^(?:[A-Z]+:)?[AB]$/.test(routeId) ? 'tram' : 'bus'; } /** - * Prague PID numbers its day and night trams below 100 and its buses from 100 - * up; anything else (rail, ferries, the funicular) is left unresolved. - * @param {string|null} routeId - * @returns {string} + * Rouen Astuce lines that are not buses, by bus-tracker.fr route id, from the + * relay's own `astuce-tcar.zip` routes.txt (checked 2026-11-09): line 90 is + * the Métro (GTFS type 1, a light rail that runs mostly on the street) and 99 + * the Calypso river boat. */ -function pidRouteMode(routeId) { - const match = /^L(\d+)$/.exec(routeId ?? ''); - if (!match) return 'unknown'; - return Number(match[1]) < 100 ? 'tram' : 'bus'; +const ASTUCE_ROUTES = Object.freeze({ + 'TCAR:90': Object.freeze({ mode: 'tram', label: 'Métro' }), + 'TCAR:99': Object.freeze({ mode: 'ferry', label: 'Calypso' }), +}); + +/** @param {string|null} routeId @returns {string} */ +function astuceRouteMode(routeId) { + if (!routeId) return 'unknown'; + return ASTUCE_ROUTES[routeId]?.mode ?? 'bus'; +} + +/** `TCAR:93` is Rouen line 93; the Métro and Calypso keep their names. */ +function astuceRouteLabel(routeId) { + return ASTUCE_ROUTES[routeId ?? '']?.label ?? busTrackerRouteLabel(routeId); } /** - * Bordeaux TBM runs trams on lettered lines A–D; every numbered line is a bus. + * Prague PID route ids are `L` plus a number whose range says what runs it, + * per PID's GTFS routes.txt (data.pid.cz, checked 2026-11-09): 1–99 trams + * (50–59 trolleybuses, 49 the Petřín funicular `LD`), 100–990 buses (the + * 800s are the X replacement lines, `L803` is X3), 991–993 metro A–C, + * 1000s and 1100s the S and R trains (`L1004` is S4, `L1109` R9), the rest + * of 1200–1399 other trains, 1700s town buses, 1800s the P ferries, and from + * 2000 more buses (`L2841` is 841). A label the range cannot give stays the + * route id. + * @param {string|null} routeId + * @returns {{mode: string, label: string|null}} + */ +function pidRoute(routeId) { + const match = /^L(\d+)$/.exec(routeId ?? ''); + if (!match) return { mode: 'unknown', label: routeId }; + const n = Number(match[1]); + if (n === 49) return { mode: 'rail', label: 'LD' }; + if (n >= 50 && n <= 59) return { mode: 'bus', label: String(n) }; + if (n < 100) return { mode: 'tram', label: String(n) }; + if (n >= 800 && n < 900) return { mode: 'bus', label: `X${n - 800}` }; + if (n < 991) return { mode: 'bus', label: String(n) }; + if (n <= 993) return { mode: 'subway', label: 'ABC'[n - 991] }; + if (n >= 1000 && n < 1100) return { mode: 'rail', label: `S${n - 1000}` }; + if (n >= 1100 && n < 1200) return { mode: 'rail', label: `R${n - 1100}` }; + if (n >= 1200 && n < 1400) return { mode: 'rail', label: routeId }; + if (n >= 1800 && n < 1900) return { mode: 'ferry', label: `P${n - 1800}` }; + if (n >= 2800 && n < 2900) return { mode: 'bus', label: String(n - 2000) }; + return { mode: n >= 1700 ? 'bus' : 'unknown', label: routeId }; +} + +/** @param {string|null} routeId @returns {string} */ +function pidRouteMode(routeId) { + return pidRoute(routeId).mode; +} + +/** @param {string|null} routeId @returns {string|null} */ +function pidRouteLabel(routeId) { + return pidRoute(routeId).label; +} + +/** + * Bordeaux TBM tram and boat lines by route id, from TBM's static GTFS + * routes.txt (checked 2026-11-09): the trams are numbered ids, not letters. + */ +const TBM_TRAM_LINES = Object.freeze({ + 59: 'A', + 60: 'B', + 61: 'C', + 62: 'D', + 163: 'E', + 164: 'F', +}); +const TBM_BOAT_LINES = new Set(['951', '952', '953']); + +/** + * Bordeaux TBM: trams A–F and the BAT³ river shuttles; every other line is a + * bus. * @param {string|null} routeId * @returns {string} */ function tbmRouteMode(routeId) { if (!routeId) return 'unknown'; - return /^[A-D]$/.test(routeId) ? 'tram' : 'bus'; + if (Object.hasOwn(TBM_TRAM_LINES, routeId)) return 'tram'; + return TBM_BOAT_LINES.has(routeId) ? 'ferry' : 'bus'; +} + +/** `59` is tram A; zero-padded bus ids lose their padding (`01` is 1). */ +function tbmRouteLabel(routeId) { + return Object.hasOwn(TBM_TRAM_LINES, routeId ?? '') + ? TBM_TRAM_LINES[routeId] + : unpaddedRouteLabel(routeId); } /** @@ -491,10 +564,14 @@ function transitFeed(fields) { * url: string, headers?: Record, * license: string, licenseUrl: string, attribution: string, * defaultMode: string, routeMode?: (routeId: string|null) => string, - * speedUnit?: 'km/h', + * speedUnit?: 'km/h', refreshMs?: number, sourceUrl?: string, + * creditDated?: boolean, * }>>} * `speedUnit` marks a feed that publishes km/h where the spec requires m/s; - * the proxy converts it before the snapshot leaves the server. + * the proxy converts it before the snapshot leaves the server. `refreshMs` + * stretches the proxy's cache for an upstream that rate-limits below one + * request per 15 s TTL. `sourceUrl` and `creditDated` add a link and a date + * to the credit for licences that ask for them (`transitFeedCredit`). */ export const TRANSIT_FEED_REGISTRY = Object.freeze([ Object.freeze({ @@ -884,7 +961,7 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ defaultMode: 'bus', routeLabel: rioRouteLabel, }), - Object.freeze({ + transitFeed({ id: 'zditm-szczecin', name: 'Szczecin buses and trams', operator: @@ -892,40 +969,38 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ region: 'Szczecin, Poland', // Every vehicle in a 2026-11-05 snapshot sat between 53.34–53.55 N and // 14.44–14.77 E, inside 20 km of this point. - center: Object.freeze({ lat: 53.44, lon: 14.56 }), + center: { lat: 53.44, lon: 14.56 }, loadRadiusKm: 25, url: 'https://www.zditm.szczecin.pl/storage/gtfs/gtfs-rt-vehicles.pb', license: 'CC0 1.0', licenseUrl: 'https://www.zditm.szczecin.pl/en/zditm/for-developers', attribution: 'Zarząd Dróg i Transportu Miejskiego w Szczecinie (ZDiTM Szczecin)', - defaultEnabled: true, - terms: Object.freeze({ + terms: { quote: 'The data are provided free of charge under the CC0 1.0 licence, for use in any context, with no prior notification required.', note: 'CC0 needs no credit; it is given anyway as a courtesy. ZDiTM gives no guarantee of accuracy or completeness. The developer page says the feed updates every minute; measured on 2026-11-05 the file changed about every 20 seconds, with vehicle timestamps up to 50 seconds old. Speeds are m/s: checked against vehicle movement between two snapshots. The feed carries no route id at all, so every vehicle takes the feed default mode even though the city also runs trams.', - }), + }, defaultMode: 'bus', }), - Object.freeze({ + transitFeed({ id: 'carris-metropolitana-lisboa', name: 'Carris Metropolitana', operator: 'Carris Metropolitana (TML), Lisbon Metropolitan Area', region: 'Lisbon Metropolitan Area, Portugal', // Every vehicle in a 2026-11-07 snapshot, from Mafra to Setúbal, sat // between 38.47–39.00 N and 9.47–8.79 W, inside 40 km of this point. - center: Object.freeze({ lat: 38.73, lon: -9.13 }), + center: { lat: 38.73, lon: -9.13 }, loadRadiusKm: 45, url: 'https://api.carrismetropolitana.pt/v2/vehicles.pb', license: 'No separate licence for the realtime feed', licenseUrl: 'https://github.com/carrismetropolitana/api', attribution: 'Carris Metropolitana', - defaultEnabled: true, - terms: Object.freeze({ + terms: { quote: 'GET /vehicles.pb — Returns vehicle locations in Protobuf format, following the GTFS-RT Vehicle Locations standard.', note: 'The operator publishes this feed keyless and documented for developers in its public API repository, but states no licence for the realtime endpoint; its static GTFS (github.com/carrismetropolitana/gtfs) is CC BY 4.0. Credited as a courtesy, on the same basis as the Metro Transit and OVapi feeds; switch it off if Carris objects. The quote above is the API README, not a licence. `/vehicles.pb` answers with a 307 to `/v2/vehicles.pb`, so the registry points at the target. Speeds are km/h, not the m/s the spec requires: 2026-11-07 readings of 31–33 matched 6–9 m/s of measured movement, so the proxy converts them. Vehicle reports arrive every 30–50 seconds. Route ids are the GTFS route id inside an area prefix and are read as the line number.', - }), + }, defaultMode: 'bus', routeLabel: carrisMetropolitanaRouteLabel, speedUnit: 'km/h', @@ -946,7 +1021,7 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ terms: { quote: 'Data, která lze stáhnout přímo zde z webu, jsou stejně jako celý obsah webu opatřena licencí CC-BY', - note: 'The PID open-data page lists this realtime feed and licenses the data it publishes under CC BY, crediting the author and any changes. The same page says data served from other sources follows that source’s licence; the feed is served by Golemio, the city’s data platform, which states none of its own. Keyless since the catalogue moved it off the X-Access-Token endpoint. Speeds are m/s, checked against movement on 2026-11-07. Route ids are `L` plus the line number; lines below 100 are trams.', + note: 'The PID open-data page lists this realtime feed and licenses the data it publishes under CC BY, crediting the author and any changes. The same page says data served from other sources follows that source’s licence; the feed is served by Golemio, the city’s data platform, which states none of its own. Keyless since the catalogue moved it off the X-Access-Token endpoint. Speeds are m/s, checked against movement on 2026-11-07. Route ids are `L` plus a number whose range gives the mode and the line (metro `L991` is A, train `L1004` is S4, ferry `L1801` is P1); `pidRoute` holds the table, read from PID’s GTFS routes.txt on 2026-11-09.', }, defaultMode: 'bus', routeLabel: pidRouteLabel, @@ -963,10 +1038,12 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ license: 'Warsaw Open Data Project Usage Terms', licenseUrl: 'https://mkuran.pl/gtfs/', attribution: 'Miasto Stołeczne Warszawa (api.um.warszawa.pl)', + sourceUrl: 'http://api.um.warszawa.pl', + creditDated: true, terms: { quote: 'The City Hall requires a credit by providing the name Miasto Stołeczne Warszawa, data download date (use the timestamp from the FeedHeader) and link to http://api.um.warszawa.pl.', - note: 'Positions come from the Warsaw City Hall API, repackaged as GTFS-RT by Mikołaj Kuranowski’s unofficial feed. The credit names the city and its API; the download date it asks for is the feed timestamp the layer already shows with each snapshot. Vehicle timestamps ran about two minutes old on 2026-11-07, which the delayed playback absorbs.', + note: 'Positions come from the Warsaw City Hall API, repackaged as GTFS-RT by Mikołaj Kuranowski’s unofficial feed. The credit names the city, links its API (`sourceUrl`) and carries the date of the feed timestamp (`creditDated`), the three things the terms ask for. Vehicle timestamps ran about two minutes old on 2026-11-07, which the delayed playback absorbs.', }, defaultMode: 'bus', }), @@ -984,10 +1061,10 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ attribution: 'Bordeaux Métropole (TBM)', terms: { quote: 'licence: fr-lo', - note: 'The quote is the licence field of the national access point’s dataset record (fr-lo is the Licence Ouverte), which asks only for credit. The `apiKey` in the URL is not a credential: it is the same fixed string printed in the open-data listing for everyone. Speeds are m/s. Trams run on lettered lines A–D; numbered lines are buses.', + note: 'The quote is the licence field of the national access point’s dataset record (fr-lo is the Licence Ouverte), which asks only for credit. The `apiKey` in the URL is not a credential: it is the same fixed string printed in the open-data listing for everyone. Speeds are m/s. The trams (A–F) and BAT³ boats ride numbered route ids (tram A is `59`), so `tbmRouteMode` and `tbmRouteLabel` map them from TBM’s static GTFS; other numbered lines are buses.', }, defaultMode: 'bus', - routeLabel: unpaddedRouteLabel, + routeLabel: tbmRouteLabel, routeMode: tbmRouteMode, }), transitFeed({ @@ -1018,10 +1095,11 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ license: 'ZTM Poznań open-data terms', licenseUrl: 'https://www.ztm.poznan.pl/otwarte-dane/dla-deweloperow/', attribution: 'Zarząd Transportu Miejskiego w Poznaniu (processed)', + creditDated: true, terms: { quote: 'Treści udostępniane są bezwnioskowo i bezpłatnie, na zasadach powszechnego dostępu i stanowią źródło informacji.', - note: 'Reuse is free on three conditions: name the source, give the date of the last update, and say the data were processed. The credit names ZTM and says processed; the snapshot timestamp is the update date. The feed carries no bearing, so heading comes from movement between fixes.', + note: 'Reuse is free on three conditions: name the source, give the date of the last update, and say the data were processed. The credit names ZTM, says processed, and carries the date of the feed timestamp (`creditDated`) as the update date. The feed carries no bearing, so heading comes from movement between fixes.', }, defaultMode: 'bus', }), @@ -1295,7 +1373,9 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ 'https://www.rtd-denver.com/business-center/open-spatial-data/gtfs-realtime-license-agreement', attribution: 'Regional Transportation District (RTD)', terms: { - note: 'RTD links a licence agreement for its realtime feeds; the page refused automated reads (403), so it is not quoted. The feed itself is keyless. Speeds are m/s.', + quote: + 'RTD hereby grants you non-exclusive, limited and revocable rights to use, reproduce, and redistribute the Data', + note: 'Read 2026-11-09. The agreement is a click-through (“By clicking to download the Data files, you confirm that you have read and agree”) that RTD may change without notice; it permits redistribution, asks for no credit wording, and bars RTD trademarks from being used with the data, so the credit stays plain text. The feed itself is keyless. Speeds are m/s.', }, defaultMode: 'bus', }), @@ -1388,11 +1468,16 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ center: { lat: 1.51, lon: 103.75 }, loadRadiusKm: 35, url: 'https://api.data.gov.my/gtfs-realtime/vehicle-position/mybas-johor/', - license: 'No licence stated for the feed', - licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-3174', + license: 'CC BY 4.0', + licenseUrl: 'https://developer.data.gov.my/realtime-api/gtfs-realtime', attribution: 'BAS.MY / data.gov.my', + // data.gov.my allows 4 GTFS-Realtime requests a minute and refreshes + // vehicle positions every 30 seconds, so the proxy asks half as often as + // the default 15 s TTL would. + refreshMs: 30_000, terms: { - note: 'Served keyless by Malaysia’s national open-data API; no licence for the feed was found. Same basis as Metro Transit and OVapi. Without the trailing slash the API redirects. Route ids append an operator code.', + quote: 'All GTFS Realtime feeds are licensed under CC BY 4.0.', + note: 'Served keyless by Malaysia’s national open-data API (developer.data.gov.my, read 2026-11-09). Its rate-limit page caps GTFS Realtime at 4 requests a minute and answers 429 above that; the feed updates every 30 seconds, hence `refreshMs`. Without the trailing slash the API redirects. Route ids append an operator code.', }, defaultMode: 'bus', routeLabel: mybasJohorRouteLabel, @@ -1406,10 +1491,14 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ center: { lat: 6.06, lon: 102.22 }, loadRadiusKm: 60, url: 'https://api.data.gov.my/gtfs-realtime/vehicle-position/mybas-kota-bharu/', - license: 'No licence stated for the feed', - licenseUrl: 'https://mobilitydatabase.org/feeds/gtfs_rt/mdb-3169', + license: 'CC BY 4.0', + licenseUrl: 'https://developer.data.gov.my/realtime-api/gtfs-realtime', attribution: 'BAS.MY / data.gov.my', - terms: { note: 'Same API and basis as Johor Bahru.' }, + refreshMs: 30_000, + terms: { + quote: 'All GTFS Realtime feeds are licensed under CC BY 4.0.', + note: 'Same API, licence and rate limit as Johor Bahru.', + }, defaultMode: 'bus', }), transitFeed({ @@ -1426,10 +1515,11 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ attribution: 'Métropole Rouen Normandie (Astuce) / bus-tracker.fr', terms: { quote: 'licence: lov2', - note: 'The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); this registry reads it through bus-tracker.fr, an unofficial relay that merges the city’s networks into one GTFS-RT file. Route ids carry the network prefix (`TCAR:`).', + note: 'The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); this registry reads it through bus-tracker.fr, an unofficial relay that merges the city’s networks into one GTFS-RT file. Route ids carry the network prefix (`TCAR:`); `TCAR:90` is the Métro (a street-running light rail, drawn as a tram) and `TCAR:99` the Calypso boat.', }, defaultMode: 'bus', - routeLabel: busTrackerRouteLabel, + routeLabel: astuceRouteLabel, + routeMode: astuceRouteMode, }), transitFeed({ id: 'mpm-toulon', diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index 8afe6ea8b5..3867b12257 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -701,7 +701,6 @@ test('trams, waterbuses and buses are told apart where the ids allow it', () => const mode = (id, routeId) => transitModeFor(getTransitFeed(id), routeId); assert.equal(mode('pid-praha', 'L22'), 'tram'); assert.equal(mode('pid-praha', 'L135'), 'bus'); - assert.equal(mode('tbm-bordeaux', 'A'), 'tram'); assert.equal(mode('tbm-bordeaux', '16'), 'bus'); assert.equal(mode('lia-le-havre', 'B'), 'tram'); assert.equal(mode('lia-le-havre', '3'), 'bus'); @@ -719,3 +718,59 @@ test('feeds that publish km/h are marked for conversion, and only those', () => 'tam-montpellier', ]); }); + +// Route ids as the live feeds and the operators' own GTFS routes.txt carried +// them on 2026-11-09: the ranges and numbered tram ids are not guessable from +// the line names riders see. +test('Prague route-id ranges give metro, trains, ferries and trolleybuses their mode', () => { + const feed = getTransitFeed('pid-praha'); + const read = (routeId) => [ + transitModeFor(feed, routeId), + transitRouteLabel(feed, routeId), + ]; + assert.deepEqual(read('L22'), ['tram', '22']); + assert.deepEqual(read('L58'), ['bus', '58'], 'trolleybus'); + assert.deepEqual(read('L49'), ['rail', 'LD'], 'Petřín funicular'); + assert.deepEqual(read('L135'), ['bus', '135']); + assert.deepEqual(read('L803'), ['bus', 'X3']); + assert.deepEqual(read('L991'), ['subway', 'A']); + assert.deepEqual(read('L993'), ['subway', 'C']); + assert.deepEqual(read('L1004'), ['rail', 'S4']); + assert.deepEqual(read('L1109'), ['rail', 'R9']); + assert.deepEqual(read('L1204'), ['rail', 'L1204'], 'no label to derive'); + assert.deepEqual(read('L1801'), ['ferry', 'P1']); + assert.deepEqual(read('L1703'), ['bus', 'L1703']); + assert.deepEqual(read('L2841'), ['bus', '841']); + assert.deepEqual(read('S4'), ['bus', 'S4'], 'unknown ids keep the default'); +}); + +test('Bordeaux trams ride numbered route ids and keep their letters', () => { + const feed = getTransitFeed('tbm-bordeaux'); + for (const [routeId, line] of [ + ['59', 'A'], + ['62', 'D'], + ['163', 'E'], + ]) { + assert.equal(transitModeFor(feed, routeId), 'tram', routeId); + assert.equal(transitRouteLabel(feed, routeId), line); + } + assert.equal(transitModeFor(feed, '952'), 'ferry'); + assert.equal(transitModeFor(feed, '01'), 'bus'); + assert.equal(transitRouteLabel(feed, '01'), '1'); +}); + +test('Rouen Métro and Calypso are not buses', () => { + const feed = getTransitFeed('astuce-rouen'); + assert.equal(transitModeFor(feed, 'TCAR:90'), 'tram'); + assert.equal(transitRouteLabel(feed, 'TCAR:90'), 'Métro'); + assert.equal(transitModeFor(feed, 'TCAR:99'), 'ferry'); + assert.equal(transitModeFor(feed, 'TCAR:93'), 'bus'); + assert.equal(transitRouteLabel(feed, 'TAE:F'), 'F'); + assert.equal(transitModeFor(getTransitFeed('lia-le-havre'), 'FUNI'), 'rail'); +}); + +test('data.gov.my feeds ask the proxy for no more than its 4 a minute', () => { + for (const id of ['mybas-johor', 'mybas-kota-bharu']) { + assert.ok(getTransitFeed(id).refreshMs >= 30_000, id); + } +}); diff --git a/src/data/transitProxy.js b/src/data/transitProxy.js index 68280d1325..6b328e5a51 100644 --- a/src/data/transitProxy.js +++ b/src/data/transitProxy.js @@ -268,17 +268,32 @@ export function buildTransitSnapshot(feed, bytes, now = Date.now()) { }; } +/** + * Fresh window for one feed's cached snapshot: the shared TTL, stretched by a + * registry `refreshMs` for upstreams that rate-limit below one request per + * TTL (data.gov.my allows 4 a minute). Never shorter than the shared TTL. + * @param {{ refreshMs?: number }|null|undefined} feed Registry entry. + * @returns {number} + */ +export function transitFeedTtlMs(feed) { + const refresh = feed?.refreshMs; + return Number.isFinite(refresh) && refresh > TRANSIT_PROXY_TTL_MS + ? refresh + : TRANSIT_PROXY_TTL_MS; +} + /** * Classify a cache entry for the request policy. * @param {{ at: number }|null|undefined} entry Cached snapshot (`at` = fetch ms). * @param {number} now + * @param {number} [ttlMs] Fresh window; `transitFeedTtlMs(feed)` for a feed. * @returns {'none'|'fresh'|'stale'|'expired'} */ -export function transitCacheState(entry, now) { +export function transitCacheState(entry, now, ttlMs = TRANSIT_PROXY_TTL_MS) { if (!entry || !Number.isFinite(entry.at)) return 'none'; const age = now - entry.at; if (age < 0) return 'fresh'; - if (age < TRANSIT_PROXY_TTL_MS) return 'fresh'; + if (age < ttlMs) return 'fresh'; if (age < TRANSIT_PROXY_STALE_MAX_MS) return 'stale'; return 'expired'; } diff --git a/src/data/transitProxy.test.mjs b/src/data/transitProxy.test.mjs index 1c9f6679fe..63f950f582 100644 --- a/src/data/transitProxy.test.mjs +++ b/src/data/transitProxy.test.mjs @@ -12,6 +12,7 @@ import { repairVehicleTimestamps, resolveTransitRoute, transitCacheState, + transitFeedTtlMs, transitRedirectDecision, transitResponseHeaders, transitUpstreamHeaders, @@ -406,3 +407,14 @@ test('Adelaide asks for */* because a protobuf Accept gets base64 text back', () /protobuf/, ); }); + +test('a feed refreshMs stretches its fresh window, never shortens it', () => { + const johor = getTransitFeed('mybas-johor'); + assert.equal(transitFeedTtlMs(johor), 30_000); + assert.equal(transitFeedTtlMs(getTransitFeed('mbta')), TRANSIT_PROXY_TTL_MS); + assert.equal(transitFeedTtlMs({ refreshMs: 1_000 }), TRANSIT_PROXY_TTL_MS); + const now = 1_000_000; + const entry = { at: now - 20_000 }; + assert.equal(transitCacheState(entry, now), 'stale'); + assert.equal(transitCacheState(entry, now, transitFeedTtlMs(johor)), 'fresh'); +}); diff --git a/src/layers/transit/ingestion.js b/src/layers/transit/ingestion.js index 22b179120d..afce6a4aaf 100644 --- a/src/layers/transit/ingestion.js +++ b/src/layers/transit/ingestion.js @@ -401,7 +401,13 @@ export function createIngestion({ state, services, parts, source }) { ); } if (state._viewer) - registerDynamicCredit(state._viewer, transitFeedCredit(feed)); + registerDynamicCredit( + state._viewer, + transitFeedCredit(feed, { + feedTimestamp: snapshot?.feedTimestamp, + fetchedAt, + }), + ); if ( state._selectedKey && state._vehicles.get(state._selectedKey)?.feedId === feed.id diff --git a/src/sources/transitService.js b/src/sources/transitService.js index 1b6b46d783..328b827119 100644 --- a/src/sources/transitService.js +++ b/src/sources/transitService.js @@ -25,6 +25,7 @@ import { nextTransitBackoffMs, resolveTransitRoute, transitCacheState, + transitFeedTtlMs, transitRedirectDecision, transitResponseHeaders, transitUpstreamHeaders, @@ -266,7 +267,7 @@ export function createTransitService({ fetchImpl = fetch } = {}) { ); } const cached = cache.get(feed.id); - const state = transitCacheState(cached, now); + const state = transitCacheState(cached, now, transitFeedTtlMs(feed)); if (state === 'fresh') { return reply( 200, From 2c1b2c278ddabf7eda6536558d60a37a6d52ac16 Mon Sep 17 00:00:00 2001 From: Said Turksever Date: Mon, 9 Nov 2026 13:58:20 +0000 Subject: [PATCH 42/61] fix(transit): read Rouen and Le Havre from the operators' own feeds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rouen now reads Métropole Rouen Normandie's TCAR vehicle feed (api.mrn.cityway.fr) and Le Havre LiA's own GTFS-RT (opendata.transports-lia.fr), both listed in their transport.data.gouv.fr records, instead of the unofficial bus-tracker.fr relay. LiA ids carry an 8- prefix, so a new liaRouteLabel strips it and liaRouteMode reads the line. --- DATA_SOURCES.md | 4 ++-- src/data/transitFeeds.js | 39 ++++++++++++++++++---------------- src/data/transitFeeds.test.mjs | 12 +++++++---- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index a302235fde..31753ade52 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -133,9 +133,9 @@ How to read this: | **Carris (Lisbon city)** (gateway.carris.pt) | Transit layer live vehicles, Lisbon, Portugal | No licence stated (https://mobilitydatabase.org/feeds/gtfs_rt/mdb-2930). Keyless official gateway; no licence found. Same basis as Metro Transit and OVapi. Carries neither bearing nor speed, and vehicle reports run about a minute old. Route ids append a variant. | Carris | | **BAS.MY Johor Bahru** (api.data.gov.my) | Transit layer live vehicles, Johor Bahru, Malaysia | CC BY 4.0 (https://developer.data.gov.my/realtime-api/gtfs-realtime). Stated: “All GTFS Realtime feeds are licensed under CC BY 4.0.” Served keyless by Malaysia’s national open-data API, which caps GTFS Realtime at 4 requests a minute and refreshes positions every 30 seconds, so the proxy caches this feed for 30 seconds. Without the trailing slash the API redirects. Route ids append an operator code. | BAS.MY / data.gov.my | | **BAS.MY Kota Bharu** (api.data.gov.my) | Transit layer live vehicles, Kota Bharu, Malaysia | CC BY 4.0 (https://developer.data.gov.my/realtime-api/gtfs-realtime). Same API, licence and rate limit as Johor Bahru. | BAS.MY / data.gov.my | -| **Rouen Astuce** (gtfs.bus-tracker.fr) | Transit layer live vehicles, Rouen, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/donnees-statiques-et-temps-reel-du-reseau-astuce-metropole-rouen-normandie). The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); this registry reads it through bus-tracker.fr, an unofficial relay that merges the city’s networks into one GTFS-RT file. Route ids carry the network prefix (`TCAR:`); line 90 is the Métro (a street-running light rail, drawn as a tram) and 99 the Calypso boat. | Métropole Rouen Normandie (Astuce) / bus-tracker.fr | +| **Rouen Astuce** (api.mrn.cityway.fr) | Transit layer live vehicles, Rouen, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/donnees-statiques-et-temps-reel-du-reseau-astuce-metropole-rouen-normandie). The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); and this is its own TCAR vehicle feed from that record; the suburban TAE and TNI networks are separate feeds and are not read. Route ids carry the network prefix (`TCAR:`); line 90 is the Métro (a street-running light rail, drawn as a tram) and 99 the Calypso boat. | Métropole Rouen Normandie (Astuce) | | **Toulon Mistral** (feed-rdtpm-toulon.ratpdev.com) | Transit layer live vehicles, Toulon, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/reseau-de-transport-urbain-de-la-metropole-toulon-provence-mediterranee). Dataset record’s licence field quoted. Speeds are km/h: readings ran 3.5 times the measured movement on 2026-11-07, so the proxy converts them. Route ids are zero-padded. | Métropole Toulon Provence Méditerranée (Mistral) | -| **Le Havre LiA** (gtfs.bus-tracker.fr) | Transit layer live vehicles, Le Havre, France | ODbL (https://transport.data.gouv.fr/datasets/reseau-de-transport-en-commun-lia-gtfs-siri). The network publishes under ODbL (dataset record quoted); read through the bus-tracker.fr relay, which converts its SIRI feed to GTFS-RT. The layer draws positions and redistributes no database. Lines A and B are the tramway. | Le Havre Seine Métropole (LiA) / bus-tracker.fr | +| **Le Havre LiA** (opendata.transports-lia.fr) | Transit layer live vehicles, Le Havre, France | ODbL (https://transport.data.gouv.fr/datasets/reseau-de-transport-en-commun-lia-gtfs-siri). The network publishes under ODbL (dataset record quoted); and this is its own GTFS-RT vehicle feed from that record; route ids carry the network prefix `8-`. The layer draws positions and redistributes no database. Lines A and B are the tramway. | Le Havre Seine Métropole (LiA) | | **Tours Fil Bleu** (data.filbleu.fr) | Transit layer live vehicles, Tours, France | Licence Ouverte 2.0 (https://transport.data.gouv.fr/datasets/fil-bleu-syndicat-des-mobilites-gtfs-gtfs-rt). Dataset record’s licence field quoted. | Fil Bleu – Syndicat des Mobilités de Touraine | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 7f2d79a024..e9aeb4359a 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -426,11 +426,14 @@ const actvRouteLabel = routeIdPattern(/^(.+)_[A-Z]{2}$/); const bcTransitRouteLabel = routeIdPattern(/^(.+)-VIC$/); /** Carris (Lisbon city) appends a variant: `172_1` is route 172. */ const carrisRouteLabel = routeIdPattern(/^(\w+)_\d+$/); -/** bus-tracker.fr prefixes the network: `TCAR:93` is Rouen line 93. */ -const busTrackerRouteLabel = routeIdPattern(/^[A-Z]+:(.+)$/); +/** Astuce prefixes the network: `TCAR:93` is Rouen line 93. */ +const astuceNetworkLabel = routeIdPattern(/^[A-Z]+:(.+)$/); /** BAS.MY Johor appends a fixed operator code: `J33CWLMYJB` is route J33. */ const mybasJohorRouteLabel = routeIdPattern(/^(.+?)CWLMYJB$/); +/** LiA prefixes its network: `8-C3` is Le Havre line C3, `8-09` line 9. */ +const liaRouteLabel = routeIdPattern(/^8-0*(\w.*)$/); + /** * Le Havre LiA runs its two tram lines as A and B and the funicular as * `FUNI`; every other line is a bus. @@ -439,15 +442,15 @@ const mybasJohorRouteLabel = routeIdPattern(/^(.+?)CWLMYJB$/); */ function liaRouteMode(routeId) { if (!routeId) return 'unknown'; - if (routeId === 'FUNI') return 'rail'; - return /^(?:[A-Z]+:)?[AB]$/.test(routeId) ? 'tram' : 'bus'; + const line = liaRouteLabel(routeId); + if (line === 'FUNI') return 'rail'; + return /^[AB]$/.test(line) ? 'tram' : 'bus'; } /** - * Rouen Astuce lines that are not buses, by bus-tracker.fr route id, from the - * relay's own `astuce-tcar.zip` routes.txt (checked 2026-11-09): line 90 is - * the Métro (GTFS type 1, a light rail that runs mostly on the street) and 99 - * the Calypso river boat. + * Rouen Astuce lines that are not buses, by route id, from the TCAR + * routes.txt (checked 2026-11-09): line 90 is the Métro (GTFS type 1, a light + * rail that runs mostly on the street) and 99 the Calypso river boat. */ const ASTUCE_ROUTES = Object.freeze({ 'TCAR:90': Object.freeze({ mode: 'tram', label: 'Métro' }), @@ -462,7 +465,7 @@ function astuceRouteMode(routeId) { /** `TCAR:93` is Rouen line 93; the Métro and Calypso keep their names. */ function astuceRouteLabel(routeId) { - return ASTUCE_ROUTES[routeId ?? '']?.label ?? busTrackerRouteLabel(routeId); + return ASTUCE_ROUTES[routeId ?? '']?.label ?? astuceNetworkLabel(routeId); } /** @@ -1504,18 +1507,18 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ transitFeed({ id: 'astuce-rouen', name: 'Rouen Astuce', - operator: 'Métropole Rouen Normandie (Astuce), relayed by bus-tracker.fr', + operator: 'Métropole Rouen Normandie (Astuce), réseau TCAR', region: 'Rouen, France', center: { lat: 49.44, lon: 1.1 }, loadRadiusKm: 20, - url: 'https://gtfs.bus-tracker.fr/gtfs-rt/tcar/?tcar=1&tae=1&tni=1', + url: 'https://api.mrn.cityway.fr/dataflow/vehicle-tc-tr/download?provider=TCAR&dataFormat=gtfs-rt', license: 'Licence Ouverte 2.0', licenseUrl: 'https://transport.data.gouv.fr/datasets/donnees-statiques-et-temps-reel-du-reseau-astuce-metropole-rouen-normandie', - attribution: 'Métropole Rouen Normandie (Astuce) / bus-tracker.fr', + attribution: 'Métropole Rouen Normandie (Astuce)', terms: { quote: 'licence: lov2', - note: 'The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted); this registry reads it through bus-tracker.fr, an unofficial relay that merges the city’s networks into one GTFS-RT file. Route ids carry the network prefix (`TCAR:`); `TCAR:90` is the Métro (a street-running light rail, drawn as a tram) and `TCAR:99` the Calypso boat.', + note: 'The metropolis publishes its realtime data under the Licence Ouverte (dataset record quoted), and this is its own TCAR vehicle feed from that record (178 vehicles on 2026-11-09). The suburban TAE and TNI networks are separate feeds in the same record and are not read here. Route ids carry the network prefix (`TCAR:`); `TCAR:90` is the Métro (a street-running light rail, drawn as a tram) and `TCAR:99` the Calypso boat.', }, defaultMode: 'bus', routeLabel: astuceRouteLabel, @@ -1544,21 +1547,21 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ transitFeed({ id: 'lia-le-havre', name: 'Le Havre LiA', - operator: 'Le Havre Seine Métropole (LiA), relayed by bus-tracker.fr', + operator: 'Le Havre Seine Métropole (LiA)', region: 'Le Havre, France', center: { lat: 49.49, lon: 0.11 }, loadRadiusKm: 18, - url: 'https://gtfs.bus-tracker.fr/gtfs-rt/lia/vehicle-positions', + url: 'https://opendata.transports-lia.fr/gtfs-rt/VehiclePosition.pb', license: 'ODbL', licenseUrl: 'https://transport.data.gouv.fr/datasets/reseau-de-transport-en-commun-lia-gtfs-siri', - attribution: 'Le Havre Seine Métropole (LiA) / bus-tracker.fr', + attribution: 'Le Havre Seine Métropole (LiA)', terms: { quote: 'licence: odc-odbl', - note: 'The network publishes under ODbL (dataset record quoted); read through the bus-tracker.fr relay, which converts its SIRI feed to GTFS-RT. The layer draws positions and redistributes no database. Lines A and B are the tramway.', + note: 'The network publishes under ODbL (dataset record quoted), and this is its own GTFS-RT vehicle feed from that record (105 vehicles on 2026-11-09). The layer draws positions and redistributes no database. Route ids carry the network prefix `8-`; lines A and B are the tramway.', }, defaultMode: 'bus', - routeLabel: busTrackerRouteLabel, + routeLabel: liaRouteLabel, routeMode: liaRouteMode, }), transitFeed({ diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index 3867b12257..75a9027281 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -702,8 +702,8 @@ test('trams, waterbuses and buses are told apart where the ids allow it', () => assert.equal(mode('pid-praha', 'L22'), 'tram'); assert.equal(mode('pid-praha', 'L135'), 'bus'); assert.equal(mode('tbm-bordeaux', '16'), 'bus'); - assert.equal(mode('lia-le-havre', 'B'), 'tram'); - assert.equal(mode('lia-le-havre', '3'), 'bus'); + assert.equal(mode('lia-le-havre', '8-B'), 'tram'); + assert.equal(mode('lia-le-havre', '8-C3'), 'bus'); assert.equal(mode('ztp-krakow-tram', null), 'tram'); assert.equal(mode('actv-venezia-waterbus', '1_UN'), 'ferry'); }); @@ -759,14 +759,18 @@ test('Bordeaux trams ride numbered route ids and keep their letters', () => { assert.equal(transitRouteLabel(feed, '01'), '1'); }); -test('Rouen Métro and Calypso are not buses', () => { +test('Rouen Métro and Calypso are not buses; Le Havre reads its own ids', () => { const feed = getTransitFeed('astuce-rouen'); assert.equal(transitModeFor(feed, 'TCAR:90'), 'tram'); assert.equal(transitRouteLabel(feed, 'TCAR:90'), 'Métro'); assert.equal(transitModeFor(feed, 'TCAR:99'), 'ferry'); assert.equal(transitModeFor(feed, 'TCAR:93'), 'bus'); assert.equal(transitRouteLabel(feed, 'TAE:F'), 'F'); - assert.equal(transitModeFor(getTransitFeed('lia-le-havre'), 'FUNI'), 'rail'); + const lia = getTransitFeed('lia-le-havre'); + assert.equal(transitModeFor(lia, '8-FUNI'), 'rail'); + assert.equal(transitRouteLabel(lia, '8-C3'), 'C3'); + assert.equal(transitRouteLabel(lia, '8-09'), '9'); + assert.equal(transitRouteLabel(lia, '8-A'), 'A'); }); test('data.gov.my feeds ask the proxy for no more than its 4 a minute', () => { From 2ea4a78e7554243801e83bd5712683d1dfd56c3b Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 18:12:48 +0400 Subject: [PATCH 43/61] Fix the fr review follow-ups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - "destination refresh" is the refresh at the place the camera flew to, so restore "son actualisation à destination". - Radio note: "que vous la demandez par la voix", "Votre adresse IP". - "{count} / 30D": "30 J", like "{days} j". - Starlink: "la couche complète", as in the active-state tooltip. - "Show {name} sighting": colon form, so names starting with a vowel do not break the elision after "de". - Wildlife note: Acartia is the source, not a kind of marine mammal. - Straight apostrophes in the five strings added on main since. --- src/i18n/locales/fr.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index a6f5f7e18c..24cd94528b 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -820,7 +820,7 @@ "FLIGHT {count}": "VOL {count}", "REUSED": "RÉUTILISÉ", "NO STAGE RE-ENTRY / RECOVERY DATA": "AUCUNE DONNÉE DE RENTRÉE / RÉCUPÉRATION D'ÉTAGE", - "{count} / 30D": "{count} / 30J", + "{count} / 30D": "{count} / 30 J", "NO MISSIONS AVAILABLE IN THE CURRENT 30-DAY WINDOW": "AUCUNE MISSION DISPONIBLE DANS LA FENÊTRE ACTUELLE DE 30 JOURS", "DATE UNAVAILABLE": "DATE INDISPONIBLE", "UNSPECIFIED OPERATOR": "OPÉRATEUR NON PRÉCISÉ", @@ -1052,7 +1052,7 @@ "Longitudes must be within ±180°": "Les longitudes doivent être comprises entre −180° et +180°", "Select one side of the dateline": "Ne traversez pas la ligne de changement de date", "Box must enclose an area": "La zone doit délimiter une surface", - "Add the full Starlink broadband shell (thousands of extra points)": "Ajouter toute la couche de la constellation Starlink (des milliers de points en plus)", + "Add the full Starlink broadband shell (thousands of extra points)": "Ajouter la couche complète de la constellation Starlink (des milliers de points en plus)", "Loading the Starlink shell…": "Chargement de la couche de la constellation Starlink…", "Starlink {detail} — click to retry": "Starlink {detail} — cliquer pour réessayer", "load failed": "échec du chargement", @@ -2616,7 +2616,7 @@ "{layer} is enabled on the {source} feed, but no airborne aircraft is loaded in the {place} view yet": "La couche {layer} est activée sur le flux {source}, mais aucun aéronef en vol n'est encore chargé dans la vue {place}", "{layer} is enabled, but no airborne aircraft is loaded in the {place} view yet": "La couche {layer} est activée, mais aucun aéronef en vol n'est encore chargé dans la vue {place}", "{layer} is enabled, but its aircraft feed is unavailable": "La couche {layer} est activée, mais son flux d'aéronefs est indisponible", - "{layer} is enabled, but its destination refresh did not complete": "La couche {layer} est activée, mais l'actualisation de ses destinations ne s'est pas terminée", + "{layer} is enabled, but its destination refresh did not complete": "La couche {layer} est activée, mais son actualisation à destination ne s'est pas terminée", "{layer} is enabled, but {source} is unavailable": "La couche {layer} est activée, mais {source} est indisponible", "Could not arrive at {place}": "Impossible d'atteindre {place}", "{name} is no longer loaded": "{name} n'est plus chargé", @@ -2912,7 +2912,7 @@ "Radio volume": "Volume de la radio", "STATION SITE": "SITE DE LA STATION", "DIRECTORY: RADIO BROWSER": "ANNUAIRE : RADIO BROWSER", - "Audio connects directly to the broadcaster when you press play, choose a station on the globe or ask voice to play. Your IP is visible to that broadcaster.": "Le flux audio se connecte directement au diffuseur lorsque vous lancez la lecture, que vous choisissez une station sur le globe ou que vous demandez sa lecture à la voix. Votre IP est visible par ce diffuseur.", + "Audio connects directly to the broadcaster when you press play, choose a station on the globe or ask voice to play. Your IP is visible to that broadcaster.": "Le flux audio se connecte directement au diffuseur lorsque vous lancez la lecture, que vous choisissez une station sur le globe ou que vous la demandez par la voix. Votre adresse IP est visible par ce diffuseur.", "Local RTL-SDR receiver": "Récepteur RTL-SDR local", "LOCAL RTL-SDR": "RTL-SDR LOCAL", "Chrome/Edge · WebUSB · one local tuner shared by FM and the Local ADS-B layer.": "Chrome/Edge · WebUSB · un seul tuner local partagé entre la FM et la couche ADS-B local.", @@ -3275,7 +3275,7 @@ "The provider refused access for this key. Check the key's project, region or permissions.": "Le fournisseur a refusé l'accès pour cette clé. Vérifiez le projet, la région ou les autorisations de la clé.", "The provider account is out of credit. Check its billing, or choose another AI Provider in Settings.": "Le compte du fournisseur n'a plus de crédit. Vérifiez la facturation ou choisissez un autre fournisseur d'IA dans les paramètres.", "SIGHTING": "OBSERVATION", - "Show {name} sighting": "Afficher l'observation de {name}", + "Show {name} sighting": "Afficher l'observation : {name}", "seen {age} ago": "vu il y a {age}", "observed {age} ago": "observé il y a {age}", "Be Whale Wise": "Respectez les cétacés", @@ -3324,7 +3324,7 @@ "CC BY 4.0": "CC BY 4.0", "{count} sightings in view": "{count} observations dans la vue", "Close sighting": "Fermer l'observation", - "Wildlife observed within 48 h (whales 7 d). Color and badge glyph show the taxon group. Sensitive species are shown only as 0.2° cells; Salish Sea marine mammal reports via Acartia are rounded to 0.01°. Not a census.": "Faune observée au cours des dernières 48 h (cétacés 7 jours). La couleur et le pictogramme du badge indiquent le groupe taxonomique. Les espèces sensibles sont limitées à des cellules de 0,2° ; les signalements de mammifères marins Acartia en mer des Salish sont arrondis à 0,01°. Pas un recensement.", + "Wildlife observed within 48 h (whales 7 d). Color and badge glyph show the taxon group. Sensitive species are shown only as 0.2° cells; Salish Sea marine mammal reports via Acartia are rounded to 0.01°. Not a census.": "Faune observée au cours des dernières 48 h (cétacés 7 jours). La couleur et le pictogramme du badge indiquent le groupe taxonomique. Les espèces sensibles sont limitées à des cellules de 0,2° ; les signalements de mammifères marins en mer des Salish provenant d'Acartia sont arrondis à 0,01°. Pas un recensement.", "Open {name} on iNaturalist": "Ouvrir {name} sur iNaturalist", "Open {name} on Acartia": "Ouvrir {name} sur Acartia", "iNaturalist": "iNaturalist", @@ -3337,12 +3337,12 @@ "event age filter|All": "Tous", "Event age": "Ancienneté", "Event age: {days}d · undated kept": "Ancienneté : {days} j · marqueurs sans date conservés", - "Close camera preview": "Fermer l’aperçu de la caméra", - "Refresh map still": "Actualiser l’image fixe sur la carte", - "The map still uses a separate request and may show a different moment.": "L’image fixe de la carte utilise une requête distincte et peut montrer un autre moment.", + "Close camera preview": "Fermer l'aperçu de la caméra", + "Refresh map still": "Actualiser l'image fixe sur la carte", + "The map still uses a separate request and may show a different moment.": "L'image fixe de la carte utilise une requête distincte et peut montrer un autre moment.", "Video plays from Québec 511, which sees your IP address.": "La vidéo est lue depuis Québec 511, qui voit votre adresse IP.", "STATIONS": "STATIONS", - "Crewed stations and the craft that visit them": "Stations habitées et les vaisseaux qui s’y rendent", + "Crewed stations and the craft that visit them": "Stations habitées et les vaisseaux qui s'y rendent", "IMAGING": "IMAGERIE", "Earth observation: optical, radar, weather and science": "Observation de la Terre : optique, radar, météo et science", "TELECOM": "TÉLÉCOM", @@ -3355,7 +3355,7 @@ "Rocket bodies, fragments and dead satellites": "Étages de fusée, fragments et satellites hors service", "Classes may lag: SATCAT is a cached copy": "Classes peut-être en retard : SATCAT est une copie en cache", "Classes may lag: SATCAT unavailable": "Classes peut-être en retard : SATCAT indisponible", - "CelesTrak SATCAT gives each object's type and status. Without a current copy the classes rest on the UCS database, names and CelesTrak groups, so a satellite that has died since may still show as working.": "SATCAT de CelesTrak donne le type et l’état de chaque objet. Sans copie à jour, les classes reposent sur la base UCS, les noms et les groupes CelesTrak : un satellite hors service depuis peut encore apparaître comme actif.", + "CelesTrak SATCAT gives each object's type and status. Without a current copy the classes rest on the UCS database, names and CelesTrak groups, so a satellite that has died since may still show as working.": "SATCAT de CelesTrak donne le type et l'état de chaque objet. Sans copie à jour, les classes reposent sur la base UCS, les noms et les groupes CelesTrak : un satellite hors service depuis peut encore apparaître comme actif.", "STARLINK ···": "STARLINK ···", "STARLINK ✕": "STARLINK ✕", "SENSOR SWATH {value} KM": "FAUCHÉE CAPTEUR {value} KM", From 09bf01630bf27515a31fd6b3fbcf98baa36784f0 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 18:14:30 +0400 Subject: [PATCH 44/61] docs(server): tighten compression comments and docs --- .../795-opensky-compress-cached-body.md | 12 ++-- docs/CURRENT-STATE.md | 2 +- server/providers/aircraft/opensky.js | 20 +++---- server/providers/common/compress.js | 55 ++++++------------- src/tooling/liveProviders.test.mjs | 23 ++++---- src/tooling/responseCompression.test.mjs | 23 +++----- 6 files changed, 49 insertions(+), 86 deletions(-) diff --git a/changelog.d/795-opensky-compress-cached-body.md b/changelog.d/795-opensky-compress-cached-body.md index c0bbadbed7..3dff6a908c 100644 --- a/changelog.d/795-opensky-compress-cached-body.md +++ b/changelog.d/795-opensky-compress-cached-body.md @@ -1,7 +1,5 @@ -- The live flight snapshot is compressed on the wire. `/api/flights` gzips its - cached global snapshot and its regional adsb.lol fallback once per upstream - refresh and serves that frame to clients offering gzip — roughly 860 KB - becomes roughly 258 KB — while a client that offers nothing receives the same - bytes uncompressed. Both answers carry `Vary: Accept-Encoding`, and a response - the proxy does not cache, such as an auth failure, is never sent under a - cached snapshot's encoding (daikaginza, #795). +- Compress the live flight snapshot on the wire. `/api/flights` gzips its + cached global snapshot and its regional adsb.lol fallback once per refresh + and sends that frame to clients that offer gzip: about 860 KB becomes about + 250 KB. Other clients get the same bytes uncompressed, and both answers carry + `Vary: Accept-Encoding` (daikaginza, #795). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 7e7349035c..22d783d848 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -6186,7 +6186,7 @@ apply to `public/` assets or built-preview serving. - `/api/overpass` is bounded by body/response caps, per-client/global rate limits, concurrency limits, operator-configured upstreams, in-flight dedupe, cache bounds, and static validation that every selector is spatially bounded. - `/api/military-installations` uses an independent limiter with the same 90-per-client/300-global one-minute bounds, so viewport installation refreshes never consume `/api/overpass` annotation capacity. - `/api/route` proxies bounded OSRM route requests for annotation routes, with profile allowlisting, distance caps, response caps, caching, and sanitized "no route found" errors. -- `/api/flights` negotiates response encoding. The cached global snapshot and the regional adsb.lol fallback are each gzipped once per refresh, so a client that offers gzip receives roughly 860 KB as 250 KB and one that does not receives the same bytes uncompressed; both answers carry `Vary: Accept-Encoding`. Bodies the proxy does not cache — auth failures, cooldown notices — are never sent under a cached response's encoding. +- `/api/flights` negotiates gzip. The cached global snapshot and the regional adsb.lol fallback are each gzipped once per refresh (about 860 KB becomes about 250 KB). Clients that offer gzip get that frame; other clients, and bodies under 1 KiB or that gzip cannot shrink, get identity bytes. Both answers carry `Vary: Accept-Encoding`. Uncached bodies, such as auth failures, are never sent under a cached frame's encoding. - Track endpoints: `/api/vessels/track?mmsi=` (server-accumulated ring buffers; sub-route handled before the rows snapshot), `/api/flights/track?icao24=` (OAuth, 60s cache, sanitized errors, independent OpenSky credit bucket), `/api/military/track?hex=` (400 for an invalid hex, otherwise `503 history_unavailable` with `Retry-After: 1800` and `Cache-Control: no-store`, no upstream request; military tracking uses its locally accumulated trail). - Realtime debug logs redact API keys, bearer tokens, client secrets, and image data URLs before writing to disk; request bodies are size-capped. - `/api/realtime/debug-log` enforces an always-on 120-per-client/400-global one-minute limiter (not the opt-in `GEV_RATELIMIT_OPENAI_PER_MIN` bucket the cost-bearing OpenAI routes share), appends asynchronously through a serialized queue, and rotates `realtime-conversations.jsonl` at 32 MB keeping one prior generation, so the sink is bounded at twice that regardless of session length. A malformed record answers 400 and a failed write 500, both with a fixed message. diff --git a/server/providers/aircraft/opensky.js b/server/providers/aircraft/opensky.js index 0c948ef7a2..b1b07c9d2b 100644 --- a/server/providers/aircraft/opensky.js +++ b/server/providers/aircraft/opensky.js @@ -20,9 +20,8 @@ let _openskyTokenPromise = null; /** @type {string|null} Cached upstream response body (JSON text). */ let _openskyCacheBody = null; /** - * @type {Buffer|null} Gzip of `_openskyCacheBody`, written in the same step as - * the body it encodes so the two can never describe different snapshots. Null - * whenever the cached body is too small to be worth a frame. + * @type {Buffer|null} Gzip of `_openskyCacheBody`, written together with it. + * Null when the body is not worth compressing. */ let _openskyCacheGzip = null; /** @type {number} HTTP status of the cached response. */ @@ -409,9 +408,8 @@ async function fetchAdsbLolPointFallback(req) { const body = JSON.stringify(normalized); const record = { body, - // Compressed with the body it belongs to, so a cache entry served - // many times pays for the frame once. Entries are bounded by - // ADSBLOL_POINT_CACHE_MAX, so the extra residency is bounded too. + // Compressed once per entry; ADSBLOL_POINT_CACHE_MAX bounds the + // extra memory. gzip: await gzipBody(body), cachedAt: Date.now(), count: normalized.states.length, @@ -647,9 +645,8 @@ export function openSkyProxy() { // Only cache successful responses — error responses (401/403/429/5xx) // should not be served from cache on subsequent requests if (upstream.ok) { - // The frame is built before either slot is written so the two - // are always published together: a request arriving mid-refresh - // reads the previous body with the previous body's frame. + // Compress before writing either slot, so a request arriving + // mid-refresh still reads a body with its own frame. const frame = await gzipBody(body); _openskyCacheBody = body; _openskyCacheGzip = frame; @@ -763,9 +760,8 @@ export function openSkyProxy() { } } - // Only the coalesced refresh caches, so the gzip slot belongs to this - // body only when this body is the one it stored. An error response is - // not cached and must not borrow the previous snapshot's frame. + // The frame belongs to this body only if this body was cached. An + // uncached error must not borrow the previous snapshot's frame. const encoded = encodedBody( req, body, diff --git a/server/providers/common/compress.js b/server/providers/common/compress.js index ebf736eda2..d9938b87e2 100644 --- a/server/providers/common/compress.js +++ b/server/providers/common/compress.js @@ -4,39 +4,25 @@ import { promisify } from 'node:util'; const gzipAsync = promisify(gzip); /** - * Response compression for proxies that already hold a whole body in memory. + * Opt-in gzip for text bodies a proxy already holds in memory. * - * Deliberately not a middleware. Two response paths in this tree must never be - * wrapped: `cctv/media.js` streams a piped body and answers byte-range requests - * with 206, and `wind/gfs.js` also serves ranges — a wrapper that buffered or - * re-encoded those would break playback and range semantics. Seven providers - * additionally forward an upstream `content-type` verbatim, including already - * compressed binary formats that gzip would only make larger. - * - * So compression is opt-in at the call site, for bodies the proxy holds and - * knows to be text. The failure mode of forgetting a site is a response that is - * merely uncompressed, never a corrupt one — but only as long as the encoded - * body and its `Content-Encoding` are chosen together, which is why - * `encodedBody` returns both rather than exposing them separately. + * Not a middleware: `cctv/media.js` streams bodies and answers range requests, + * and several providers forward binary upstream types that gzip only grows. + * `encodedBody` returns the body with its headers so the two cannot disagree. */ -/** Below this, a gzip frame costs more than the bytes it saves. */ +/** Skip compression for bodies smaller than 1 KiB. */ const MIN_COMPRESSED_BYTES = 1024; /** - * The `qvalue` grammar of RFC 9110 section 12.4.2: zero to three decimals - * below one, or one with only zeros after it. Matching the whole token rather - * than parsing a numeric prefix is what makes `q=1oops` and the out-of-range - * `q=2` unreadable instead of quietly rounding to something acceptable. + * RFC 9110 section 12.4.2 `qvalue`. Matching the whole token keeps `q=1oops` + * and `q=2` unreadable instead of rounding them into acceptance. */ const QVALUE = /^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/; /** - * Whether the client offered gzip in `Accept-Encoding`. - * - * Anything this cannot read confidently — a missing header, a malformed or - * out-of-range quality value, the `x-gzip` alias — reads as "no", because the - * fallback is an identity response every client can decode. + * Whether `Accept-Encoding` offers gzip. Anything unreadable (no header, a bad + * q value, `x-gzip`) reads as no: every client can decode identity. * * @param {import('node:http').IncomingMessage} request * @returns {boolean} @@ -51,23 +37,18 @@ export function acceptsGzip(request) { .map((parameter) => parameter.trim().toLowerCase()) .find((parameter) => parameter.startsWith('q=')); if (quality === undefined) return true; - // `q=0` is the one way a client can name an encoding and still refuse it. + // `q=0` names gzip and refuses it. const value = quality.slice(2); return QVALUE.test(value) && Number(value) > 0; }); } /** - * Gzip a body once, for callers that cache it and serve it many times. + * Gzip a body once for a caller that caches it. Async, so the ~860 KB OpenSky + * snapshot does not block other requests while it compresses. * - * OpenSky's snapshot is ~860 KB and is held for the cache TTL, so this is paid - * per refresh rather than per request. It runs off the event loop on purpose: - * on that snapshot the synchronous call stalls every other in-flight request by - * 11 ms, while this stalls them by under 1 ms and costs the caller — which is - * already waiting on an upstream fetch — about 5 ms more of its own latency. - * - * Returns null when the body is too small to be worth a frame, so callers can - * store the result directly and treat null as "serve identity". + * Returns null, meaning "serve identity", when the body is under 1 KiB or gzip + * does not shrink it. * * @param {string|Buffer} body - the exact bytes the identity response sends. * @returns {Promise} @@ -81,11 +62,9 @@ export async function gzipBody(body) { } /** - * Pick the body to send and the headers that describe it, together. - * - * `Vary: Accept-Encoding` is set on both branches, not only the compressed one: - * a cache that stored an identity response without it would later hand those - * bytes to a client that asked for gzip, and vice versa. + * Pick the body and the headers that describe it. `Vary` is on both branches + * so a shared cache never serves one encoding to a client that asked for the + * other. * * @param {import('node:http').IncomingMessage} request * @param {string|Buffer} identity - the uncompressed body. diff --git a/src/tooling/liveProviders.test.mjs b/src/tooling/liveProviders.test.mjs index 70410ec2f8..3198ee7526 100644 --- a/src/tooling/liveProviders.test.mjs +++ b/src/tooling/liveProviders.test.mjs @@ -615,8 +615,7 @@ test('the OpenSky snapshot is compressed for clients that ask, and an error body if (upstreamStatus !== 200) return new Response('{"error":"upstream"}', { status: upstreamStatus }); const sourceSeconds = Math.floor((now - snapshotAgeMs) / 1000); - // A healthy credit budget, so the proxy keeps its 9 s base TTL and the - // clock advances below are unambiguously past it. + // Healthy credits keep the 9 s base TTL, so the clock jumps below clear it. return Response.json( { time: sourceSeconds, @@ -634,8 +633,7 @@ test('the OpenSky snapshot is compressed for clients that ask, and an error body ); }); - // A module instance of its own: the snapshot cache, its frame and the - // adaptive TTL are module state, and this test reasons about all three. + // A fresh module: the snapshot cache, its frame and the TTL are module state. const isolated = await import( `../../server/providers/aircraft/opensky.js?compression=${now}` ); @@ -648,25 +646,25 @@ test('the OpenSky snapshot is compressed for clients that ask, and an error body assert.equal(compressed.headers.vary, 'Accept-Encoding'); assert.ok(Buffer.isBuffer(compressed.body)); - // Same snapshot from cache, this time to a client that offered nothing: the - // identity bytes, and the compressed frame above must decode to exactly them. + // Same cached snapshot, no Accept-Encoding: identity bytes, which the frame + // above must decode to. const identity = await states('/api/flights'); assert.equal(identity.headers['x-opensky-cache'], 'HIT'); assert.equal(identity.headers['content-encoding'], undefined); assert.equal(identity.headers.vary, 'Accept-Encoding'); assert.equal(gunzipSync(compressed.body).toString(), identity.body); - // A client that names gzip and refuses it with q=0 is a non-gzip client. + // `gzip;q=0` refuses gzip. const refused = await states('/api/flights', '/', 'GET', { 'accept-encoding': 'gzip;q=0', }); assert.equal(refused.headers['content-encoding'], undefined); assert.equal(refused.body, identity.body); - // An upstream rejection is not cached, so it has no frame of its own. It must - // not be sent under the previous snapshot's Content-Encoding. + // An upstream rejection is not cached, so it must not carry the previous + // snapshot's Content-Encoding. upstreamStatus = 403; - now += 60000; // past the 9 s base TTL this fresh instance starts with + now += 60000; // past the 9 s base TTL const rejected = await states('/api/flights', '/', 'GET', { 'accept-encoding': 'gzip', }); @@ -674,9 +672,8 @@ test('the OpenSky snapshot is compressed for clients that ask, and an error body assert.equal(rejected.headers['content-encoding'], undefined); assert.ok(JSON.parse(rejected.body).error, 'a readable error body'); - // The regional fallback is a fifth body this route can answer with. It is - // cached the same way and so it negotiates the same way: a snapshot too old - // to serve hands the request to adsb.lol, compressed. + // A snapshot too old to serve falls back to adsb.lol, which negotiates the + // same way. upstreamStatus = 200; snapshotAgeMs = 3600000; now += 60000; diff --git a/src/tooling/responseCompression.test.mjs b/src/tooling/responseCompression.test.mjs index e2dff64591..6fbd531939 100644 --- a/src/tooling/responseCompression.test.mjs +++ b/src/tooling/responseCompression.test.mjs @@ -17,7 +17,7 @@ function request(acceptEncoding) { }; } -/** Repetitive JSON, the shape of an actual snapshot body. */ +/** Repetitive JSON shaped like a snapshot body. */ function snapshotBody(states = 200) { return JSON.stringify({ time: 1700000000, @@ -33,10 +33,7 @@ function snapshotBody(states = 200) { }); } -/** - * Deterministic high-entropy bytes. Random data would do, but a seeded sequence - * keeps the "gzip made it bigger" assertion from depending on luck. - */ +/** Seeded high-entropy bytes, so the "gzip made it bigger" check is stable. */ function incompressibleBytes(length) { const bytes = Buffer.alloc(length); let state = 123456789; @@ -61,16 +58,15 @@ test('accept-encoding is read the way clients actually write it', () => { assert.equal(acceptsGzip({}), false); assert.equal(acceptsGzip(undefined), false); - // A quality of zero names gzip and refuses it (RFC 9110 section 12.4.2). + // `q=0` names gzip and refuses it (RFC 9110 section 12.4.2). assert.equal(acceptsGzip(request('gzip;q=0')), false); assert.equal(acceptsGzip(request('gzip;q=0.000')), false); assert.equal(acceptsGzip(request('gzip;q=0.001')), true); assert.equal(acceptsGzip(request('gzip;q=1')), true); assert.equal(acceptsGzip(request('gzip;q=1.000')), true); - // A quality that is not a whole `qvalue` is unreadable, not a number with - // trailing noise: the grammar allows three decimals and a ceiling of 1, so - // these must not round into acceptance. + // A q that is not a whole `qvalue` is unreadable and must not round into + // acceptance. assert.equal(acceptsGzip(request('gzip;q=bogus')), false); assert.equal(acceptsGzip(request('gzip;q=1oops')), false); assert.equal(acceptsGzip(request('gzip;q=0.5abc')), false); @@ -102,8 +98,7 @@ test('a body is only compressed when compression pays for itself', async () => { assert.ok(compressed.byteLength < Buffer.byteLength(identity)); assert.equal(gunzipSync(compressed).toString(), identity); - // Buffers are accepted as-is, and data that gzip cannot shrink is refused - // rather than served as a larger response. + // Buffers are accepted as-is; data gzip cannot shrink stays uncompressed. assert.ok((await gzipBody(Buffer.from(identity))) !== null); assert.equal(await gzipBody(incompressibleBytes(4096)), null); }); @@ -118,8 +113,7 @@ test('the encoded body and the header that names it are chosen together', async assert.equal(negotiated.headers.Vary, 'Accept-Encoding'); assert.equal(gunzipSync(negotiated.body).toString(), identity); - // Offered but not wanted: identity bytes, and no Content-Encoding to - // contradict them. + // Offered but refused: identity bytes and no Content-Encoding. const refused = encodedBody(request('br'), identity, compressed); assert.equal(refused.body, identity); assert.equal(refused.headers['Content-Encoding'], undefined); @@ -130,8 +124,7 @@ test('the encoded body and the header that names it are chosen together', async assert.equal(unavailable.body, identity); assert.equal(unavailable.headers['Content-Encoding'], undefined); - // Vary is on both branches: without it a shared cache could hand a stored - // response to a client whose Accept-Encoding it was not selected for. + // Vary is on both branches, so a shared cache cannot serve the wrong encoding. assert.equal(unavailable.headers.Vary, 'Accept-Encoding'); assert.equal( encodedBody(request(undefined), identity, compressed).headers.Vary, From caad795fa2aa1bfd2acf647823847817c149a3ba Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 18:15:13 +0400 Subject: [PATCH 45/61] refactor(server): drop the null and String paths from gzipBody --- server/providers/common/compress.js | 3 +-- src/tooling/responseCompression.test.mjs | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/server/providers/common/compress.js b/server/providers/common/compress.js index d9938b87e2..cbce21c6ea 100644 --- a/server/providers/common/compress.js +++ b/server/providers/common/compress.js @@ -54,8 +54,7 @@ export function acceptsGzip(request) { * @returns {Promise} */ export async function gzipBody(body) { - if (body == null) return null; - const raw = Buffer.isBuffer(body) ? body : Buffer.from(String(body)); + const raw = Buffer.isBuffer(body) ? body : Buffer.from(body); if (raw.byteLength < MIN_COMPRESSED_BYTES) return null; const compressed = await gzipAsync(raw); return compressed.byteLength < raw.byteLength ? compressed : null; diff --git a/src/tooling/responseCompression.test.mjs b/src/tooling/responseCompression.test.mjs index 6fbd531939..011d767c3e 100644 --- a/src/tooling/responseCompression.test.mjs +++ b/src/tooling/responseCompression.test.mjs @@ -81,8 +81,6 @@ test('accept-encoding is read the way clients actually write it', () => { }); test('a body is only compressed when compression pays for itself', async () => { - assert.equal(await gzipBody(null), null); - assert.equal(await gzipBody(undefined), null); assert.equal(await gzipBody(''), null); assert.equal( await gzipBody('{"states":[]}'), From 3e630cf34fbefe4deb63d46432e983dd975f9c0b Mon Sep 17 00:00:00 2001 From: Said Turksever Date: Mon, 9 Nov 2026 14:34:33 +0000 Subject: [PATCH 46/61] fix(transit): mark route line names as kept for i18n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Métro, Calypso, LD and the metro letters are line names as signed, not UI copy; the i18n catalog check flagged them. --- src/data/transitFeeds.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index e9aeb4359a..42f399d778 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -453,7 +453,9 @@ function liaRouteMode(routeId) { * rail that runs mostly on the street) and 99 the Calypso river boat. */ const ASTUCE_ROUTES = Object.freeze({ + // i18n-ignore: line name, as on the vehicle 'TCAR:90': Object.freeze({ mode: 'tram', label: 'Métro' }), + // i18n-ignore: line name, as on the vehicle 'TCAR:99': Object.freeze({ mode: 'ferry', label: 'Calypso' }), }); @@ -484,11 +486,13 @@ function pidRoute(routeId) { const match = /^L(\d+)$/.exec(routeId ?? ''); if (!match) return { mode: 'unknown', label: routeId }; const n = Number(match[1]); + // i18n-ignore: line code, as signed if (n === 49) return { mode: 'rail', label: 'LD' }; if (n >= 50 && n <= 59) return { mode: 'bus', label: String(n) }; if (n < 100) return { mode: 'tram', label: String(n) }; if (n >= 800 && n < 900) return { mode: 'bus', label: `X${n - 800}` }; if (n < 991) return { mode: 'bus', label: String(n) }; + // i18n-ignore: metro line letters, as signed if (n <= 993) return { mode: 'subway', label: 'ABC'[n - 991] }; if (n >= 1000 && n < 1100) return { mode: 'rail', label: `S${n - 1000}` }; if (n >= 1100 && n < 1200) return { mode: 'rail', label: `R${n - 1100}` }; From c3738c0fdb8dfeb0e2add30bbbd79f03915c2af5 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 19:07:14 +0400 Subject: [PATCH 47/61] docs(server): tighten the method-guard comments and changelog --- changelog.d/794-api-method-guard.md | 11 ++++------- docs/CURRENT-STATE.md | 2 +- server/providers/aircraft/adsb-lol.js | 4 +--- server/providers/aircraft/opensky.js | 5 +---- server/providers/places/routes.js | 2 -- src/tooling/liveProviders.test.mjs | 13 ++++--------- src/tooling/placeProviders.test.mjs | 6 ++---- 7 files changed, 13 insertions(+), 30 deletions(-) diff --git a/changelog.d/794-api-method-guard.md b/changelog.d/794-api-method-guard.md index 530be060ea..97801e091e 100644 --- a/changelog.d/794-api-method-guard.md +++ b/changelog.d/794-api-method-guard.md @@ -1,7 +1,4 @@ -- The read-only query proxies state their method contract. `/api/flights`, - `/api/military` and `/api/route` answered any verb with the same body - while ignoring the request; they now answer `405 Method Not Allowed` to - anything but `GET`, the way `/api/geocode` and the other query proxies - already did, and declare `Allow: GET` with it the way `/api/radio/stations` - does. The refusal precedes rate limiting and any upstream call - (daikaginza, #794). +- Answer `405 Method Not Allowed` with `Allow: GET` to anything but `GET` on + `/api/flights`, `/api/military` and `/api/route`, as the other query proxies + do. They answered every verb with the same body. The refusal comes before + rate limiting and any upstream call (daikaginza, #794). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index f2569f3637..6a3b07c5de 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -6491,7 +6491,7 @@ apply to `public/` assets or built-preview serving. - `/api/overpass` is bounded by body/response caps, per-client/global rate limits, concurrency limits, operator-configured upstreams, in-flight dedupe, cache bounds, and static validation that every selector is spatially bounded. - `/api/military-installations` uses an independent limiter with the same 90-per-client/300-global one-minute bounds, so viewport installation refreshes never consume `/api/overpass` annotation capacity. - `/api/route` proxies bounded OSRM route requests for annotation routes, with profile allowlisting, distance caps, response caps, caching, and sanitized "no route found" errors. -- `/api/flights`, `/api/military`, and `/api/route` are read-only query proxies and answer `405 Method Not Allowed` to anything but `GET`, as `/api/geocode` and the other query proxies already did, declaring `Allow: GET` with it as `/api/radio/stations` does. The refusal precedes rate limiting and any upstream call. +- `/api/flights`, `/api/military`, and `/api/route` answer `405 Method Not Allowed` with `Allow: GET` to anything but `GET`, before rate limiting and any upstream call. - `/api/flights` negotiates gzip. The cached global snapshot and the regional adsb.lol fallback are each gzipped once per refresh (about 860 KB becomes about 250 KB). Clients that offer gzip get that frame; other clients, and bodies under 1 KiB or that gzip cannot shrink, get identity bytes. Both answers carry `Vary: Accept-Encoding`. Uncached bodies, such as auth failures, are never sent under a cached frame's encoding. - Track endpoints: `/api/vessels/track?mmsi=` (server-accumulated ring buffers; sub-route handled before the rows snapshot), `/api/flights/track?icao24=` (OAuth, 60s cache, sanitized errors, independent OpenSky credit bucket), `/api/military/track?hex=` (400 for an invalid hex, otherwise `503 history_unavailable` with `Retry-After: 1800` and `Cache-Control: no-store`, no upstream request; military tracking uses its locally accumulated trail). - Realtime debug logs redact API keys, bearer tokens, client secrets, and image data URLs before writing to disk; request bodies are size-capped. diff --git a/server/providers/aircraft/adsb-lol.js b/server/providers/aircraft/adsb-lol.js index 80aacc7c49..6bdc65e9f9 100644 --- a/server/providers/aircraft/adsb-lol.js +++ b/server/providers/aircraft/adsb-lol.js @@ -83,9 +83,7 @@ export function adsbLolProxy() { // This mount also matches its /track route, served by its own handler. if (new URL(req.url || '/', 'http://localhost').pathname !== '/') return next(); - // Read-only snapshot endpoint; match the method contract its sibling - // query proxies already declare instead of serving every verb alike. - // Checked after the /track hand-off, so that route keeps its own. + // After the /track hand-off, so /track keeps its own method handling. if (req.method !== 'GET') { res.writeHead(405, { 'Content-Type': 'application/json', diff --git a/server/providers/aircraft/opensky.js b/server/providers/aircraft/opensky.js index 0a23978a5c..1cc30a482b 100644 --- a/server/providers/aircraft/opensky.js +++ b/server/providers/aircraft/opensky.js @@ -496,10 +496,7 @@ export function openSkyProxy() { // This mount also matches its /track route, served by its own handler. if (new URL(req.url || '/', 'http://localhost').pathname !== '/') return next(); - // Read-only snapshot endpoint: state the method contract the way - // /api/geocode and the other query proxies state it, rather than - // answering any verb with the same body and ignoring the request body. - // Checked after the /track hand-off, so that route keeps its own. + // After the /track hand-off, so /track keeps its own method handling. if (req.method !== 'GET') { res.writeHead(405, { 'Content-Type': 'application/json', diff --git a/server/providers/places/routes.js b/server/providers/places/routes.js index 2c67f1f5c9..7b0a814496 100644 --- a/server/providers/places/routes.js +++ b/server/providers/places/routes.js @@ -227,8 +227,6 @@ export function installRouteMiddleware( // only shape that asks the upstream for them. A response WITHOUT steps is // byte for byte what this endpoint has always returned. middlewares.use('/api/route', async (req, res) => { - // The documented shape above is a GET with query parameters; say so, - // the way the other query proxies do, instead of answering any verb. if (req.method !== 'GET') { res.writeHead(405, { 'Content-Type': 'application/json', Allow: 'GET' }); res.end(JSON.stringify({ error: 'Method Not Allowed' })); diff --git a/src/tooling/liveProviders.test.mjs b/src/tooling/liveProviders.test.mjs index e40e4079cc..df71ec9a75 100644 --- a/src/tooling/liveProviders.test.mjs +++ b/src/tooling/liveProviders.test.mjs @@ -586,10 +586,7 @@ test('track backfill proxy returns 502 on an oversized upstream body and caches }); test('the aircraft snapshot routes decline a non-GET before any upstream work', async (t) => { - // Both routes answered every verb with the full snapshot, unlike the query - // proxies beside them, so nothing said whether a body was read or ignored. - // A stubbed fetch that throws proves the refusal happens before the handler - // reaches upstream, rather than after paying for the work and discarding it. + // A fetch that throws proves the refusal comes before any upstream call. t.mock.method(globalThis, 'fetch', async (url) => { throw new Error(`upstream must not be reached: ${url}`); }); @@ -601,8 +598,7 @@ test('the aircraft snapshot routes decline a non-GET before any upstream work', for (const method of ['POST', 'PUT', 'DELETE', 'PATCH']) { const response = await request(route, '/', method); assert.equal(response.statusCode, 405, `${method} ${route}`); - // RFC 9110 section 15.5.6 requires a 405 to name the methods it does - // accept, which is what `/api/radio/stations` already does in-tree. + // RFC 9110 section 15.5.6: a 405 names the methods it accepts. assert.equal(response.headers.allow, 'GET', `${method} ${route}`); assert.deepEqual(JSON.parse(response.body), { error: 'Method Not Allowed', @@ -612,9 +608,8 @@ test('the aircraft snapshot routes decline a non-GET before any upstream work', }); test('the snapshot method check hands each /track route on to its own handler', async () => { - // Each snapshot mount is a prefix of its /track route, so the snapshot - // handler sees /track requests first and must hand them on before it - // judges the method; otherwise the 405 would answer for the other route. + // The snapshot mount also matches /track, so it must hand /track on + // before it checks the method. for (const [plugin, route] of [ [providers.openSkyProxy(), '/api/flights'], [providers.adsbLolProxy(), '/api/military'], diff --git a/src/tooling/placeProviders.test.mjs b/src/tooling/placeProviders.test.mjs index 4b728b6ac5..4ae9558ffb 100644 --- a/src/tooling/placeProviders.test.mjs +++ b/src/tooling/placeProviders.test.mjs @@ -502,9 +502,7 @@ test('the upstream host is pinned: a redirect is refused, not followed', async ( }); test('the routing proxy declines a non-GET before rate limiting or upstream', async (t) => { - // The documented shape is a GET with query parameters, but every verb was - // answered alike. Refuse first: a stubbed fetch that throws shows the - // rejection costs neither an upstream call nor a rate-limit slot. + // A fetch that throws proves the refusal comes before any upstream call. const request = install(installRouteMiddleware); t.mock.method(globalThis, 'fetch', async () => { throw new Error('upstream must not be reached'); @@ -516,7 +514,7 @@ test('the routing proxy declines a non-GET before rate limiting or upstream', as method, ); assert.equal(response.statusCode, 405, method); - // RFC 9110 section 15.5.6 requires a 405 to name the methods it accepts. + // RFC 9110 section 15.5.6: a 405 names the methods it accepts. assert.equal(response.headers.allow, 'GET', method); assert.deepEqual(response.body, { error: 'Method Not Allowed' }); } From cdf52ab290497bda4ff23cc00cfba156524e5389 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 19:07:14 +0400 Subject: [PATCH 48/61] test(server): drop unused fields from the /track hand-off stub --- src/tooling/liveProviders.test.mjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tooling/liveProviders.test.mjs b/src/tooling/liveProviders.test.mjs index df71ec9a75..070a6f9977 100644 --- a/src/tooling/liveProviders.test.mjs +++ b/src/tooling/liveProviders.test.mjs @@ -620,8 +620,6 @@ test('the snapshot method check hands each /track route on to its own handler', }); const res = { statusCode: 200, - headers: {}, - setHeader() {}, writeHead(s) { this.statusCode = s; }, From 4da477a654e64333930bb74d2cf5b047d7c464f1 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 07:16:14 -0800 Subject: [PATCH 49/61] feat(draw): hand one drawn area or line back to the application createApplicationTools returns drawShape({ shape, signal }): it opens Draw for one area or line and resolves with its Polygon or LineString without placing a mark, or null when draw mode is left, the signal aborts, a newer request replaces it, the pointer is held elsewhere or the tool goes. The shape controls cannot change the asked-for shape, and a shape across the antimeridian is refused as a row's actions refuse it and drawn again. It also returns pointerFree, so an application's own click handlers yield to a tool holding the pointer, as the layers' do. --- CHANGELOG.md | 5 + docs/CURRENT-STATE.md | 1 + src/annotations/drawTool.js | 66 ++++++++- src/annotations/drawToolBehaviour.test.mjs | 152 +++++++++++++++++++++ src/app/tools.js | 15 +- 5 files changed, 237 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 356289841a..89ae0e1e50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## [Unreleased] +- Applications can ask Draw for one area or line and get its geometry back + without placing a mark (`drawShape` from `createApplicationTools`), and their + own click handlers can yield while a tool holds the pointer, as the layers' + do (`pointerFree`) (samehkhamis). + ## [0.3.0] — 2026-10-27 — Street Level, On Your Phone, in Your Language - Show a Street Level view facing 359.5° or more as 0°. The viewer caption diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 08dc69d1f5..b70dc1d923 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -6311,6 +6311,7 @@ request viewbox and continues searching without that geographic preference. - UTILITIES ▸ **Draw** turns the globe into a whiteboard drawn by hand. Pick a shape (icon buttons for Area, Line and Pin) and a colour swatch for the next shape, click the vertices on the real world, and finish. **Keyboard contract, live only while Draw is on and never while you are typing in another field:** Enter finishes the shape (as does a double-click, and the two cannot both submit it — the session is replaced before the annotate call is awaited); Backspace removes the last vertex; Esc cancels the shape in progress, and a second Esc — Esc on an empty session — leaves draw mode. **Clear** wipes the board (the shape in progress and every placed mark), so removing marks does not require the console or the microphone. - **Drawn shapes are listed under Draw like Import's files** (`src/ui/views/panels/DrawMarkList.vue`, rows worded by `presentDrawMarks` in `src/annotations/drawMarks.js`): one row per hand-drawn mark (`manual: true`; voice marks are not listed) with its colour swatch, its name, and show/hide, fly-to and remove. The draw tool publishes the rows with the rest of its controls and answers the row actions (`renameDrawMark`, `recolorDrawMark`, `toggleDrawMark`, `flyToDrawMark`, `removeDrawMark`) through the display store; it republishes on the engine's `onChange`, so a voice clear or an expiry updates the list. Rows are keyed and updated in place: a board change never takes a name being typed (the field keeps its draft while focused) or the button under a click. The name is saved on Enter or on leaving the field, once; Esc restores it, before anything else and with the row's colours open too. Both keep focus in the field, so neither drops it to the page or leaves Draw. The swatch opens the five colours right after it (shown at the end of the row), with the current colour focused; the arrows, Home and End try another, and a click or Esc closes them and returns focus to the swatch. Both colour groups (the next shape's and a row's) are one `DrawSwatches` radio group with a single tab stop, coloured from `DRAW_COLOR_CSS`; on touch screens each dot answers a 24 px target. An unnamed shape shows its kind, and an unnamed line its length; a renamed line keeps its length (`Ridge walk — 950 m`). **Hidden** keeps a mark on the board at alpha 0, and the world renderer takes every one of its entities out (`show = false`), so no material that keeps its own colour (the line's flowing stroke) still paints it; the screen renderer does not project a hidden callout, so it cannot push a visible label aside; `fly_route` skips a hidden route; and with every mark hidden the annotations render hold is released. **Fly to** is an immediate navigation (`runImmediateNavigation('drawing', …)`), like Import's: Cockpit refuses it and a running orbit, follow or track lets go first. A line is framed by its whole path, across the antimeridian too. - Runtime entry: `createApplicationTools` (`src/app/tools.js`, behind the `src/standalone/tools.js` shim) calls `initDrawTool({ viewer, annotations, navigation, publish, connect, markActions })` after `initAnnotations` and defers its `destroy()`, so disposing the shell returns every DOM listener, the Cesium handler, the preview data source, the borrowed click actions and the `window.__gevDrawTool` handle. Its controls are Vue views in the UTILITIES panel (`DrawControls.vue`, `DrawMarkList.vue`) that render what the tool publishes to the display store and call its actions. That handle (`setActive`, `setShape`, `addVertex(lon, lat)`, `finish`, `cancel`, `clearAll`, `marks`, `setColor`, `diagnostics`) is the no-mouse test seam. +- **One shape, handed back.** `createApplicationTools` also returns `drawShape({ shape, signal })` (`drawTool.drawShape`): it opens draw mode for one `area` or `line` and resolves with its geometry, a closed `[lon, lat]` `Polygon` or a `LineString`, without placing a mark; the shape chosen before comes back and draw mode ends. While it is open the controls cannot change the shape, and one across the antimeridian is refused as a row's actions refuse it ("That shape could not be placed.") and drawn again. It resolves `null` when the drawing is cancelled (the second Escape), draw mode is left, `signal` aborts, another request replaces it, the pointer is held elsewhere, the tool is destroyed, or the page has no Draw controls. It returns `pointerFree` (`data/inputOwnership.js` `isPointerFree`) too, so an application's own click handlers yield to the tool holding the pointer, as the layers' do. - **Row actions are an application's own.** `createApplicationTools({ drawMarkActions })` hands `initDrawTool` buttons for drawn areas' and lines' rows; the standalone shell passes none, so the open-source build shows no new button and makes no new request. Each action (`drawMarkActions` in `src/annotations/drawMarks.js`) is `{ id, icon, label(name), shapes: ['area', 'line'], accepts?(geometry, shape), run({ id, shape, name, title, geometry }) }`: the icon a Material Symbols name, the label worded by the application, `name` the person's own and `title` the row's (the name, else `Area` or `Line · 950 m`), the geometry `drawMarkGeometry`'s `[lon, lat]` `Polygon` (closed; a `MultiPolygon` for an area handle with several parts) or `LineString`, longitudes wrapped into [-180, 180]. A pin, and a shape that crosses the antimeridian or has a part that cannot be given whole, has no geometry and is offered nothing. Malformed actions and repeated ids are dropped once, at construction. What `run` returns or resolves to is a note under the row (`role=status`; past 200 characters it is cut at a word with an ellipsis); the row is busy (`aria-disabled`, no second press) until it settles, a rejection or a throw clears the note and is logged (so an action words its own refusals and resolves with them), and a shape's note goes with the shape, so a late answer never lands on a removed one. - Contract: a finished shape is submitted through the SAME `annotationEngine.annotate()` the voice agent uses, with geometry supplied and `manual: true` (`type: area` + `ring`, `type: route` + `path`, `type: pin` + coordinates). `resolveSpec` short-circuits manual specs (`resolveManualSpec`) so no geocoder, Places or Overpass call is made. A drawn area is a real (not synthesized) outline and drapes solid; a drawn line is a `route` with `mode: 'manual'`, labelled with its length and never a travel time; a pin is a point. Drawn marks therefore render with the whiteboard look, persist, appear in `.list()`, and clear with `clear_annotations` / `.clear()`. A drawn shape is never merged with another as a duplicate: every one is drawn on purpose, and every one is unnamed until its row names it, so two pins dropped close together are two pins. - **A vertex is a lon/lat, and the mark is DRAPED.** Clicks are picked through `pickWorldFromScreen` — one of two scene helpers the annotation resolver factory (`src/annotations/resolver.js`) exposes alongside `sampleGroundHeight`, so the app has ONE depth-aware pick cascade rather than a second written beside it — which returns the height the pick landed on as well as the coordinate, so the live preview hangs on the roof or hillside under the pointer instead of sinking to sea level. The world renderer draws areas and routes with `clampToGround`, so the height is dropped at finish in one place (`finishSpec`) rather than being carried downstream and discarded silently: what you get is the outline you drew, lying on the surface beneath it. diff --git a/src/annotations/drawTool.js b/src/annotations/drawTool.js index f44d30753d..14a5929eb7 100644 --- a/src/annotations/drawTool.js +++ b/src/annotations/drawTool.js @@ -54,6 +54,7 @@ import { DRAW_COLORS, DRAW_COLOR_CSS, drawMarkActions, + drawMarkGeometry, drawMarkActionsFor, drawMarkFallbackName, presentDrawMarks, @@ -120,6 +121,9 @@ export function initDrawTool({ let savedDoubleClick = null; let savedSingleClick = null; let cursor = null; // last mouse position on the canvas, for the rubber band + // One shape asked for by `drawShape`: `{ resolve, restoreShape, off }`. Its + // finish hands the geometry back instead of placing a mark. + let request = null; // Bumped by anything that supersedes an in-flight finish: cancelling, clearing // the board, leaving draw mode, teardown. An `annotate()` that resolves after // one of those must not write its outcome over the newer state. @@ -280,6 +284,20 @@ export function initDrawTool({ // Named afterwards, in the shape's row. const spec = finishSpec(session, { label: '', color }); if (!spec) return null; + if (request) { + // As a row's actions get it: a shape across the antimeridian has none, + // and is drawn again rather than handed back wrapped round the world. + const geometry = drawMarkGeometry(spec); + if (!geometry) { + session = createDrawSession(shape); + cursor = null; + syncPreview(); + setHint(() => t('That shape could not be placed.')); + return null; + } + endRequest(geometry); + return geometry; + } // Start a fresh session BEFORE awaiting, so a second Enter or the second // half of a double-click cannot submit the same shape twice. session = createDrawSession(shape); @@ -407,6 +425,7 @@ export function initDrawTool({ generation += 1; session = null; cursor = null; + endRequest(null); releaseSceneHandler(); releasePointer(lease); lease = null; @@ -532,6 +551,46 @@ export function initDrawTool({ return true; } + /** + * Close the asked-for shape with `geometry` (null when there is none): the + * shape chosen before it comes back, and draw mode ends. + */ + function endRequest(geometry) { + const open = request; + if (!open) return; + request = null; + open.off(); + chooseShape(open.restoreShape); + open.resolve(geometry); + if (active) setActive(false); + } + + /** + * Draw one area or line and hand back its geometry (a Polygon or a + * LineString) without placing a mark. Escape works as in Draw: the first + * clears a shape in progress, and one on an empty shape leaves. Resolves null + * when draw mode is left, `signal` aborts, or the pointer is taken. + * A second request ends the first with null. + * @param {{shape?: 'area'|'line', signal?: AbortSignal}} [options] + * @returns {Promise<{type: 'Polygon', coordinates: number[][][]}|{type: 'LineString', coordinates: number[][]}|null>} + */ + function drawShape({ shape: wanted = 'area', signal } = {}) { + if (destroyed || signal?.aborted) return Promise.resolve(null); + endRequest(null); + const restoreShape = shape; + return new Promise((resolve) => { + const abort = () => endRequest(null); + signal?.addEventListener('abort', abort, { once: true }); + request = { + resolve, + restoreShape, + off: () => signal?.removeEventListener('abort', abort), + }; + chooseShape(normalizeShape(wanted) === 'line' ? 'line' : 'area'); + if (!active && !setActive(true)) endRequest(null); + }); + } + /** Draw `next` from now on; an open shape starts over in it. */ function chooseShape(next) { shape = normalizeShape(next); @@ -545,7 +604,10 @@ export function initDrawTool({ } const disconnect = connect({ toggleDraw: () => setActive(!active), - setDrawShape: chooseShape, + // An asked-for shape is the one asked for. + setDrawShape: (next) => { + if (!request) chooseShape(next); + }, setDrawColor: (value) => { color = DRAW_COLORS.includes(value) ? value : 'primary'; present(); @@ -602,6 +664,7 @@ export function initDrawTool({ finish, cancel, clearAll, + drawShape, shapes: DRAW_SHAPES, /** What this tool currently holds — for teardown and leak assertions. */ diagnostics() { @@ -638,6 +701,7 @@ export function initDrawTool({ if (destroyed) return attaching; // Supersede any finish still in flight before anything is torn down. generation += 1; + endRequest(null); if (active) setActive(false); destroyed = true; offLocale(); diff --git a/src/annotations/drawToolBehaviour.test.mjs b/src/annotations/drawToolBehaviour.test.mjs index 4cef4d4fe0..2768522484 100644 --- a/src/annotations/drawToolBehaviour.test.mjs +++ b/src/annotations/drawToolBehaviour.test.mjs @@ -704,6 +704,158 @@ test('what a row action answers is its row\'s note; the row is busy until then, } }); +test('drawShape hands back the drawn area as a polygon and places no mark', async () => { + const h = harness(); + try { + h.act('setDrawShape', 'line'); + const drawn = h.tool.drawShape({ shape: 'area' }); + assert.equal(h.tool.active, true, 'it opens draw mode'); + assert.equal(h.tool.shape, 'area'); + h.tool.addVertex(-97.75, 30.26); + h.tool.addVertex(-97.74, 30.26); + h.tool.addVertex(-97.74, 30.27); + h.documentDouble.emit('keydown', { + key: 'Enter', + target: h.documentDouble.body, + }); + const geometry = await drawn; + assert.deepEqual(geometry, { + type: 'Polygon', + coordinates: [ + [ + [-97.75, 30.26], + [-97.74, 30.26], + [-97.74, 30.27], + [-97.75, 30.26], + ], + ], + }); + assert.equal(h.annotations.calls.annotate.length, 0, 'no mark is placed'); + assert.equal(h.tool.active, false, 'draw mode ends'); + assert.equal(isPointerFree(), true); + assert.equal(h.tool.shape, 'line', 'the shape chosen before comes back'); + } finally { + h.restore(); + } +}); + +test('drawShape hands back a line as a LineString', async () => { + const h = harness(); + try { + const drawn = h.tool.drawShape({ shape: 'line' }); + h.tool.addVertex(-97.75, 30.26); + h.tool.addVertex(-97.74, 30.26); + h.documentDouble.emit('keydown', { + key: 'Enter', + target: h.documentDouble.body, + }); + assert.deepEqual(await drawn, { + type: 'LineString', + coordinates: [ + [-97.75, 30.26], + [-97.74, 30.26], + ], + }); + } finally { + h.restore(); + } +}); + +test('drawShape resolves null on Escape, on abort, on a newer request and when the pointer is taken', async () => { + const h = harness(); + try { + // Escape with a shape started clears it; a second Escape leaves. + const escaped = h.tool.drawShape({ shape: 'area' }); + h.tool.addVertex(-97.75, 30.26); + h.documentDouble.emit('keydown', { + key: 'Escape', + target: h.documentDouble.body, + }); + assert.equal(h.tool.active, true, 'the first Escape only clears the shape'); + h.documentDouble.emit('keydown', { + key: 'Escape', + target: h.documentDouble.body, + }); + assert.equal(await escaped, null); + assert.equal(h.tool.active, false); + + const controller = new AbortController(); + const aborted = h.tool.drawShape({ + shape: 'area', + signal: controller.signal, + }); + controller.abort(); + assert.equal(await aborted, null); + assert.equal(isPointerFree(), true, 'an abort gives the pointer back'); + + const first = h.tool.drawShape({ shape: 'area' }); + const second = h.tool.drawShape({ shape: 'line' }); + assert.equal(await first, null, 'a newer request ends the older one'); + h.act('toggleDraw'); + assert.equal(await second, null, 'leaving draw mode ends it'); + + const done = new AbortController(); + done.abort(); + assert.equal(await h.tool.drawShape({ signal: done.signal }), null); + + const other = claimPointer('directions'); + assert.equal( + await h.tool.drawShape({ shape: 'area' }), + null, + 'a held pointer refuses it', + ); + releasePointer(other); + + // Drawing by hand afterwards places marks as before. + h.act('toggleDraw'); + h.tool.addVertex(-97.75, 30.26); + h.tool.addVertex(-97.74, 30.26); + h.tool.addVertex(-97.74, 30.27); + h.documentDouble.emit('keydown', { + key: 'Enter', + target: h.documentDouble.body, + }); + await Promise.resolve(); + assert.equal(h.annotations.calls.annotate.length, 1); + } finally { + h.restore(); + } +}); + +test('drawShape keeps its shape, and a shape across the antimeridian is drawn again', async () => { + const h = harness(); + try { + const drawn = h.tool.drawShape({ shape: 'line' }); + h.act('setDrawShape', 'pin'); + assert.equal(h.tool.shape, 'line', 'the controls cannot change the asked-for shape'); + h.tool.addVertex(179.5, 10); + h.tool.addVertex(-179.5, 10); + h.documentDouble.emit('keydown', { key: 'Enter', target: h.documentDouble.body }); + assert.equal(h.tool.active, true, 'still drawing'); + assert.equal(h.tool.session.vertices.length, 0, 'drawn again from the start'); + assert.equal(h.shown.view.hint, 'That shape could not be placed.'); + h.tool.addVertex(29, 41); + h.tool.addVertex(29.1, 41); + h.documentDouble.emit('keydown', { key: 'Enter', target: h.documentDouble.body }); + assert.equal((await drawn).type, 'LineString'); + h.act('setDrawShape', 'pin'); + assert.equal(h.tool.shape, 'pin', 'after it, the controls choose again'); + } finally { + h.restore(); + } +}); + +test('destroy ends a drawShape request with null', async () => { + const h = harness(); + try { + const drawn = h.tool.drawShape({ shape: 'area' }); + h.tool.destroy(); + assert.equal(await drawn, null); + } finally { + h.restore(); + } +}); + test('Backspace on the page removes the last vertex', () => { const h = harness(); try { diff --git a/src/app/tools.js b/src/app/tools.js index 8925151ad7..9ecb3559a8 100644 --- a/src/app/tools.js +++ b/src/app/tools.js @@ -1,6 +1,7 @@ import { SceneDirector } from '../scenes/director.js'; import { initAnnotations } from '../annotations/index.js'; import { initDrawTool } from '../annotations/drawTool.js'; +import { isPointerFree } from '../data/inputOwnership.js'; import { initGeoFileImport } from '../ui/geoFileImport.js'; import { useDisplayStore } from '../ui/stores/display.js'; import { applicationPinia } from '../ui/vueRuntime.js'; @@ -245,5 +246,17 @@ export function createApplicationTools({ signal, }), ); - return { sceneDirector, annotations, voiceCommands }; + // Draw one area or line and get its geometry back, without placing a mark + // (annotations/drawTool.js `drawShape`); null without the Draw controls. + const drawShape = (options) => + drawTool ? drawTool.drawShape(options) : Promise.resolve(null); + // An application's own click handlers yield while a tool holds the pointer, + // as the layers' do (data/inputOwnership.js). + return { + sceneDirector, + annotations, + voiceCommands, + drawShape, + pointerFree: isPointerFree, + }; } From 0600d8658401bbafdd945344da18e3debbf4e460 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 07:16:52 -0800 Subject: [PATCH 50/61] docs(changelog): Draw hands one shape back (#1641) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89ae0e1e50..7c425d0b67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Applications can ask Draw for one area or line and get its geometry back without placing a mark (`drawShape` from `createApplicationTools`), and their own click handlers can yield while a tool holds the pointer, as the layers' - do (`pointerFree`) (samehkhamis). + do (`pointerFree`) (samehkhamis, #1641). ## [0.3.0] — 2026-10-27 — Street Level, On Your Phone, in Your Language From 75e8e7ddbdb68c01616ed074b00b80bfd1734274 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 19:41:51 +0400 Subject: [PATCH 51/61] refactor(data): describe tile budgets per period, drop a duplicate test, add the changelog entry --- changelog.d/762-tile-budget-module.md | 4 ++++ src/data/tileBudget.js | 22 +++++++++++----------- src/data/tileBudget.test.mjs | 16 ---------------- src/data/tomtomTiles.js | 5 +++-- 4 files changed, 18 insertions(+), 29 deletions(-) create mode 100644 changelog.d/762-tile-budget-module.md diff --git a/changelog.d/762-tile-budget-module.md b/changelog.d/762-tile-budget-module.md new file mode 100644 index 0000000000..6d000d3574 --- /dev/null +++ b/changelog.d/762-tile-budget-module.md @@ -0,0 +1,4 @@ +- Move the tile budget helpers `utcDayKey`, `normalizeBudget` and + `isOverBudget` out of the TomTom module into `src/data/tileBudget.js`, so + other keyed tile proxies can share them. `src/data/tomtomTiles.js` + re-exports them; behaviour does not change (monwiss, #762). diff --git a/src/data/tileBudget.js b/src/data/tileBudget.js index dcc44a28c7..83cf9b6935 100644 --- a/src/data/tileBudget.js +++ b/src/data/tileBudget.js @@ -22,29 +22,29 @@ export function utcDayKey(epochMs = Date.now()) { } /** - * Normalize a persisted budget state against today's UTC day key. - * Rolls the counter to zero on day change; replaces missing/corrupt state. - * Returns the SAME object when it is already valid for `dayKey` (cheap to - * call on every request). + * Normalize a persisted budget state against the current period key. + * Rolls the counter to zero when the period changes; replaces missing/corrupt + * state. Returns the SAME object when it is already valid for `periodKey` + * (cheap to call on every request). * * @param {{date:string, count:number}|null|undefined} state - Persisted state. - * @param {string} dayKey - Today's UTC day key (from `utcDayKey`). - * @returns {{date:string, count:number}} Valid state for `dayKey`. + * @param {string} periodKey - Current period key, e.g. from `utcDayKey`. + * @returns {{date:string, count:number}} Valid state for `periodKey`. */ -export function normalizeBudget(state, dayKey) { +export function normalizeBudget(state, periodKey) { const valid = Boolean(state) && - state.date === dayKey && + state.date === periodKey && Number.isFinite(state.count) && state.count >= 0; - return valid ? state : { date: dayKey, count: 0 }; + return valid ? state : { date: periodKey, count: 0 }; } /** - * Whether the daily soft cap has been reached. + * Whether the soft cap for the current period has been reached. * * @param {{count:number}} state - Normalized budget state. - * @param {number} limit - Daily tile budget; non-positive/invalid never blocks. + * @param {number} limit - Budget per period; non-positive/invalid never blocks. * @returns {boolean} True when `count >= limit`. */ export function isOverBudget(state, limit) { diff --git a/src/data/tileBudget.test.mjs b/src/data/tileBudget.test.mjs index fa48440bbd..c1baa42352 100644 --- a/src/data/tileBudget.test.mjs +++ b/src/data/tileBudget.test.mjs @@ -8,19 +8,3 @@ test('tile budget helpers live in one module and TomTom re-exports them', () => assert.equal(tomtom.normalizeBudget, normalizeBudget); assert.equal(tomtom.isOverBudget, isOverBudget); }); - -test('normalizeBudget keeps a valid state and resets another period', () => { - const state = { date: '2026-09-24', count: 3 }; - assert.equal(normalizeBudget(state, '2026-09-24'), state); - assert.deepEqual(normalizeBudget(state, '2026-09-25'), { - date: '2026-09-25', - count: 0, - }); - assert.deepEqual( - normalizeBudget({ date: '2026-09-24', count: -1 }, '2026-09-24'), - { - date: '2026-09-24', - count: 0, - }, - ); -}); diff --git a/src/data/tomtomTiles.js b/src/data/tomtomTiles.js index 9f3b1f0b99..14101c8313 100644 --- a/src/data/tomtomTiles.js +++ b/src/data/tomtomTiles.js @@ -1,9 +1,10 @@ /** - * @file Pure tile math + budget accounting for the TomTom traffic-flow proxy. + * @file Pure tile math for the TomTom traffic-flow proxy; budget helpers are + * re-exported from `./tileBudget.js`. * * Shared by the `/api/tomtom` vite plugin (server-side: coordinate validation, * daily budget governor) and `src/layers/traffic/flowSource.js` (client-side: which tiles - * cover the current traffic fetch bounds). Zero dependencies, Cesium-free, so + * cover the current traffic fetch bounds). No external dependencies, Cesium-free, so * both sides can unit-test against it with node:test. * * Slippy scheme: standard Web Mercator XYZ, y grows southward From b04fcf191cbaf781cde1db1ff08072dd819f1c5f Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 21:38:07 +0400 Subject: [PATCH 52/61] docs(firms): count two VIIRS sources in the layer table and test note --- docs/CURRENT-STATE.md | 2 +- src/data/firmsInteraction.test.mjs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 102efb997b..6346c1db6d 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4152,7 +4152,7 @@ its criteria cannot be silently ignored. | Datacenters ▣ | OSM extract (bundled) | `src/data/infrastructure.js` | — | static | | Dams ▰ | OpenInfraMap/OSM extract (bundled) | `src/data/infrastructure.js` | — | static | | Submarine Cables ◠ | TeleGeography public map (bundled) | `src/data/telegeographySubmarineCables.js` | — | static | -| FIRMS Active Fires ▲ | NASA FIRMS live (VIIRS ×3 NRT + MODIS NRT, trailing 24h) | `src/data/firmsHeatmap.js` | `/api/firms` (`FIRMS_MAP_KEY`) | 10 min (proxy TTL 30 min) | +| FIRMS Active Fires ▲ | NASA FIRMS live (VIIRS ×2 NRT + MODIS NRT, trailing 24h) | `src/data/firmsHeatmap.js` | `/api/firms` (`FIRMS_MAP_KEY`) | 10 min (proxy TTL 30 min) | | Street Level 📷 | Mapillary street-level imagery (vector tiles, Graph API, MapillaryJS) | `src/layers/streetLevel/` via `src/app/layers/streetLevel.js` | `/api/mapillary/status`, `/api/mapillary/tiles/coverage/{z}/{x}/{y}` (`MAPILLARY_CLIENT_TOKEN`) | camera-driven (320 ms debounce, ≤9 tiles, server memory cache 24 h) | | Wind 🌬 | NOAA GFS 10 m wind (keyless, 0.25°→1° grid; animated particles) | `src/data/wind.js` | `/api/wind` | 1 h (forecast cycle) | | GNSS Integrity 📡 (`gnss-integrity`) | adsb.lol point snapshot, low navigation accuracy binned per 0.5° cell (GEV NIC/NACp threshold + gpsjam.org formula and bands, keyless, ODbL) | `src/layers/gnss/` via `src/app/layers/gnss.js` | `/api/gnss-integrity` | camera-driven (600 ms debounce, minimum 2.5 s between reads) + 60s poll (server cache 60 s; 30 min rolling window) | diff --git a/src/data/firmsInteraction.test.mjs b/src/data/firmsInteraction.test.mjs index d735df3f86..9931c8b32a 100644 --- a/src/data/firmsInteraction.test.mjs +++ b/src/data/firmsInteraction.test.mjs @@ -119,9 +119,10 @@ test('fire detection key survives a refetch that renumbers the index', () => { }); test('two satellites over the same pixel at the same time stay distinct', () => { - // The proxy merges SNPP + NOAA-20 + NOAA-21 without dedup and their orbits - // overlap, so position and time alone are NOT unique. Collapsing them let a - // restored selection land on the other satellite's record. + // The proxy merges NOAA-20 + NOAA-21 without dedup and their orbits overlap, + // so position and time alone are NOT unique. Collapsing them let a restored + // selection land on the other satellite's record. Archived Suomi NPP (`N`) + // rows must stay distinct too. const base = makeFire({ satellite: 'N20' }); const twin = makeFire({ satellite: 'N21' }); const suomi = makeFire({ satellite: 'N' }); From fce5ee6381b948db2f263e1090a19b77d74dd164 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 9 Nov 2026 21:44:09 +0400 Subject: [PATCH 53/61] docs(firms): tighten the Suomi NPP notes --- DATA_SOURCES.md | 2 +- docs/CURRENT-STATE.md | 4 +--- server/providers/firms.js | 7 +++---- src/data/firmsProxy.test.mjs | 6 +++--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 8ceb94e845..ba231df31d 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -329,7 +329,7 @@ and MODIS NRT (Terra + Aqua), clamped to the trailing 24 h, cached 30 min to res transaction quota. Requires a free `FIRMS_MAP_KEY` (https://firms.modaps.eosdis.nasa.gov/api/map_key/); the layer is empty without it. The former bundled 2026-05-25 snapshot was removed 2026-07-16. Suomi NPP (`VIIRS_SNPP_NRT`) -is no longer requested: NASA stopped delivering its data on 2026-11-02. +is not requested: NASA stopped delivering it on 2026-11-02. ### UCS Satellite Database (`ucs_satellites/`) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 417e815519..05240d9227 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -2860,9 +2860,7 @@ reporting are unchanged. ## FIRMS source status The FIRMS proxy requests VIIRS NOAA-20, VIIRS NOAA-21 and MODIS NRT (Terra and -Aqua). It no longer requests VIIRS Suomi NPP: NASA stopped delivering Suomi NPP -data on 2026-11-02, and the source returned no rows while still costing one -MAP_KEY transaction per refresh. +Aqua). It skips VIIRS Suomi NPP, which NASA stopped delivering on 2026-11-02. The FIRMS CSV parser rejects impossible acquisition calendar dates before the proxy filters records to the trailing 24 hours, while retaining valid UTC acquisition times. The `get_active_fires` tool reports acquisition times as UTC ISO timestamps, diff --git a/server/providers/firms.js b/server/providers/firms.js index 51ea4fc567..d21dc296e8 100644 --- a/server/providers/firms.js +++ b/server/providers/firms.js @@ -132,8 +132,8 @@ export async function fetchFirms( * Upstream: https://firms.modaps.eosdis.nasa.gov/api/area/csv/{KEY}/{SOURCE}/world/2 * * Merges two VIIRS NRT sources (NOAA-20, NOAA-21 — independent satellites, no - * cross-source dedup) plus MODIS_NRT (combined Terra+Aqua, - * ~1 km, numeric 0-100 confidence), fetched sequentially (quota courtesy) + * cross-source dedup) plus MODIS_NRT (combined Terra+Aqua, ~1 km, numeric + * 0-100 confidence), fetched sequentially (quota courtesy) * with `days=2` (`days=1` means "current UTC day", nearly empty just after * 00:00Z) and clamps to the trailing 24 h via src/data/firmsCsv.js. FIRMS * quota is 5,000 transactions / 10 min per MAP_KEY, so the cache is the point: @@ -141,8 +141,7 @@ export async function fetchFirms( * fresh-enough disk cache (.gev-cache/firms.json) prevents ANY upstream * fetch across dev-server restarts. Pattern mirrors celestrakProxy. * - * VIIRS_SNPP_NRT is not requested: NASA stopped delivering Suomi NPP data on - * 2026-11-02, so that source only spent a transaction per refresh (#849). + * VIIRS_SNPP_NRT is left out: NASA stopped delivering Suomi NPP on 2026-11-02. * * Routes: * GET /api/firms → {fetchedAt, stale, ttlMs, sources, count, fires} diff --git a/src/data/firmsProxy.test.mjs b/src/data/firmsProxy.test.mjs index dc9ed81447..71c0af4d6a 100644 --- a/src/data/firmsProxy.test.mjs +++ b/src/data/firmsProxy.test.mjs @@ -21,7 +21,7 @@ assert.notEqual(start, -1, 'FIRMS refresh function exists'); const end = config.indexOf('\n }', start); assert.notEqual(end, -1, 'FIRMS refresh function closes'); const refreshSource = config.slice(start, end + 4); -// Read the source list from production so these tests share one source of truth. +// Read the list from production so these tests follow it. const listed = config.match(/const SOURCES = \[([^\]]*)\];/); assert.ok(listed, 'FIRMS source list exists'); const SOURCES = [...listed[1].matchAll(/'([A-Z0-9_]+)'/g)].map((m) => m[1]); @@ -312,7 +312,7 @@ test('every FIRMS upstream request goes through the IPv4 fallback', async () => }); test('FIRMS requests only the satellites NASA still delivers', () => { - // NASA stopped delivering Suomi NPP data on 2026-11-02 (#849): requesting it - // returns no rows and still spends a MAP_KEY transaction on every refresh. + // NASA stopped delivering Suomi NPP on 2026-11-02; asking for it only spends + // a MAP_KEY transaction. assert.ok(!SOURCES.includes('VIIRS_SNPP_NRT')); }); From 04b8c856ad8d155cc1f60bfbf61f23ebd6fe22fb Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 01:25:43 -0800 Subject: [PATCH 54/61] Keep vehicles off rooftops and bridge decks: probe the mesh where the vehicle is On the photoreal stack the rendered-mesh floor took one probe at each coarse cell's centre (0.001 degrees) and kept it for the session. A centre on a roof passed the +80 m DEM window and lifted every vehicle in the cell to roof height (a Haymarket bus drew 23.5 m above the street, on the garage roof); a centre in the river put Red Line trains on the Longfellow Bridge 6-9 m under the deck. The sampler now probes at the caller's point. A cell with a reading is probed again only at spots about 17 m apart from earlier ones, eight at most, and a spot refused only because the cell's DEM prior was cold is tried again later. The floor keeps each reading that passes the gate at the point it was taken (two within about 5 m keep the lower; sixteen at most per cell) and answers a read from the reading nearest the asked point, so a viaduct and the street beside it in one cell keep their own heights. --- docs/CURRENT-STATE.md | 23 ++- src/data/groundFloor.js | 1 + src/data/meshFloorSampler.test.mjs | 179 +++++++++++++++++++++++- src/layers/cctv/geometry.js | 2 +- src/layers/flights/snapshotRenderer.js | 4 +- src/layers/military/snapshotRenderer.js | 4 +- src/services/groundFloor.js | 81 +++++++++-- src/services/groundSnap.js | 2 +- src/services/meshFloorSampler.js | 61 ++++++-- 9 files changed, 329 insertions(+), 28 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 05240d9227..5e7c36be26 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1347,6 +1347,27 @@ and snapshot source. The standalone adapter keeps the existing USGS daily feed, M2.5+ filtering, static discs, magnitude labels and analyst records. Disabling or destroying the layer cancels pending work and ignores late results. +## Rendered-mesh floor readings — November 9, 2026 + +On the photoreal stack the shared floor (`cachedGroundFloor`) answers from +rendered-mesh readings per coarse cell (0.001°, about 110 × 80 m), sampled by +`src/services/meshFloorSampler.js` and gated against the DEM by +`reportValidatedMeshFloorCell` in `src/services/groundFloor.js`. The probe goes +where the caller's point is (a vehicle or contact), not to the cell's centre; +the sampler reads a cell at up to eight spots about 12–17 m or more apart, and +each reading that passes the gate is kept at its point (ground snaps add theirs +the same way; a cell keeps at most sixteen). A read answers from the cell's +reading nearest the asked point, so a viaduct and the street beside it in one +cell keep their own heights; two readings within about 5 m of each other keep +the lower. A spot refused only because the cell's DEM prior was cold is tried +again later. Before this, one probe at the cell's centre latched for the +session, so a centre on a roof lifted everything in the cell (a Haymarket bus +drew 23.5 m above the street, on the garage roof) and a centre in the river put +Red Line trains on the Longfellow Bridge 6–9 m under the deck. Residual: the +probe is vertical, so a vehicle directly under a deck or a roof overhang reads +the structure above it, and a vehicle between readings takes the nearest one, so +its floor steps where the nearest reading changes. + ## Vessel components and sources `src/data/aisLiveVessels.js` assembles `createVesselLayer` from the @@ -3148,7 +3169,7 @@ This is the current runtime/source-of-truth snapshot for the project. > `HELD_SNAP_CONTRADICTION_M` (5 m) ABOVE the held value drops the hold and the > contact is COLD again, back to the floored 2D billboard. The rule is > ONE-SIDED on purpose — it targets BURIAL. A cell reading BELOW a real sample -> is the floor chain's expected under-read (one-shot latch over ~111 m, +> is the floor chain's expected under-read (a few point readings over ~111 m, > neighbours lean lowest, `displayFloorHeightM` only ever raises), not evidence > of anything, and a two-sided cut was disproved on the track rig by a planted > cell 66.7 m below a real sample at the same spot. Accepted residual, stated diff --git a/src/data/groundFloor.js b/src/data/groundFloor.js index fed7a6cd65..978f302185 100644 --- a/src/data/groundFloor.js +++ b/src/data/groundFloor.js @@ -22,6 +22,7 @@ export const { reportMeshFloorCell, meshFloorSampleWithinPrior, reportValidatedMeshFloorCell, + meshFloorPriorReady, cachedMeshFloor, _clearMeshFloorCellsForTest, cachedGroundFloor, diff --git a/src/data/meshFloorSampler.test.mjs b/src/data/meshFloorSampler.test.mjs index f651d72f8c..d33c4873da 100644 --- a/src/data/meshFloorSampler.test.mjs +++ b/src/data/meshFloorSampler.test.mjs @@ -24,7 +24,7 @@ import { sampleMeshFloorCells } from './meshFloorSampler.js'; import { resolveEllipsoidalGround } from './terrainHeights.js'; import { cachedGroundFloor, cachedMeshFloor, setMeshFloorPreferred, - _clearMeshFloorCellsForTest, + _clearMeshFloorCellsForTest, reportValidatedMeshFloorCell, } from './groundFloor.js'; /** Distinct site per test — terrainHeights' cache is module-global and warm @@ -137,3 +137,180 @@ test('sampler: a cell just across the antimeridian is still near the viewer', () sampleMeshFloorCells(scene, [{ lat: -16.81, lon: 179.999 }], { viewerLat: -16.81, viewerLon: -179.999 }); assert.equal(calls, 2, 'about 200 m apart, so both cells are probed'); }); + +test('sampler: the probe goes where the point is, not to the cell centre', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + const asked = []; + const scene = fakeScene((carto) => { + asked.push(Cesium.Math.toDegrees(carto.longitude)); + return 122.0; + }); + const point = { lat: cell.lat + 0.0003, lon: cell.lon + 0.0004 }; + sampleMeshFloorCells(scene, [point], { viewerLat: cell.lat, viewerLon: cell.lon }); + assert.equal(asked.length, 1); + assert.ok(Math.abs(asked[0] - point.lon) < 1e-9, `probed at ${asked[0]}, not ${point.lon}`); +}); + +test('sampler: a viaduct and the street beside it in one cell keep their own heights', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + // A viaduct deck 9 m up along one line of the cell, the street elsewhere. + const deckLat = cell.lat + 0.0003; + let calls = 0; + const scene = fakeScene((carto) => { + calls += 1; + return Math.abs(Cesium.Math.toDegrees(carto.latitude) - deckLat) < 1e-7 ? 129.0 : 121.0; + }); + const opts = { viewerLat: cell.lat, viewerLon: cell.lon }; + const onDeck = { lat: deckLat, lon: cell.lon }; + const street = { lat: cell.lat - 0.0003, lon: cell.lon }; + sampleMeshFloorCells(scene, [onDeck], opts); + sampleMeshFloorCells(scene, [street], opts); + assert.equal(calls, 2); + assert.equal(cachedMeshFloor(onDeck.lat, onDeck.lon + 0.0001), 129.0, 'the train stays on the deck'); + assert.equal(cachedMeshFloor(street.lat, street.lon - 0.0001), 121.0, 'the bus stays on the street'); + assert.equal(cachedGroundFloor(street.lat, street.lon), 121.0); + sampleMeshFloorCells(scene, [{ lat: deckLat, lon: cell.lon + 0.00001 }], opts); + assert.equal(calls, 2, 'a point next to one already probed is not probed again'); +}); + +test('sampler: a roof over the cell centre does not lift a bus on the street', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + // A roof 22 m up covering the cell's centre; the street 30 m west of it. + const scene = fakeScene((carto) => + Math.abs(Cesium.Math.toDegrees(carto.longitude) - cell.lon) < 0.0001 ? 142.0 : 121.0); + const bus = { lat: cell.lat, lon: cell.lon - 0.0003 }; + sampleMeshFloorCells(scene, [bus], { viewerLat: cell.lat, viewerLon: cell.lon }); + assert.equal(cachedGroundFloor(bus.lat, bus.lon), 121.0); +}); + +test('sampler: a second reading at the same spot keeps the lower one', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + assert.equal(reportValidatedMeshFloorCell(cell.lat, cell.lon, 131.0), true); + assert.equal(reportValidatedMeshFloorCell(cell.lat + 0.00002, cell.lon, 122.0), true); + assert.equal(cachedMeshFloor(cell.lat, cell.lon), 122.0); + assert.equal(reportValidatedMeshFloorCell(cell.lat, cell.lon + 0.00002, 140.0), true); + assert.equal(cachedMeshFloor(cell.lat, cell.lon), 122.0, 'a higher one never raises it'); +}); + +test('sampler: a cell with a reading is probed a few times at most', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + let calls = 0; + const scene = fakeScene(() => { + calls += 1; + return 121.0; + }); + const opts = { viewerLat: cell.lat, viewerLon: cell.lon }; + for (let i = 0; i < 20; i++) + sampleMeshFloorCells( + scene, + [{ lat: cell.lat - 0.0004 + (i % 5) * 0.0002, lon: cell.lon - 0.00045 + Math.floor(i / 5) * 0.0003 }], + opts, + ); + assert.equal(calls, 8); +}); + +test('sampler: a cell with no accepted reading is probed again on every call', async () => { + reset(); + const cell = nextSite(); + let calls = 0; + const scene = fakeScene(() => { + calls += 1; + return 138.0; + }); + const opts = { viewerLat: cell.lat, viewerLon: cell.lon }; + for (let i = 0; i < 3; i++) sampleMeshFloorCells(scene, [cell], opts); + assert.equal(calls, 3, 'no DEM prior yet, so nothing is kept and the cell is retried'); + await seedDem(cell, 120.0); + sampleMeshFloorCells(scene, [cell], opts); + assert.equal(cachedMeshFloor(cell.lat, cell.lon), 138.0, 'and lands once the prior is warm'); +}); + +test('sampler: a spot whose reading is refused does not use up the cell', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + // A tower 260 m up where the first vehicle waits; the street elsewhere and + // a deck 9 m up along one line of the cell. + const towerLon = cell.lon + 0.0004; + const deckLat = cell.lat + 0.0003; + const scene = fakeScene((carto) => { + if (Math.abs(Cesium.Math.toDegrees(carto.longitude) - towerLon) < 1e-7) return 380.0; + return Math.abs(Cesium.Math.toDegrees(carto.latitude) - deckLat) < 1e-7 ? 129.0 : 121.0; + }); + const opts = { viewerLat: cell.lat, viewerLon: cell.lon }; + for (let i = 0; i < 10; i++) sampleMeshFloorCells(scene, [{ lat: cell.lat, lon: towerLon }], opts); + assert.equal(cachedMeshFloor(cell.lat, cell.lon), null, 'the tower is refused every time'); + sampleMeshFloorCells(scene, [{ lat: cell.lat - 0.0003, lon: cell.lon }], opts); + sampleMeshFloorCells(scene, [{ lat: deckLat, lon: cell.lon - 0.0003 }], opts); + assert.equal(cachedMeshFloor(deckLat, cell.lon - 0.0003), 129.0, 'the deck is still probed'); +}); + +test('ground floor: a cell keeps at most sixteen readings', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + for (let i = 0; i < 40; i++) { + const lat = cell.lat - 0.00045 + (i % 8) * 0.0001; + const lon = cell.lon - 0.00045 + Math.floor(i / 8) * 0.0002; + reportValidatedMeshFloorCell(lat, lon, 121.0 + i); + } + // Readings 0..15 are kept; reading 39 (at the far corner) is not, so that + // spot answers from the nearest kept one. + assert.equal(cachedMeshFloor(cell.lat - 0.00045, cell.lon - 0.00045), 121.0); + assert.equal(cachedMeshFloor(cell.lat + 0.00025, cell.lon + 0.00035), 121.0 + 15); +}); + +test('sampler: a spot refused while the DEM was cold is probed again once it is warm', async () => { + reset(); + const cell = nextSite(); + const deckLat = cell.lat + 0.0003; + let calls = 0; + const scene = fakeScene((carto) => { + calls += 1; + return Math.abs(Cesium.Math.toDegrees(carto.latitude) - deckLat) < 1e-7 ? 129.0 : 121.0; + }); + const opts = { viewerLat: cell.lat, viewerLon: cell.lon }; + const onDeck = { lat: deckLat, lon: cell.lon }; + sampleMeshFloorCells(scene, [onDeck], opts); + assert.equal(cachedMeshFloor(onDeck.lat, onDeck.lon), null, 'no prior, nothing kept'); + await seedDem(cell, 120.0); + sampleMeshFloorCells(scene, [{ lat: cell.lat - 0.0003, lon: cell.lon }], opts); + sampleMeshFloorCells(scene, [onDeck], opts); + assert.equal(calls, 3); + assert.equal(cachedMeshFloor(onDeck.lat, onDeck.lon), 129.0); +}); + +test('sampler: a spot refused while the DEM prior was evicted is probed again', async () => { + const { createGroundFloor } = await import('../services/groundFloor.js'); + const { createMeshFloorSampler } = await import('../services/meshFloorSampler.js'); + let prior = 120.0; + const terrain = { + cachedRealEllipsoidalGround: () => prior, + resolveEllipsoidalGround: async () => {}, + }; + const groundFloor = createGroundFloor({ terrain }); + const sampler = createMeshFloorSampler({ groundFloor }); + const cell = { lat: 41.5, lon: -97.66 }; + const deckLat = cell.lat + 0.0003; + const scene = fakeScene((carto) => + Math.abs(Cesium.Math.toDegrees(carto.latitude) - deckLat) < 1e-7 ? 129.0 : 121.0); + const opts = { viewerLat: cell.lat, viewerLon: cell.lon }; + const onDeck = { lat: deckLat, lon: cell.lon }; + sampler.sampleMeshFloorCells(scene, [{ lat: cell.lat - 0.0003, lon: cell.lon }], opts); + prior = null; // the cell's DEM entry is evicted; the street reading stays + sampler.sampleMeshFloorCells(scene, [onDeck], opts); + assert.equal(groundFloor.cachedMeshFloor(onDeck.lat, onDeck.lon), 121.0); + prior = 120.0; + sampler.sampleMeshFloorCells(scene, [onDeck], opts); + assert.equal(groundFloor.cachedMeshFloor(onDeck.lat, onDeck.lon), 129.0); +}); diff --git a/src/layers/cctv/geometry.js b/src/layers/cctv/geometry.js index 362ad47897..a1402c6c20 100644 --- a/src/layers/cctv/geometry.js +++ b/src/layers/cctv/geometry.js @@ -448,7 +448,7 @@ export function createGeometry({ state: layerState, services, parts, source }) { } // Photoreal regime. Sampling is delegated to the shared coarse-cell - // sampler. It remains event-driven, one-shot per cell, and keeps its + // sampler. It remains event-driven, a few probes per cell, and keeps its // existing acceptance window; CCTV adds no rooftop rejection policy. if (sampleGround && parts.model.projectionTilesReady()) { record.groundMeshSampleRequestCount = diff --git a/src/layers/flights/snapshotRenderer.js b/src/layers/flights/snapshotRenderer.js index ec6c2933b3..d48d127741 100644 --- a/src/layers/flights/snapshotRenderer.js +++ b/src/layers/flights/snapshotRenderer.js @@ -300,8 +300,8 @@ export function createFlightSnapshotRenderer({ // floor cells collected in the loop (fire-and-forget, single-flight; // read synchronously by NEXT poll's clamp — the military-layer pattern). warmGroundFloor(floorWarmPoints); - // Round 4: sample the RENDERED mesh for those same cells (one-shot per - // cell, budget-capped, viewer-proximate, google-3d regime only). Own + // Round 4: sample the RENDERED mesh for those same cells (a few probes + // per cell, budget-capped, viewer-proximate, google-3d regime only). Own // billboards/models are excluded so a vertical probe can't land on an // aircraft instead of the pavement. sampleMeshFloorCells(flightState._viewer?.scene, floorWarmPoints, { diff --git a/src/layers/military/snapshotRenderer.js b/src/layers/military/snapshotRenderer.js index 7ed2b1c1fe..eb3a341f8e 100644 --- a/src/layers/military/snapshotRenderer.js +++ b/src/layers/military/snapshotRenderer.js @@ -228,8 +228,8 @@ export function createMilitarySnapshotRenderer({ const bbStale = flightState._billboards.get(icao24); if (bbStale) bbStale.position = liftedPos; } - // Round 4: sample the RENDERED mesh for those cells (one-shot per cell, - // budget-capped, viewer-proximate, google-3d regime only), excluding + // Round 4: sample the RENDERED mesh for those cells (a few probes per + // cell, budget-capped, viewer-proximate, google-3d regime only), excluding // this layer's own billboards/models from the probe. { const viewerCarto = diff --git a/src/services/groundFloor.js b/src/services/groundFloor.js index 27b7dc5e4c..3b4939fc58 100644 --- a/src/services/groundFloor.js +++ b/src/services/groundFloor.js @@ -418,13 +418,26 @@ export function createGroundFloor({ terrain, signal }) { // is the photogrammetric MESH, which sits above it (measured ~17 m at the // Austin airport apron). DEM-flooring therefore still buried sprites/trails // inside the mesh. These cells hold the RENDERED surface height, sampled - // one-shot per coarse cell near the viewer (scene.sampleHeight — the same + // at the callers' points, a few per coarse cell near the viewer, each kept + // where it was taken and read back from the nearest (scene.sampleHeight — the same // source groundSnap uses, which is why 3D models always looked right) and // reported here by meshFloorSampler.js. Design principle (owner): NEVER // below the visible surface; slightly above is always fine. The DEM stays // the instant global prior/fallback and the sanity gate for samples. - /** @type {Map} coarse cell key -> rendered-surface height (m, ellipsoidal). */ + /** @type {Map>} + * coarse cell key -> rendered-surface readings (m, ellipsoidal), each kept + * at the point it was probed. A read answers from the reading nearest the + * asked point, so a viaduct and the street beside it in one cell keep their + * own heights. */ const _meshCells = new Map(); + /** @constant {number} Readings closer than this (degrees, about 5 m) are + * one spot: the lower one is kept there. */ + const MESH_READING_SAME_SPOT_DEG = 0.00005; + /** @constant {number} Readings kept per cell. The sampler probes a cell at + * most eight times, but ground snaps report at each aircraft's position; + * past this many, a reading away from the others is not kept, so a busy + * apron cell stays a short list to scan. */ + const MESH_READINGS_PER_CELL = 16; /** @type {boolean} Whether mesh cells apply — true only in the google-3d * regime (photoreal stack). On globe stacks the rendered surface IS the * terrain provider (Re:Earth on keyless), so the DEM is already correct @@ -444,7 +457,8 @@ export function createGroundFloor({ terrain, signal }) { /** * Records a sampled rendered-surface height for the cell containing the - * coordinate (one-shot latch — first accepted sample wins). + * coordinate, unchecked, when the cell has no reading yet. The sampler goes + * through `reportValidatedMeshFloorCell`, which keeps a reading per point. * @param {number} lat @param {number} lon @param {number} heightM */ function reportMeshFloorCell(lat, lon, heightM) { @@ -456,7 +470,7 @@ export function createGroundFloor({ terrain, signal }) { return; const c = coarseFloorCoord(lat, lon); const key = `${c.lat},${c.lon}`; - if (!_meshCells.has(key)) _meshCells.set(key, heightM); + if (!_meshCells.has(key)) _meshCells.set(key, [{ lat, lon, h: heightM }]); } /** Return whether a rendered-mesh sample is plausible against a real DEM prior. */ @@ -471,9 +485,11 @@ export function createGroundFloor({ terrain, signal }) { /** * Validate and record a rendered-mesh floor through the single shared gate. - * Callers must not bypass this with raw `reportMeshFloorCell`: a coarse-LOD, - * rooftop, or aircraft hit would otherwise win the session-long first-write - * latch and poison every floor consumer in the cell. + * Callers must not bypass this with raw `reportMeshFloorCell`: a coarse-LOD + * or aircraft hit would otherwise poison every floor consumer in the cell. + * The reading is kept at the point it was taken; a second reading at the + * same spot (within about 5 m) keeps the lower of the two. A cell keeps at + * most MESH_READINGS_PER_CELL readings. * @returns {boolean} Whether the sample passed and was reported. */ function reportValidatedMeshFloorCell(lat, lon, heightM) { @@ -481,13 +497,41 @@ export function createGroundFloor({ terrain, signal }) { const cell = coarseFloorCoord(lat, lon); const prior = cachedRealEllipsoidalGround(cell.lat, cell.lon); if (!meshFloorSampleWithinPrior(heightM, prior)) return false; - reportMeshFloorCell(cell.lat, cell.lon, heightM); + const key = `${cell.lat},${cell.lon}`; + const readings = _meshCells.get(key); + if (!readings) { + _meshCells.set(key, [{ lat, lon, h: heightM }]); + return true; + } + const same = readings.find( + (r) => + Math.abs(r.lat - lat) < MESH_READING_SAME_SPOT_DEG && + Math.abs(r.lon - lon) < MESH_READING_SAME_SPOT_DEG, + ); + if (same) { + if (heightM < same.h) same.h = heightM; + } else if (readings.length < MESH_READINGS_PER_CELL) { + readings.push({ lat, lon, h: heightM }); + } return true; } /** - * Synchronous mesh-cell read — null when the cell is unsampled OR the - * google-3d regime is inactive (globe stacks must floor on the DEM). + * Whether the cell holding the point has the real DEM prior that + * `reportValidatedMeshFloorCell` judges a reading against. + * @param {number} lat @param {number} lon + * @returns {boolean} + */ + function meshFloorPriorReady(lat, lon) { + if (!Number.isFinite(lat) || !Number.isFinite(lon)) return false; + const c = coarseFloorCoord(lat, lon); + return cachedRealEllipsoidalGround(c.lat, c.lon) != null; + } + + /** + * Synchronous mesh-cell read — the cell's reading nearest the point, or + * null when the cell is unsampled OR the google-3d regime is inactive (globe + * stacks must floor on the DEM). * @param {number} lat @param {number} lon * @returns {number|null} */ @@ -495,8 +539,20 @@ export function createGroundFloor({ terrain, signal }) { if (!_meshPreferred) return null; if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null; const c = coarseFloorCoord(lat, lon); - const h = _meshCells.get(`${c.lat},${c.lon}`); - return h != null ? h : null; + const readings = _meshCells.get(`${c.lat},${c.lon}`); + if (!readings) return null; + if (readings.length === 1) return readings[0].h; + const k = Math.cos((lat * Math.PI) / 180) ** 2; + let best = readings[0], + bestD = Infinity; + for (const r of readings) { + const d = (r.lat - lat) ** 2 + k * (r.lon - lon) ** 2; + if (d < bestD) { + bestD = d; + best = r; + } + } + return best.h; } /** Test hook: clears mesh cells (never called at runtime — cells are valid all session). */ @@ -662,6 +718,7 @@ export function createGroundFloor({ terrain, signal }) { reportMeshFloorCell, meshFloorSampleWithinPrior, reportValidatedMeshFloorCell, + meshFloorPriorReady, cachedMeshFloor, _clearMeshFloorCellsForTest, cachedGroundFloor, diff --git a/src/services/groundSnap.js b/src/services/groundSnap.js index eecb1fa34f..b1d75cfbb9 100644 --- a/src/services/groundSnap.js +++ b/src/services/groundSnap.js @@ -101,7 +101,7 @@ const HELD_SNAP_MAX_DRIFT_M = 250; * alone, and the asymmetry is not tidiness: * * - A cell reading LOW against a real sample is the EXPECTED error here, not a - * contradiction. Cells are a one-shot first-write latch over ~111 m, the + * contradiction. Cells hold a few point readings over ~111 m, the * borrowed-neighbour path leans to the LOWEST on purpose (`neighborFloorM`), * and `displayFloorHeightM` only ever RAISES — the whole floor chain is * built to under-read rather than to invent. Releasing on that sign would diff --git a/src/services/meshFloorSampler.js b/src/services/meshFloorSampler.js index c967f80c81..083789ea90 100644 --- a/src/services/meshFloorSampler.js +++ b/src/services/meshFloorSampler.js @@ -11,6 +11,7 @@ export function createMeshFloorSampler({ coarseFloorCoord, cachedMeshFloor, reportValidatedMeshFloorCell, + meshFloorPriorReady, setMeshFloorPreferred, meshFloorPreferred, cachedGroundFloor, @@ -23,13 +24,16 @@ export function createMeshFloorSampler({ // which sits above the Re:Earth bare-earth DEM (measured ~17 m at the Austin // airport apron) — so DEM-floored sprites/trails still buried themselves in // the mesh while 3D models (which groundSnap against the mesh) looked right. - // This module samples the mesh height ONE-SHOT per coarse cell and reports it - // to groundFloor.js, whose cachedGroundFloor() then answers mesh-first. + // This module samples the mesh height at the callers' points, a few probes + // per coarse cell, and reports them to groundFloor.js, which keeps each + // reading that passes its gate at its own point; cachedGroundFloor() then + // answers mesh-first, from the reading nearest the asked point. // // Rationing (the CCTV loading-jitter lesson): scene.sampleHeight forces // tile-load prioritization at the probe point, so sampling is (a) gated to // cells NEAR the viewer — where tiles are streamed and where an error is - // visible at all, (b) capped per call, (c) one-shot per cell for the session, + // visible at all, (b) capped per call, (c) at most MAX_PROBES_PER_CELL + // readings per cell for the session, each at a point apart from the others, // (d) skipped entirely outside the google-3d regime. A returned-undefined // probe (tiles not streamed yet) is NOT latched — it retries on a later call. // @@ -49,6 +53,16 @@ export function createMeshFloorSampler({ * streamed LOD under a high camera is coarse everywhere, so every probe * would latch junk. */ const MAX_CAMERA_HEIGHT_M = 25_000; + /** @constant {number} Readings per cell: a cell is probed at most this + * many times, each at a point apart from the others, and groundFloor keeps + * each reading at its point (a read answers from the nearest one). */ + const MAX_PROBES_PER_CELL = 8; + /** @constant {number} How far apart (degrees, about 17 m) a new probe must + * be from the cell's earlier ones to be worth taking. */ + const PROBE_APART_DEG = 0.00015; + /** @type {Map>} Points probed + * per cell that returned a reading. */ + const _probedPoints = new Map(); /** @type {Cesium.Cartographic} Scratch for probe coordinates. */ const _scratchProbe = new Cesium.Cartographic(); @@ -82,7 +96,7 @@ export function createMeshFloorSampler({ /** * Samples the rendered mesh height for the coarse cells containing `points`, - * one-shot per cell, budget-capped, viewer-proximity-gated. Call ONCE per + * a few probes per cell, budget-capped, viewer-proximity-gated. Call ONCE per * layer poll (never per contact, never per frame). Synchronous — Cesium's * sampleHeight is a CPU-side query against loaded tiles. * @@ -119,8 +133,21 @@ export function createMeshFloorSampler({ const cell = coarseFloorCoord(p.lat, p.lon); const key = `${cell.lat},${cell.lon}`; if (attempted.has(key)) continue; + // A cell with a reading is probed again only at a point well apart + // from the ones already probed, a few times at most, so the cell's + // readings follow where its vehicles actually are. + const probes = _probedPoints.get(key); + if ( + cachedMeshFloor(cell.lat, cell.lon) != null && + (probes?.length >= MAX_PROBES_PER_CELL || + probes?.some( + (q) => + Math.abs(q.lat - p.lat) < PROBE_APART_DEG && + Math.abs(q.lon - p.lon) < PROBE_APART_DEG, + )) + ) + continue; attempted.add(key); - if (cachedMeshFloor(cell.lat, cell.lon) != null) continue; // one-shot latch if ( Number.isFinite(viewerLat) && Number.isFinite(viewerLon) && @@ -131,9 +158,11 @@ export function createMeshFloorSampler({ } let height; try { + // Probe where the caller's point is, not at the cell's centre: a + // centre that falls on a roof would lift everything in the cell. const carto = Cesium.Cartographic.fromDegrees( - cell.lon, - cell.lat, + p.lon, + p.lat, 0, _scratchProbe, ); @@ -171,7 +200,23 @@ export function createMeshFloorSampler({ // feasible and deliberately deferred — see the P2 in // the project roadmap, which bundles it with the fly_route probe so // one post-launch pass settles rendered-mesh sampling everywhere. - reportValidatedMeshFloorCell(cell.lat, cell.lon, height); + const accepted = reportValidatedMeshFloorCell(p.lat, p.lon, height); + // A spot counts as probed once the gate has judged it against a real + // prior: accepted, or refused with the cell's DEM warm. A spot refused + // only because the DEM was still cold is tried again later. Each spot is + // recorded once, so a cell retried while it has no reading does not fill + // its probe allowance with the same spot. + if (!accepted && !meshFloorPriorReady(cell.lat, cell.lon)) continue; + if (!probes) _probedPoints.set(key, [{ lat: p.lat, lon: p.lon }]); + else if ( + probes.length < MAX_PROBES_PER_CELL && + !probes.some( + (q) => + Math.abs(q.lat - p.lat) < PROBE_APART_DEG && + Math.abs(q.lon - p.lon) < PROBE_APART_DEG, + ) + ) + probes.push({ lat: p.lat, lon: p.lon }); } } From 9bce41d3c6a83125ac496ad3b6abeea6ca200f3b Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 01:26:01 -0800 Subject: [PATCH 55/61] Read the mesh floor where transit vehicles and grounded flights actually are With readings kept per point, the floor a vehicle gets depends on which point is probed and where it is read. Transit offered the sampler the first point of each vehicle's path in a cell, usually its oldest fix there, so a vehicle that stayed in one cell never had its current spot probed. It now offers the latest point of the path in each cell, and the newest fix in the vehicle's own cell (the selected vehicle's history is walked newest first). The grounded-flight display clamp read the floor at its sticky cell's centre, which now answers from the reading nearest the centre, not the contact. It reads at the contact's own position, held inside the sticky cell so boundary hysteresis still applies. --- docs/CURRENT-STATE.md | 17 ++-- src/data/flights.test.mjs | 35 +++++++++ src/layers/flights/motion.js | 29 +++++-- src/layers/transit/height.js | 16 +++- src/layers/transit/lifecycle.test.mjs | 108 ++++++++++++++++++++++++++ 5 files changed, 192 insertions(+), 13 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 5e7c36be26..0739cf5e15 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1360,13 +1360,16 @@ the same way; a cell keeps at most sixteen). A read answers from the cell's reading nearest the asked point, so a viaduct and the street beside it in one cell keep their own heights; two readings within about 5 m of each other keep the lower. A spot refused only because the cell's DEM prior was cold is tried -again later. Before this, one probe at the cell's centre latched for the -session, so a centre on a roof lifted everything in the cell (a Haymarket bus -drew 23.5 m above the street, on the garage roof) and a centre in the river put -Red Line trains on the Longfellow Bridge 6–9 m under the deck. Residual: the -probe is vertical, so a vehicle directly under a deck or a roof overhang reads -the structure above it, and a vehicle between readings takes the nearest one, so -its floor steps where the nearest reading changes. +again later. Transit offers the sampler the latest point of each vehicle's path +in a cell (its newest fix in its own cell), and the grounded-flight display +clamp reads at the contact, held inside its sticky cell. Before this, one probe +at the cell's centre latched for the session, so a centre on a roof lifted +everything in the cell (a Haymarket bus drew 23.5 m above the street, on the +garage roof) and a centre in the river put Red Line trains on the Longfellow +Bridge 6–9 m under the deck. Residual: the probe is vertical, so a vehicle +directly under a deck or a roof overhang reads the structure above it, and a +vehicle between readings takes the nearest one, so its floor steps where the +nearest reading changes. ## Vessel components and sources diff --git a/src/data/flights.test.mjs b/src/data/flights.test.mjs index 7fe197c303..1d6007e8f3 100644 --- a/src/data/flights.test.mjs +++ b/src/data/flights.test.mjs @@ -20,9 +20,11 @@ import { setMilitaryLayerActive } from './militaryRegistry.js'; import { GROUND_FLOOR_LIFT_M, reportMeshFloorCell, + reportValidatedMeshFloorCell, setMeshFloorPreferred, _clearMeshFloorCellsForTest, } from './groundFloor.js'; +import { resolveEllipsoidalGround } from './terrainHeights.js'; import { _setTrackedOverlayHostForTest, destroyTrackedReadout, @@ -1181,6 +1183,39 @@ test('display floor: a grounded contact that drifted onto a higher cell is lifte assert.ok(Math.abs(Cesium.Math.toDegrees(c.longitude) + 97.6604) < 1e-6); }); +test('display floor: reads the reading nearest the contact, not the cell centre', async () => { + _clearDisplayFloorStateForTest(); + _clearMeshFloorCellsForTest(); + setMeshFloorPreferred(true); + const realFetch = globalThis.fetch; + globalThis.fetch = async () => + new Response(JSON.stringify({ results: [{ ellipsoid: 120 }] }), { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }); + try { + await resolveEllipsoidalGround([{ lat: 30.317, lon: -97.717 }]); + } finally { + globalThis.fetch = realFetch; + } + // A hangar roof over the cell's centre; the apron where the contact is. + assert.equal(reportValidatedMeshFloorCell(30.317, -97.717, 142), true); + assert.equal(reportValidatedMeshFloorCell(30.3173, -97.7173, 121), true); + const pos = Cesium.Cartesian3.fromDegrees(-97.7173, 30.3173, 100); + const out = _floorGroundedDisplayPositionForTest( + { onGround: true }, + pos, + false, + ); + const c = _floorCarto(out); + assert.ok( + Math.abs(c.height - (121 + GROUND_FLOOR_LIFT_M)) < 0.05, + `height ${c.height} should be the apron's 121 + lift`, + ); + _clearMeshFloorCellsForTest(); + _clearDisplayFloorStateForTest(); +}); + test('display floor: an AIRBORNE contact over the same cell is never lifted', () => { _clearDisplayFloorStateForTest(); _clearMeshFloorCellsForTest(); diff --git a/src/layers/flights/motion.js b/src/layers/flights/motion.js index a14c8c4ac1..c095221539 100644 --- a/src/layers/flights/motion.js +++ b/src/layers/flights/motion.js @@ -37,6 +37,22 @@ import { DISPLAY_CORRIDOR_FAIR_SHARE, } from './policy.js'; +/** Half a coarse floor cell (0.001°), less a margin so rounding keeps a + * clamped coordinate inside the cell. */ +const HALF_CELL_DEG = 0.00049; + +/** + * A coordinate held within half a cell of the cell's centre (the short way + * round for longitude), so a read lands in the given cell. + * @param {number} deg @param {number} centreDeg + * @returns {number} + */ +function clampToCell(deg, centreDeg) { + let d = deg - centreDeg; + d -= 360 * Math.round(d / 360); + return centreDeg + Math.max(-HALF_CELL_DEG, Math.min(HALF_CELL_DEG, d)); +} + export function createMotion({ flightState, services, @@ -865,12 +881,15 @@ export function createMotion({ ); // Boundary hysteresis: a position jittering across a cell edge would flip // floors at fleet-tick rate (see stickyFloorCell). - const cell = stickyFloorCell( - Cesium.Math.toDegrees(carto.latitude), - Cesium.Math.toDegrees(carto.longitude), - state?.cell, + const latDeg = Cesium.Math.toDegrees(carto.latitude); + const lonDeg = Cesium.Math.toDegrees(carto.longitude); + const cell = stickyFloorCell(latDeg, lonDeg, state?.cell); + // A cell holds rendered-surface readings at the points they were taken, + // so the floor is read where the contact is, held inside its sticky cell. + const floor = cachedGroundFloor( + clampToCell(latDeg, cell.lat), + clampToCell(lonDeg, cell.lon), ); - const floor = cachedGroundFloor(cell.lat, cell.lon); const next = state || { cell, in: new Cesium.Cartesian3(), diff --git a/src/layers/transit/height.js b/src/layers/transit/height.js index 2e2945a88c..027dc7d412 100644 --- a/src/layers/transit/height.js +++ b/src/layers/transit/height.js @@ -124,7 +124,14 @@ export function createHeight({ state, services, parts }) { const cells = new Map(); const collect = (point, answer) => { if (!onGround) return; - if (!cells.has(answer.cell)) + // A cell keeps the last point offered in it: the path is walked + // oldest first, so that is where the vehicle is now or about to be, + // and the mesh sampler reads the surface there. + const held = cells.get(answer.cell); + if (held) { + held.lat = point.lat; + held.lon = point.lon; + } else cells.set(answer.cell, { lat: point.lat, lon: point.lon, @@ -136,6 +143,13 @@ export function createHeight({ state, services, parts }) { const newest = entry.fixes.at(-1); const answer = requestHeight(newest.lat, newest.lon, entry); entry.heightCell = answer.cell; + // The selected vehicle's path also offers its history, newest segment + // first; the vehicle's own cell is read where its newest fix is. + const own = cells.get(answer.cell); + if (own) { + own.lat = newest.lat; + own.lon = newest.lon; + } if (answer.height !== null) { entry.heightM = answer.height; entry.heightResolved = true; diff --git a/src/layers/transit/lifecycle.test.mjs b/src/layers/transit/lifecycle.test.mjs index e36d87de84..fee9a60ed0 100644 --- a/src/layers/transit/lifecycle.test.mjs +++ b/src/layers/transit/lifecycle.test.mjs @@ -2938,6 +2938,114 @@ test('mesh refinement reaches all 100 retained DEM cells within five poll budget assert.equal(probed.size, 100); }); +test('mesh refinement probes the latest point the path offers in a cell', async (t) => { + const { createHeight } = await import('./height.js'); + // Three points along one cell's stretch of path, oldest first. + const path = [ + { lat: 42.3611, lon: -71.0751 }, + { lat: 42.3612, lon: -71.0753 }, + { lat: 42.3614, lon: -71.0754 }, + ]; + const entry = { key: 'train', to: path[0], fixes: [path.at(-1)] }; + const probed = []; + const state = { + _enabled: true, + _selectedKey: null, + _visible: new Set([entry]), + _vehicles: new Map([[entry.key, entry]]), + _floorCursor: 0, + _heightDirty: new Set(), + _viewer: { camera: { positionCartographic: { height: 100 } } }, + }; + const height = createHeight({ + state, + services: { + render: { governorRequestRender() {} }, + ground: { + coarseFloorCoord: (lat, lon) => ({ + lat: Number(lat.toFixed(3)), + lon: Number(lon.toFixed(3)), + }), + cachedGroundFloor: () => 10, + GROUND_FLOOR_LIFT_M: 1.5, + }, + mesh: { + sampleMeshFloorCells(scene, points) { + probed.push(...points.map((p) => [p.lat, p.lon])); + }, + }, + }, + parts: { + trails: { + prepareEntry(e, collect) { + if (collect) + for (const point of path) + collect(point, height.requestHeight(point.lat, point.lon)); + }, + }, + rendering: { requestVisibility() {} }, + }, + }); + t.after(() => height.clear()); + height.anchorFloors(); + assert.deepEqual(probed, [[42.3614, -71.0754]]); +}); + +test('the selected vehicle is probed at its newest fix in its own cell', async (t) => { + const { createHeight } = await import('./height.js'); + // The selected path offers its active corridor first, then its history + // newest segment first, so the last offer in the cell is an older point. + const newest = { lat: 42.3614, lon: -71.0754 }; + const offers = [ + newest, + { lat: 42.3612, lon: -71.0753 }, + { lat: 42.3611, lon: -71.0751 }, + ]; + const entry = { key: 'train', to: offers[0], fixes: [newest] }; + const probed = []; + const state = { + _enabled: true, + _selectedKey: entry.key, + _visible: new Set([entry]), + _vehicles: new Map([[entry.key, entry]]), + _floorCursor: 0, + _heightDirty: new Set(), + _viewer: { camera: { positionCartographic: { height: 100 } } }, + }; + const height = createHeight({ + state, + services: { + render: { governorRequestRender() {} }, + ground: { + coarseFloorCoord: (lat, lon) => ({ + lat: Number(lat.toFixed(3)), + lon: Number(lon.toFixed(3)), + }), + cachedGroundFloor: () => 10, + GROUND_FLOOR_LIFT_M: 1.5, + }, + mesh: { + sampleMeshFloorCells(scene, points) { + probed.push(...points.map((p) => [p.lat, p.lon])); + }, + }, + }, + parts: { + trails: { + prepareEntry(e, collect) { + if (collect) + for (const point of offers) + collect(point, height.requestHeight(point.lat, point.lon)); + }, + }, + rendering: { requestVisibility() {} }, + }, + }); + t.after(() => height.clear()); + height.anchorFloors(); + assert.deepEqual(probed, [[42.3614, -71.0754]]); +}); + test('selection churn releases past geometry on every retained vehicle', async (t) => { const app = harness(t, { floorAt: () => 10 }); const { mergeHistory, seek } = await import('../../data/contactPlayback.js'); From 09520bc34ce262ad208295fc9843146f6dce3330 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 14:54:51 -0800 Subject: [PATCH 56/61] Changelog fragment for #1642 --- changelog.d/1642-transit-floor-per-point.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog.d/1642-transit-floor-per-point.md diff --git a/changelog.d/1642-transit-floor-per-point.md b/changelog.d/1642-transit-floor-per-point.md new file mode 100644 index 0000000000..04dd59760f --- /dev/null +++ b/changelog.d/1642-transit-floor-per-point.md @@ -0,0 +1,7 @@ +- Keep buses and trains off rooftops and out of bridge decks on the photoreal + 3D tiles: the ground floor probes the rendered mesh where each vehicle is, + keeps each reading at the point it was taken (up to sixteen a cell) and + answers from the reading nearest the vehicle, instead of one probe at each + 110 m cell's centre that lifted every vehicle in the cell onto whatever lay + there. Transit probes each vehicle's latest point, and grounded flights read + the floor at their own position (Sameh Khamis, @samehkhamis, #1642). From a7f96313e92105e96180d02bfdbf712d79816ff3 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 16:56:59 -0800 Subject: [PATCH 57/61] feat(pointer): an application's own tool can take the pointer createApplicationTools returns pointer: claim(owner) takes the pointer as Draw does and returns its lease, or null while another tool holds it; release(lease) gives it back; isFree() lets the application's own click handlers yield, as the layers' do. This replaces drawShape, which this branch added: Draw is as it was. --- CHANGELOG.md | 7 +- docs/CURRENT-STATE.md | 2 +- src/annotations/drawTool.js | 66 +-------- src/annotations/drawToolBehaviour.test.mjs | 152 --------------------- src/app/tools.js | 22 +-- 5 files changed, 18 insertions(+), 231 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c425d0b67..f49dad02be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,9 @@ ## [Unreleased] -- Applications can ask Draw for one area or line and get its geometry back - without placing a mark (`drawShape` from `createApplicationTools`), and their - own click handlers can yield while a tool holds the pointer, as the layers' - do (`pointerFree`) (samehkhamis, #1641). +- An application's own tool can take the pointer as Draw does, and its click + handlers can yield while a tool holds it, as the layers' do (`pointer` from + `createApplicationTools`) (samehkhamis, #1641). ## [0.3.0] — 2026-10-27 — Street Level, On Your Phone, in Your Language diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index b70dc1d923..f8914f19f5 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -6311,7 +6311,7 @@ request viewbox and continues searching without that geographic preference. - UTILITIES ▸ **Draw** turns the globe into a whiteboard drawn by hand. Pick a shape (icon buttons for Area, Line and Pin) and a colour swatch for the next shape, click the vertices on the real world, and finish. **Keyboard contract, live only while Draw is on and never while you are typing in another field:** Enter finishes the shape (as does a double-click, and the two cannot both submit it — the session is replaced before the annotate call is awaited); Backspace removes the last vertex; Esc cancels the shape in progress, and a second Esc — Esc on an empty session — leaves draw mode. **Clear** wipes the board (the shape in progress and every placed mark), so removing marks does not require the console or the microphone. - **Drawn shapes are listed under Draw like Import's files** (`src/ui/views/panels/DrawMarkList.vue`, rows worded by `presentDrawMarks` in `src/annotations/drawMarks.js`): one row per hand-drawn mark (`manual: true`; voice marks are not listed) with its colour swatch, its name, and show/hide, fly-to and remove. The draw tool publishes the rows with the rest of its controls and answers the row actions (`renameDrawMark`, `recolorDrawMark`, `toggleDrawMark`, `flyToDrawMark`, `removeDrawMark`) through the display store; it republishes on the engine's `onChange`, so a voice clear or an expiry updates the list. Rows are keyed and updated in place: a board change never takes a name being typed (the field keeps its draft while focused) or the button under a click. The name is saved on Enter or on leaving the field, once; Esc restores it, before anything else and with the row's colours open too. Both keep focus in the field, so neither drops it to the page or leaves Draw. The swatch opens the five colours right after it (shown at the end of the row), with the current colour focused; the arrows, Home and End try another, and a click or Esc closes them and returns focus to the swatch. Both colour groups (the next shape's and a row's) are one `DrawSwatches` radio group with a single tab stop, coloured from `DRAW_COLOR_CSS`; on touch screens each dot answers a 24 px target. An unnamed shape shows its kind, and an unnamed line its length; a renamed line keeps its length (`Ridge walk — 950 m`). **Hidden** keeps a mark on the board at alpha 0, and the world renderer takes every one of its entities out (`show = false`), so no material that keeps its own colour (the line's flowing stroke) still paints it; the screen renderer does not project a hidden callout, so it cannot push a visible label aside; `fly_route` skips a hidden route; and with every mark hidden the annotations render hold is released. **Fly to** is an immediate navigation (`runImmediateNavigation('drawing', …)`), like Import's: Cockpit refuses it and a running orbit, follow or track lets go first. A line is framed by its whole path, across the antimeridian too. - Runtime entry: `createApplicationTools` (`src/app/tools.js`, behind the `src/standalone/tools.js` shim) calls `initDrawTool({ viewer, annotations, navigation, publish, connect, markActions })` after `initAnnotations` and defers its `destroy()`, so disposing the shell returns every DOM listener, the Cesium handler, the preview data source, the borrowed click actions and the `window.__gevDrawTool` handle. Its controls are Vue views in the UTILITIES panel (`DrawControls.vue`, `DrawMarkList.vue`) that render what the tool publishes to the display store and call its actions. That handle (`setActive`, `setShape`, `addVertex(lon, lat)`, `finish`, `cancel`, `clearAll`, `marks`, `setColor`, `diagnostics`) is the no-mouse test seam. -- **One shape, handed back.** `createApplicationTools` also returns `drawShape({ shape, signal })` (`drawTool.drawShape`): it opens draw mode for one `area` or `line` and resolves with its geometry, a closed `[lon, lat]` `Polygon` or a `LineString`, without placing a mark; the shape chosen before comes back and draw mode ends. While it is open the controls cannot change the shape, and one across the antimeridian is refused as a row's actions refuse it ("That shape could not be placed.") and drawn again. It resolves `null` when the drawing is cancelled (the second Escape), draw mode is left, `signal` aborts, another request replaces it, the pointer is held elsewhere, the tool is destroyed, or the page has no Draw controls. It returns `pointerFree` (`data/inputOwnership.js` `isPointerFree`) too, so an application's own click handlers yield to the tool holding the pointer, as the layers' do. +- **The pointer, for an application's own tool.** `createApplicationTools` also returns `pointer` (`data/inputOwnership.js`): `claim(owner)` takes the pointer as Draw does and returns its lease, or `null` while another tool holds it; `release(lease)` gives it back; `isFree()` lets the application's own click handlers yield, as the layers' do. An owner without a name in `pointerOwnerNames.js` is named by its id when another tool reports who holds the pointer. - **Row actions are an application's own.** `createApplicationTools({ drawMarkActions })` hands `initDrawTool` buttons for drawn areas' and lines' rows; the standalone shell passes none, so the open-source build shows no new button and makes no new request. Each action (`drawMarkActions` in `src/annotations/drawMarks.js`) is `{ id, icon, label(name), shapes: ['area', 'line'], accepts?(geometry, shape), run({ id, shape, name, title, geometry }) }`: the icon a Material Symbols name, the label worded by the application, `name` the person's own and `title` the row's (the name, else `Area` or `Line · 950 m`), the geometry `drawMarkGeometry`'s `[lon, lat]` `Polygon` (closed; a `MultiPolygon` for an area handle with several parts) or `LineString`, longitudes wrapped into [-180, 180]. A pin, and a shape that crosses the antimeridian or has a part that cannot be given whole, has no geometry and is offered nothing. Malformed actions and repeated ids are dropped once, at construction. What `run` returns or resolves to is a note under the row (`role=status`; past 200 characters it is cut at a word with an ellipsis); the row is busy (`aria-disabled`, no second press) until it settles, a rejection or a throw clears the note and is logged (so an action words its own refusals and resolves with them), and a shape's note goes with the shape, so a late answer never lands on a removed one. - Contract: a finished shape is submitted through the SAME `annotationEngine.annotate()` the voice agent uses, with geometry supplied and `manual: true` (`type: area` + `ring`, `type: route` + `path`, `type: pin` + coordinates). `resolveSpec` short-circuits manual specs (`resolveManualSpec`) so no geocoder, Places or Overpass call is made. A drawn area is a real (not synthesized) outline and drapes solid; a drawn line is a `route` with `mode: 'manual'`, labelled with its length and never a travel time; a pin is a point. Drawn marks therefore render with the whiteboard look, persist, appear in `.list()`, and clear with `clear_annotations` / `.clear()`. A drawn shape is never merged with another as a duplicate: every one is drawn on purpose, and every one is unnamed until its row names it, so two pins dropped close together are two pins. - **A vertex is a lon/lat, and the mark is DRAPED.** Clicks are picked through `pickWorldFromScreen` — one of two scene helpers the annotation resolver factory (`src/annotations/resolver.js`) exposes alongside `sampleGroundHeight`, so the app has ONE depth-aware pick cascade rather than a second written beside it — which returns the height the pick landed on as well as the coordinate, so the live preview hangs on the roof or hillside under the pointer instead of sinking to sea level. The world renderer draws areas and routes with `clampToGround`, so the height is dropped at finish in one place (`finishSpec`) rather than being carried downstream and discarded silently: what you get is the outline you drew, lying on the surface beneath it. diff --git a/src/annotations/drawTool.js b/src/annotations/drawTool.js index 14a5929eb7..f44d30753d 100644 --- a/src/annotations/drawTool.js +++ b/src/annotations/drawTool.js @@ -54,7 +54,6 @@ import { DRAW_COLORS, DRAW_COLOR_CSS, drawMarkActions, - drawMarkGeometry, drawMarkActionsFor, drawMarkFallbackName, presentDrawMarks, @@ -121,9 +120,6 @@ export function initDrawTool({ let savedDoubleClick = null; let savedSingleClick = null; let cursor = null; // last mouse position on the canvas, for the rubber band - // One shape asked for by `drawShape`: `{ resolve, restoreShape, off }`. Its - // finish hands the geometry back instead of placing a mark. - let request = null; // Bumped by anything that supersedes an in-flight finish: cancelling, clearing // the board, leaving draw mode, teardown. An `annotate()` that resolves after // one of those must not write its outcome over the newer state. @@ -284,20 +280,6 @@ export function initDrawTool({ // Named afterwards, in the shape's row. const spec = finishSpec(session, { label: '', color }); if (!spec) return null; - if (request) { - // As a row's actions get it: a shape across the antimeridian has none, - // and is drawn again rather than handed back wrapped round the world. - const geometry = drawMarkGeometry(spec); - if (!geometry) { - session = createDrawSession(shape); - cursor = null; - syncPreview(); - setHint(() => t('That shape could not be placed.')); - return null; - } - endRequest(geometry); - return geometry; - } // Start a fresh session BEFORE awaiting, so a second Enter or the second // half of a double-click cannot submit the same shape twice. session = createDrawSession(shape); @@ -425,7 +407,6 @@ export function initDrawTool({ generation += 1; session = null; cursor = null; - endRequest(null); releaseSceneHandler(); releasePointer(lease); lease = null; @@ -551,46 +532,6 @@ export function initDrawTool({ return true; } - /** - * Close the asked-for shape with `geometry` (null when there is none): the - * shape chosen before it comes back, and draw mode ends. - */ - function endRequest(geometry) { - const open = request; - if (!open) return; - request = null; - open.off(); - chooseShape(open.restoreShape); - open.resolve(geometry); - if (active) setActive(false); - } - - /** - * Draw one area or line and hand back its geometry (a Polygon or a - * LineString) without placing a mark. Escape works as in Draw: the first - * clears a shape in progress, and one on an empty shape leaves. Resolves null - * when draw mode is left, `signal` aborts, or the pointer is taken. - * A second request ends the first with null. - * @param {{shape?: 'area'|'line', signal?: AbortSignal}} [options] - * @returns {Promise<{type: 'Polygon', coordinates: number[][][]}|{type: 'LineString', coordinates: number[][]}|null>} - */ - function drawShape({ shape: wanted = 'area', signal } = {}) { - if (destroyed || signal?.aborted) return Promise.resolve(null); - endRequest(null); - const restoreShape = shape; - return new Promise((resolve) => { - const abort = () => endRequest(null); - signal?.addEventListener('abort', abort, { once: true }); - request = { - resolve, - restoreShape, - off: () => signal?.removeEventListener('abort', abort), - }; - chooseShape(normalizeShape(wanted) === 'line' ? 'line' : 'area'); - if (!active && !setActive(true)) endRequest(null); - }); - } - /** Draw `next` from now on; an open shape starts over in it. */ function chooseShape(next) { shape = normalizeShape(next); @@ -604,10 +545,7 @@ export function initDrawTool({ } const disconnect = connect({ toggleDraw: () => setActive(!active), - // An asked-for shape is the one asked for. - setDrawShape: (next) => { - if (!request) chooseShape(next); - }, + setDrawShape: chooseShape, setDrawColor: (value) => { color = DRAW_COLORS.includes(value) ? value : 'primary'; present(); @@ -664,7 +602,6 @@ export function initDrawTool({ finish, cancel, clearAll, - drawShape, shapes: DRAW_SHAPES, /** What this tool currently holds — for teardown and leak assertions. */ diagnostics() { @@ -701,7 +638,6 @@ export function initDrawTool({ if (destroyed) return attaching; // Supersede any finish still in flight before anything is torn down. generation += 1; - endRequest(null); if (active) setActive(false); destroyed = true; offLocale(); diff --git a/src/annotations/drawToolBehaviour.test.mjs b/src/annotations/drawToolBehaviour.test.mjs index 2768522484..4cef4d4fe0 100644 --- a/src/annotations/drawToolBehaviour.test.mjs +++ b/src/annotations/drawToolBehaviour.test.mjs @@ -704,158 +704,6 @@ test('what a row action answers is its row\'s note; the row is busy until then, } }); -test('drawShape hands back the drawn area as a polygon and places no mark', async () => { - const h = harness(); - try { - h.act('setDrawShape', 'line'); - const drawn = h.tool.drawShape({ shape: 'area' }); - assert.equal(h.tool.active, true, 'it opens draw mode'); - assert.equal(h.tool.shape, 'area'); - h.tool.addVertex(-97.75, 30.26); - h.tool.addVertex(-97.74, 30.26); - h.tool.addVertex(-97.74, 30.27); - h.documentDouble.emit('keydown', { - key: 'Enter', - target: h.documentDouble.body, - }); - const geometry = await drawn; - assert.deepEqual(geometry, { - type: 'Polygon', - coordinates: [ - [ - [-97.75, 30.26], - [-97.74, 30.26], - [-97.74, 30.27], - [-97.75, 30.26], - ], - ], - }); - assert.equal(h.annotations.calls.annotate.length, 0, 'no mark is placed'); - assert.equal(h.tool.active, false, 'draw mode ends'); - assert.equal(isPointerFree(), true); - assert.equal(h.tool.shape, 'line', 'the shape chosen before comes back'); - } finally { - h.restore(); - } -}); - -test('drawShape hands back a line as a LineString', async () => { - const h = harness(); - try { - const drawn = h.tool.drawShape({ shape: 'line' }); - h.tool.addVertex(-97.75, 30.26); - h.tool.addVertex(-97.74, 30.26); - h.documentDouble.emit('keydown', { - key: 'Enter', - target: h.documentDouble.body, - }); - assert.deepEqual(await drawn, { - type: 'LineString', - coordinates: [ - [-97.75, 30.26], - [-97.74, 30.26], - ], - }); - } finally { - h.restore(); - } -}); - -test('drawShape resolves null on Escape, on abort, on a newer request and when the pointer is taken', async () => { - const h = harness(); - try { - // Escape with a shape started clears it; a second Escape leaves. - const escaped = h.tool.drawShape({ shape: 'area' }); - h.tool.addVertex(-97.75, 30.26); - h.documentDouble.emit('keydown', { - key: 'Escape', - target: h.documentDouble.body, - }); - assert.equal(h.tool.active, true, 'the first Escape only clears the shape'); - h.documentDouble.emit('keydown', { - key: 'Escape', - target: h.documentDouble.body, - }); - assert.equal(await escaped, null); - assert.equal(h.tool.active, false); - - const controller = new AbortController(); - const aborted = h.tool.drawShape({ - shape: 'area', - signal: controller.signal, - }); - controller.abort(); - assert.equal(await aborted, null); - assert.equal(isPointerFree(), true, 'an abort gives the pointer back'); - - const first = h.tool.drawShape({ shape: 'area' }); - const second = h.tool.drawShape({ shape: 'line' }); - assert.equal(await first, null, 'a newer request ends the older one'); - h.act('toggleDraw'); - assert.equal(await second, null, 'leaving draw mode ends it'); - - const done = new AbortController(); - done.abort(); - assert.equal(await h.tool.drawShape({ signal: done.signal }), null); - - const other = claimPointer('directions'); - assert.equal( - await h.tool.drawShape({ shape: 'area' }), - null, - 'a held pointer refuses it', - ); - releasePointer(other); - - // Drawing by hand afterwards places marks as before. - h.act('toggleDraw'); - h.tool.addVertex(-97.75, 30.26); - h.tool.addVertex(-97.74, 30.26); - h.tool.addVertex(-97.74, 30.27); - h.documentDouble.emit('keydown', { - key: 'Enter', - target: h.documentDouble.body, - }); - await Promise.resolve(); - assert.equal(h.annotations.calls.annotate.length, 1); - } finally { - h.restore(); - } -}); - -test('drawShape keeps its shape, and a shape across the antimeridian is drawn again', async () => { - const h = harness(); - try { - const drawn = h.tool.drawShape({ shape: 'line' }); - h.act('setDrawShape', 'pin'); - assert.equal(h.tool.shape, 'line', 'the controls cannot change the asked-for shape'); - h.tool.addVertex(179.5, 10); - h.tool.addVertex(-179.5, 10); - h.documentDouble.emit('keydown', { key: 'Enter', target: h.documentDouble.body }); - assert.equal(h.tool.active, true, 'still drawing'); - assert.equal(h.tool.session.vertices.length, 0, 'drawn again from the start'); - assert.equal(h.shown.view.hint, 'That shape could not be placed.'); - h.tool.addVertex(29, 41); - h.tool.addVertex(29.1, 41); - h.documentDouble.emit('keydown', { key: 'Enter', target: h.documentDouble.body }); - assert.equal((await drawn).type, 'LineString'); - h.act('setDrawShape', 'pin'); - assert.equal(h.tool.shape, 'pin', 'after it, the controls choose again'); - } finally { - h.restore(); - } -}); - -test('destroy ends a drawShape request with null', async () => { - const h = harness(); - try { - const drawn = h.tool.drawShape({ shape: 'area' }); - h.tool.destroy(); - assert.equal(await drawn, null); - } finally { - h.restore(); - } -}); - test('Backspace on the page removes the last vertex', () => { const h = harness(); try { diff --git a/src/app/tools.js b/src/app/tools.js index 9ecb3559a8..9da848c784 100644 --- a/src/app/tools.js +++ b/src/app/tools.js @@ -1,7 +1,11 @@ import { SceneDirector } from '../scenes/director.js'; import { initAnnotations } from '../annotations/index.js'; import { initDrawTool } from '../annotations/drawTool.js'; -import { isPointerFree } from '../data/inputOwnership.js'; +import { + claimPointer, + isPointerFree, + releasePointer, +} from '../data/inputOwnership.js'; import { initGeoFileImport } from '../ui/geoFileImport.js'; import { useDisplayStore } from '../ui/stores/display.js'; import { applicationPinia } from '../ui/vueRuntime.js'; @@ -246,17 +250,17 @@ export function createApplicationTools({ signal, }), ); - // Draw one area or line and get its geometry back, without placing a mark - // (annotations/drawTool.js `drawShape`); null without the Draw controls. - const drawShape = (options) => - drawTool ? drawTool.drawShape(options) : Promise.resolve(null); - // An application's own click handlers yield while a tool holds the pointer, - // as the layers' do (data/inputOwnership.js). + // An application's own tool takes the pointer as Draw does, and its own + // click handlers yield while a tool holds it, as the layers' do + // (data/inputOwnership.js). return { sceneDirector, annotations, voiceCommands, - drawShape, - pointerFree: isPointerFree, + pointer: { + claim: claimPointer, + release: releasePointer, + isFree: isPointerFree, + }, }; } From 4dc51927bc55e88a9a09bd442c8c18fac3d072af Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 18:04:16 -0800 Subject: [PATCH 58/61] perf(traffic): build road lines one set at a time With Lines on, every progressive paint of a loading city rebuilt all road lines: up to three ground-line primitives for as many as 1,500 roads, built asynchronously. Builds started faster than they finished, and each kept the set it replaced in the scene until it was ready, so sets piled up. One set now builds at a time. A rebuild asked for while lines are building replaces the one waiting, and the newest starts when the build finishes. Lines replaced by a finished build are removed before the next one starts. Turning Lines off removes the lines at once and drops the waiting rebuild. --- docs/CURRENT-STATE.md | 2 +- scripts/format-scope.json | 1 + src/layers/traffic/lineRebuild.test.mjs | 219 ++++++++++++++++++++++++ src/layers/traffic/rendering.js | 52 ++++-- src/layers/traffic/state.js | 4 + 5 files changed, 264 insertions(+), 14 deletions(-) create mode 100644 src/layers/traffic/lineRebuild.test.mjs diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 91b7a56a41..03d4efc94d 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -134,7 +134,7 @@ existing batch size and one bounded upstream chunk. Larger requests return HTTP 413 before disk-cache loading or upstream work; malformed coordinates remain 400. The browser continues to split larger workloads into sequential 64-point requests. -Traffic holds continuous rendering only while enabled with shown animated dots, a pulsing jam heat-line, or road lines whose geometry is still building (replaced lines stay drawn until their successors are ready, so a rebuild never blinks); hidden dots (`dots` off) and settled flow lines hold nothing. Empty and high-altitude views release the hold. A failed load leaves no hold only when no animated content is retained: if an earlier load succeeded, ingestion keeps its animated points and the hold stays. Population admission reacquires the hold and resets animation time. Clear, disable, and destroy also release it. Retained fading dots keep animation alive until they are removed. When the last point leaves mid height correction, the correction is settled at once, before the hold is released, so it cannot keep the layer reporting loading. +Traffic holds continuous rendering only while enabled with shown animated dots, a pulsing jam heat-line, or road lines whose geometry is still building (replaced lines stay drawn until their successors are ready, so a rebuild never blinks; one set builds at a time, and of the rebuilds asked for meanwhile only the newest runs, when that build finishes; turning lines off removes them at once); hidden dots (`dots` off) and settled flow lines hold nothing. Empty and high-altitude views release the hold. A failed load leaves no hold only when no animated content is retained: if an earlier load succeeded, ingestion keeps its animated points and the hold stays. Population admission reacquires the hold and resets animation time. Clear, disable, and destroy also release it. Retained fading dots keep animation alive until they are removed. When the last point leaves mid height correction, the correction is settled at once, before the hold is released, so it cannot keep the layer reporting loading. Shared distance checks use `src/geoDistance.js` with `{ lat, lon }` points and the IUGG mean spherical Earth radius, 6371.0088 km. `greatCircleKm` is diff --git a/scripts/format-scope.json b/scripts/format-scope.json index 7dbd9d2b74..c82c5ebb34 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -1077,6 +1077,7 @@ "src/layers/traffic/roadModes.test.mjs", "scripts/qa-traffic-motion.mjs", "src/layers/traffic/motion.test.mjs", + "src/layers/traffic/lineRebuild.test.mjs", "scripts/qa-journey-recorder.mjs", "scripts/qa-alpr-journey.mjs", "scripts/qa-context-arrivals.mjs", diff --git a/src/layers/traffic/lineRebuild.test.mjs b/src/layers/traffic/lineRebuild.test.mjs new file mode 100644 index 0000000000..b4533b63d0 --- /dev/null +++ b/src/layers/traffic/lineRebuild.test.mjs @@ -0,0 +1,219 @@ +// Street Traffic road lines build one set at a time: rebuilds asked for while +// a set is building wait, and only the newest of them runs. +import test from 'node:test'; +import assert from 'node:assert/strict'; +import * as Cesium from 'cesium'; +import { createRendering } from './rendering.js'; + +// Cesium tests a material's uniforms against these browser classes. +for (const name of [ + 'HTMLCanvasElement', + 'HTMLImageElement', + 'ImageBitmap', + 'OffscreenCanvas', +]) + globalThis[name] ??= class {}; +// A line primitive's render state is checked against the context's limits, +// which only a WebGL context sets. +Cesium.ContextLimits._minimumAliasedLineWidth = 1; +Cesium.ContextLimits._maximumAliasedLineWidth = 1; + +/** A road with flow; `level` picks its bucket (0.1 jam, 0.6 slow, 1 free). */ +function road(level = 1) { + return { + flow: { level, closure: false }, + segmentDist: [100], + waypoints: Cesium.Cartesian3.fromDegreesArray([ + -97.744, 30.267, -97.742, 30.267, + ]), + }; +} + +/** + * Rendering over a scene that records its ground primitives. Each added + * primitive is replaced by a stand-in whose `ready` the test sets, as Cesium + * sets it once the asynchronous geometry is built. + */ +function harness() { + const scene = []; + const added = []; + let linesOn = true; + const state = { + _viewer: { + scene: { + globe: { show: true }, + groundPrimitives: { + add(primitive) { + const line = { + ready: false, + roads: primitive.geometryInstances.length, + }; + scene.push(line); + added.push(line); + return line; + }, + remove(line) { + const index = scene.indexOf(line); + if (index >= 0) scene.splice(index, 1); + }, + }, + }, + }, + _liveMode: true, + _showLines: true, + _heatSupported: true, + _heatJamPrim: null, + _heatSlowPrim: null, + _heatFreePrim: null, + _heatRetired: [], + _heatPendingRoads: null, + _heatLineCount: 0, + }; + const rendering = createRendering({ + state, + services: {}, + source: {}, + parts: { + style: { heatlineOn: () => linesOn }, + animation: { syncRenderDemand() {} }, + }, + }); + return { + state, + rendering, + scene, + added, + setLines(on) { + linesOn = on; + state._showLines = on; + }, + /** Finish every build in the scene, then run a frame. */ + frame({ built = true } = {}) { + if (built) for (const line of scene) line.ready = true; + rendering.retireHeatLines(); + }, + }; +} + +const roads = (count) => Array.from({ length: count }, () => road()); + +test('rebuilds asked for while lines build do not start more builds', () => { + const { rendering, scene, added, frame } = harness(); + rendering.rebuildHeatLines(roads(1)); + assert.equal(added.length, 1); + // Progressive paints while the first set builds. + for (const count of [2, 3, 4]) rendering.rebuildHeatLines(roads(count)); + frame({ built: false }); + assert.equal(added.length, 1, 'no build started during a build'); + assert.equal(scene.length, 1); + assert.deepEqual(scene[0].roads, 1); +}); + +test('the newest rebuild asked for during a build is the one that runs', () => { + const { state, rendering, scene, added, frame } = harness(); + rendering.rebuildHeatLines(roads(1)); + for (const count of [2, 3, 4]) rendering.rebuildHeatLines(roads(count)); + frame(); + // One build for the three requests, of the last one's roads. + assert.deepEqual( + added.map((line) => line.roads), + [1, 4], + ); + assert.equal(state._heatLineCount, 4); + assert.equal(state._heatPendingRoads, null); + // The set it replaces stays drawn while it builds, then goes. + assert.deepEqual( + scene.map((line) => line.roads), + [1, 4], + ); + frame(); + assert.deepEqual( + scene.map((line) => line.roads), + [4], + ); + // Nothing is waiting, so later frames start nothing. + frame(); + assert.equal(added.length, 2); +}); + +test('a rebuild with nothing building starts at once', () => { + const { rendering, added, frame } = harness(); + rendering.rebuildHeatLines(roads(1)); + frame(); + rendering.rebuildHeatLines(roads(2)); + assert.deepEqual( + added.map((line) => line.roads), + [1, 2], + ); +}); + +test('turning lines off during a build removes them at once and drops the waiting rebuild', () => { + const { state, rendering, scene, added, setLines, frame } = harness(); + rendering.rebuildHeatLines(roads(1)); + frame(); + rendering.rebuildHeatLines(roads(2)); + rendering.rebuildHeatLines(roads(3)); + assert.equal(scene.length, 2, 'the drawn set and the building one'); + setLines(false); + rendering.rebuildHeatLines(roads(3)); + assert.deepEqual(scene, [], 'not deferred behind the build'); + assert.equal(state._heatPendingRoads, null); + assert.equal(state._heatLineCount, 0); + frame(); + assert.equal(added.length, 2, 'the waiting rebuild never runs'); + assert.deepEqual(scene, []); +}); + +test('a rebuild right after a build finishes does not keep the lines that build replaced', () => { + const { rendering, scene } = harness(); + rendering.rebuildHeatLines(roads(1)); + for (const line of scene) line.ready = true; + rendering.rebuildHeatLines(roads(2)); + // The second build finishes, and a third is asked for before a frame ran. + for (const line of scene) line.ready = true; + rendering.rebuildHeatLines(roads(3)); + assert.deepEqual( + scene.map((line) => line.roads), + [2, 3], + ); +}); + +test('removing the lines drops the waiting rebuild', () => { + const { state, rendering, scene, added, frame } = harness(); + rendering.rebuildHeatLines(roads(1)); + rendering.rebuildHeatLines(roads(2)); + rendering.removeHeatLines(); + assert.deepEqual(scene, []); + assert.equal(state._heatPendingRoads, null); + frame(); + assert.equal(added.length, 1); +}); + +test('a stream of rebuilds never leaves more than two sets in the scene, and ends with one', () => { + const { rendering, scene, added, frame } = harness(); + let most = 0; + const lines = [road(0.1), road(0.6), road(1)]; + // Three primitives per set: one per flow bucket. + for (let paint = 0; paint < 40; paint += 1) { + rendering.rebuildHeatLines(lines); + most = Math.max(most, scene.length); + // A build takes several paints. + if (paint % 5 === 4) frame(); + else frame({ built: false }); + most = Math.max(most, scene.length); + } + frame(); + frame(); + assert.equal(most <= 6, true, `${most} primitives at once`); + assert.equal(scene.length, 3, 'only the current set remains'); + assert.equal( + scene.every((line) => line.ready), + true, + ); + // Without coalescing every paint builds: 40 sets, 120 primitives. + assert.equal( + added.length <= 3 * 10, + true, + `${added.length} primitives built`, + ); +}); diff --git a/src/layers/traffic/rendering.js b/src/layers/traffic/rendering.js index 402cd08b65..49f5af8e99 100644 --- a/src/layers/traffic/rendering.js +++ b/src/layers/traffic/rendering.js @@ -59,24 +59,37 @@ export function createRendering({ /** Remove the heat-line / flow-line ground primitives from the scene. */ function removeHeatLines() { + layerState._heatPendingRoads = null; removePrimitives(takeHeatLines()); removePrimitives(layerState._heatRetired || []); layerState._heatRetired = []; parts.animation.syncRenderDemand?.(); } + /** @returns {boolean} Whether a line primitive's geometry is still building. */ + + function linesBuilding() { + return LINE_KEYS.some((key) => layerState[key] && !layerState[key].ready); + } + /** * Replaced lines stay drawn until their successors finish building * (GroundPolylinePrimitive geometry is asynchronous), so a rebuild never - * blinks. Called every held frame. + * blinks. Once they have, the replaced lines go and the newest rebuild + * asked for in the meantime starts. Called every held frame. */ function retireHeatLines() { - if (!layerState._heatRetired?.length) return; - if (LINE_KEYS.some((key) => layerState[key] && !layerState[key].ready)) - return; - removePrimitives(layerState._heatRetired); - layerState._heatRetired = []; + if (linesBuilding()) return; + if (layerState._heatRetired?.length) { + removePrimitives(layerState._heatRetired); + layerState._heatRetired = []; + } + const pending = layerState._heatPendingRoads; + if (pending) { + layerState._heatPendingRoads = null; + rebuildHeatLines(pending); + } } /** @@ -95,24 +108,37 @@ export function createRendering({ * the globe is hidden (photoreal) and on terrain or tiles otherwise. No-op in * sim mode, when both looks are off, or without ground-primitive support. * + * One build runs at a time. A city loads in progressive paints, each asking + * for a rebuild, and every build drapes up to the cap of polylines + * asynchronously. A rebuild asked for while lines are building only replaces + * the one waiting, which retireHeatLines starts when the build finishes, so + * the scene never holds more than the lines drawn and the lines building. + * Turning the lines off is never deferred. + * * @param {Array} roads - Road objects visible in the current render. */ function rebuildHeatLines(roads) { + const wanted = + layerState._viewer && layerState._liveMode && parts.style.heatlineOn(); + if (wanted && linesBuilding()) { + layerState._heatPendingRoads = roads; + return; + } + layerState._heatPendingRoads = null; + // No build is left for replaced lines to wait for (it finished, or lines + // are going off), so they go first and never pile up behind this rebuild. + removePrimitives(layerState._heatRetired || []); + layerState._heatRetired = []; const previous = takeHeatLines(); const finish = () => { - // Nothing new to wait for: the old lines go now. if (LINE_KEYS.some((key) => layerState[key])) (layerState._heatRetired ||= []).push(...previous); + // Nothing new to wait for: the old lines go now. else removePrimitives(previous); parts.animation.syncRenderDemand?.(); }; - if ( - !layerState._viewer || - !layerState._liveMode || - !parts.style.heatlineOn() - ) - return finish(); + if (!wanted) return finish(); if (layerState._heatSupported === null) { layerState._heatSupported = Cesium.GroundPolylinePrimitive.isSupported( layerState._viewer.scene, diff --git a/src/layers/traffic/state.js b/src/layers/traffic/state.js index 8c2fd9f941..e82cd6191a 100644 --- a/src/layers/traffic/state.js +++ b/src/layers/traffic/state.js @@ -200,6 +200,10 @@ export function createState({ services, source }) { layerState._heatRetired = []; + /** @type {Array|null} Roads of the newest rebuild asked for while the lines were building. */ + + layerState._heatPendingRoads = null; + /** @type {number} Heat-lines in the current render (stats). */ layerState._heatLineCount = 0; From b996e35b0ce86dd62f16d7547a2e0c57c2f5fa64 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 20:31:53 -0800 Subject: [PATCH 59/61] docs(changelog): traffic lines build one set at a time --- changelog.d/1645-traffic-lines-one-build.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog.d/1645-traffic-lines-one-build.md diff --git a/changelog.d/1645-traffic-lines-one-build.md b/changelog.d/1645-traffic-lines-one-build.md new file mode 100644 index 0000000000..da1d00be26 --- /dev/null +++ b/changelog.d/1645-traffic-lines-one-build.md @@ -0,0 +1,3 @@ +- Street Traffic Lines build one set at a time while a city loads, instead of + one per paint, so panning with Lines on no longer piles up line builds + (Sameh Khamis, @samehkhamis, #1645). From 1a8defbfc880a53597410f61679a156cbbfe8b9e Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 20:36:03 -0800 Subject: [PATCH 60/61] feat(flights): show the tracked aircraft's Planespotters photo in Contacts Tracking a civil flight asks Planespotters for that aircraft's photo, once per aircraft, straight from the browser. The CONTEXT panel's CONTACTS view shows it under the flight's name with the photographer's credit, as a plain link to the photo's page. Only images on plnspttrs.net and pages on www.planespotters.net are ever shown or linked. Military aircraft and a converted TR-3B are never looked up. Flight lookups (type, route, photo) whose source failed temporarily are asked again after a 60-second cool-down; an answer, found or not, and a permanent refusal stay final for the session. A route belongs to the callsign it was looked up for, so a callsign change drops the old route. Browser QA scripts that track a flight answer the photo lookup themselves, so they never call the third party. --- DATA_SOURCES.md | 6 +- docs/CODE-BOUNDARIES.md | 3 + docs/CURRENT-STATE.md | 11 + package.json | 1 + scripts/package-boundaries.json | 20 +- scripts/qa-cockpit-utility.mjs | 3 + scripts/qa-context-arrivals.mjs | 2 + scripts/qa-emergency-squawk.mjs | 2 + scripts/qa-focus-evidence.mjs | 2 + scripts/qa-heading-b3.mjs | 2 + scripts/qa-photo-stub.mjs | 78 ++++++ scripts/qa-sprites-b5.mjs | 2 + scripts/track-regression.mjs | 3 + src/data/dataCredits.js | 7 + src/data/dataCredits.test.mjs | 7 + src/data/flights.js | 2 + src/data/flights.test.mjs | 260 +++++++++++++++++- src/data/militaryAwareness.test.mjs | 88 +++++- src/data/planespottersPhoto.js | 121 +++++++++ src/data/planespottersPhoto.test.mjs | 200 ++++++++++++++ src/i18n/locales/ar.json | 3 +- src/i18n/locales/de.json | 3 +- src/i18n/locales/es.json | 3 +- src/i18n/locales/fr.json | 3 +- src/i18n/locales/it.json | 3 +- src/i18n/locales/ja.json | 3 +- src/i18n/locales/pt.json | 3 +- src/i18n/locales/ru.json | 3 +- src/i18n/locales/uk.json | 3 +- src/i18n/locales/zh-CN.json | 3 +- src/i18n/locales/zh-Hant.json | 3 +- src/i18n/same-as-english.json | 3 +- src/layers/awareness/panel.js | 23 ++ src/layers/awareness/panel.test.mjs | 117 ++++++++ src/layers/awareness/state.js | 2 + src/layers/awareness/subject.js | 60 ++++- src/layers/flights/enrichment.js | 118 ++++++++- src/layers/flights/lifecycle.js | 1 + src/layers/flights/ownership.test.mjs | 354 ++++++++++++++++++++++++- src/layers/flights/policy.js | 5 + src/layers/flights/queries.js | 16 +- src/layers/flights/records.js | 15 +- src/layers/flights/records.test.mjs | 24 ++ src/layers/flights/snapshotRenderer.js | 7 + src/layers/flights/state.js | 4 + src/layers/flights/testing.js | 15 +- src/layers/flights/tracking.js | 1 + src/sources/live/contract.test.mjs | 74 ++++++ src/sources/live/standalone.js | 29 ++ src/ui/awarenessPanel.test.mjs | 70 +++++ src/ui/styles/radio.css | 25 ++ src/ui/views/panels/AwarenessPanel.vue | 11 + 52 files changed, 1781 insertions(+), 46 deletions(-) create mode 100644 scripts/qa-photo-stub.mjs create mode 100644 src/data/planespottersPhoto.js create mode 100644 src/data/planespottersPhoto.test.mjs diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index ba231df31d..03a37ee5af 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -30,6 +30,7 @@ How to read this: | **adsb.lol point API** | Bounded live-flight fallback when OpenSky has no usable snapshot; GNSS Integrity layer (aircraft-reported NIC/NACp and GPS-loss integrity facts, via `/api/gnss-integrity`, 60 s server cache) | ODbL 1.0 | adsb.lol contributors; `api.adsb.lol/v2/lat/{lat}/lon/{lon}/dist/{radius}` | | **adsb.lol** | Military flights + aircraft traces | ODbL 1.0 | "adsb.lol" (ODbL) | | **adsbdb** (`api.adsbdb.com`) | Aircraft type, model name and registration by ICAO hex for enriched flights; airline and origin/destination airports for the tracked flight's callsign | No licence or rate limit is published for the service. Its own credits: aircraft data from PlaneBase, ICAO-to-N-number conversion by Guillaume Michel, and flight route data that "is the work of David Taylor, Edinburgh and Jim Mason, Glasgow, and may not be copied, published, or incorporated into other databases without the explicit permission of David J Taylor, Edinburgh" | "adsbdb — api.adsbdb.com" (courtesy); route data credited to David Taylor, Edinburgh, and Jim Mason, Glasgow | +| **Planespotters.net** (`api.planespotters.net/pub/photos/hex/{hex}`) | One thumbnail photo of the tracked aircraft, by ICAO hex, in the CONTEXT panel's CONTACTS view under the tracked flight's name | [Planespotters photo API terms](https://www.planespotters.net/photo/api); each photo remains the copyright of its photographer. Thumbnails may be hotlinked on the condition that the photographer is named next to the photo and the photo links to its Planespotters page with a followable link | "Photo © {photographer}" beside every photo, linked to its Planespotters page; "Planespotters.net" in Data attribution | | **AISStream.io** | Live vessels (AIS) | Free, beta, no formal ToS; AIS is a public broadcast | "AISStream.io" (courtesy) | | **CelesTrak** | Satellite TLEs (SGP4) and SATCAT records (object type, operational status, owner) that file each satellite under a class | US-government-origin data, no license; citation requested | "CelesTrak (celestrak.org), Dr. T.S. Kelso" | | **The Space Devs — Launch Library 2 v2.3** | Recent launch, payload, stage, and recovery metadata for Space Missions (30d) | [The Space Devs terms of use](https://github.com/TheSpaceDevs/Tutorials/blob/main/faqs/faq_TSD.md#terms-of-use): data may be used and shared in any form; avoid forwarding it without added value; attribution is encouraged (not mandatory). [Official API limits](https://ll.thespacedevs.com/docs/): 15 unauthenticated calls/hour; optional token | "Launch Library 2 — The Space Devs" (courtesy attribution) | @@ -200,7 +201,8 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei contributors, ODbL 1.0; GPSJAM for aggregation only. -- **adsbdb enrichment.** `/api/adsbdb` resolves an ICAO hex to aircraft type, model name and registration, and the tracked flight's callsign to an airline and an origin/destination pair. Fan-out is deliberately small because adsbdb is a free community API that publishes no quota: at most 4 requests in flight, dispatches dripped to roughly 5/s, and each key asked for at most once per session, with route lookups reserved for the tracked aircraft. The dev-server proxy caches each key for 24 hours in `.gev-cache/adsbdb.json`, negative answers included, so fresh entries survive server restarts. That gitignored cache remains local to the deployment and is not bundled with this repo. adsbdb publishes no general service license; its README says the route data may not be copied, published, or incorporated into other databases without the explicit permission of David J Taylor, Edinburgh. Deployers are responsible for obtaining any permission their use requires. Enrichment is best-effort and fail-silent — a flight that gets no answer keeps what the flight feed already gave it. +- **adsbdb enrichment.** `/api/adsbdb` resolves an ICAO hex to aircraft type, model name and registration, and the tracked flight's callsign to an airline and an origin/destination pair. Fan-out is deliberately small because adsbdb is a free community API that publishes no quota: at most 4 requests in flight, dispatches dripped to roughly 5/s, and each key asked for at most once per session (for the flights layer's enrichment, a lookup that failed temporarily, such as an outage, a timeout, a rate limit or an authorization refusal that may clear, may be asked again after a 60-second cool-down; an answer, found or not, and a permanent refusal such as a 404 are final; Local ADS-B lookups are asked once), with route lookups reserved for the tracked aircraft. The dev-server proxy caches each key for 24 hours in `.gev-cache/adsbdb.json`, negative answers included, so fresh entries survive server restarts. That gitignored cache remains local to the deployment and is not bundled with this repo. adsbdb publishes no general service license; its README says the route data may not be copied, published, or incorporated into other databases without the explicit permission of David J Taylor, Edinburgh. Deployers are responsible for obtaining any permission their use requires. Enrichment is best-effort and fail-silent — a flight that gets no answer keeps what the flight feed already gave it. +- **Planespotters photos.** When you track an aircraft, the browser asks `https://api.planespotters.net/pub/photos/hex/{hex}` directly (the API answers cross-origin, so no key and no server proxy are involved) for that aircraft only, once per hex per session, through the same enrichment queue as adsbdb, with an 8-second timeout. A miss is remembered for the session; a request that failed temporarily (an outage, the timeout or a rate limit) may be asked again after a 60-second cool-down while the aircraft stays tracked, as for the flights layer's other enrichment. Either way no photo shows meanwhile. The first photo whose image is an `https://` URL on `*.plnspttrs.net`, whose page is an `https://www.planespotters.net` URL, and which names its photographer is shown in the CONTEXT panel's CONTACTS view, under the tracked flight's name (`src/ui/views/panels/AwarenessPanel.vue`), and nowhere else; a vessel, an installation, a military aircraft or a converted TR-3B has none, and a military aircraft or TR-3B is never looked up. Anything else is dropped, so the app never shows or links outside Planespotters (`src/data/planespottersPhoto.js`, also exported as `gods-eye-view/sources/planespotters` for servers that cache the lookup). The photo follows the attribution rules: the thumbnail is hotlinked from the URL the API gives (never copied or re-hosted), the photographer's name is visible text next to it ("Photo © {photographer}"), and the photo and credit are a plain link to the photo's Planespotters page with `target="_blank" rel="noopener"` and never `rel="nofollow"`. If the image fails to load, the photo and its credit are hidden. - **Launch Library 2.** `/api/launches` makes a server-side rolling-30-day query against the supported v2.3 detailed launch endpoint, caches successful responses for 15 minutes in memory and on disk, and serves the last successful response during a throttle or transient outage. Anonymous access is limited to 15 calls/hour; deployments can provide `LL2_API_TOKEN` for authenticated access. The Space Devs' published terms permit using and sharing the API data in any form, ask users not to forward it without adding value, disclaim complete accuracy, and encourage—but do not require—attribution. This app keeps a courtesy credit. Payload and stage/recovery records are shown only when supplied. Failed launches expose their source status and never receive fallback orbit geometry or a live/estimated marker. LL2 supplies launch context and event timing, not continuous ascent telemetry or live orbital state. - **TfL JamCams.** The camera list comes from the keyless `api.tfl.gov.uk` endpoint (an optional `TFL_APP_KEY` raises its rate limit); frames come from TfL's public S3 bucket. The "Powered by TfL Open Data" attribution is required by TfL's terms and is registered in the Data attribution popover. - **Ontario 511 CCTV.** The camera list comes from the `511on.ca/api/v2/get/cameras` endpoint, which now requires a free developer key (`ONTARIO_511_API_KEY`: sign up at 511on.ca/my511/register, then request it while logged in at 511on.ca/developers/doc; throttled to 10 calls a minute). Without the key the pack is skipped. Frames are server-registered still images under `511on.ca/map/Cctv/`. The source is live-fetched at runtime and attributed under the Open Government Licence - Ontario. Access is governed by Ontario 511's Developer's Access Agreement (511on.ca/developers/resources): the data stays under the Open Government Licence - Ontario unless otherwise specified; key requests are reviewed case by case and ask for the intended use and any third parties that will receive the data; attribution by link to 511on.ca is encouraged, and the Ontario 511 logo may not be altered or used to imply endorsement (this app links and shows no logo); and the data is provided "as is", a disclaimer distributors should pass on, which the credit does. @@ -538,4 +540,4 @@ NOAA density imagery with the raw GLM product. ## In-app attribution -The required Google Maps / Cesium credit renders on the on-globe credit line (`#cesium-credits`, bottom-left) and must stay visible — including in clean-view and recording modes (the whole line, logo + "Google Maps" + the "Data attribution" link, stays on screen; only the GEV panels/HUD fade). The layer-specific credits (adsb.lol, adsbdb, TeleGeography, OSM datacenters/dams/roads, NASA FIRMS, CelesTrak, USGS, City of Austin, Fintraffic, GBFS, Radio Browser, OpenSky, AISStream) are registered into the expandable **"Data attribution"** popover on that credit line via `viewer.creditDisplay.addStaticCredit(new Cesium.Credit(html, /* showOnScreen */ false))` — see `src/data/dataCredits.js`. When you add a new data source, add its license and attribution to this file **and** append an entry to `DATA_CREDITS` in `src/data/dataCredits.js` so it surfaces in the app. +The required Google Maps / Cesium credit renders on the on-globe credit line (`#cesium-credits`, bottom-left) and must stay visible — including in clean-view and recording modes (the whole line, logo + "Google Maps" + the "Data attribution" link, stays on screen; only the GEV panels/HUD fade). The layer-specific credits (adsb.lol, adsbdb, Planespotters.net, TeleGeography, OSM datacenters/dams/roads, NASA FIRMS, CelesTrak, USGS, City of Austin, Fintraffic, GBFS, Radio Browser, OpenSky, AISStream) are registered into the expandable **"Data attribution"** popover on that credit line via `viewer.creditDisplay.addStaticCredit(new Cesium.Credit(html, /* showOnScreen */ false))` — see `src/data/dataCredits.js`. When you add a new data source, add its license and attribution to this file **and** append an entry to `DATA_CREDITS` in `src/data/dataCredits.js` so it surfaces in the app. diff --git a/docs/CODE-BOUNDARIES.md b/docs/CODE-BOUNDARIES.md index e5b337a514..591db02dcb 100644 --- a/docs/CODE-BOUNDARIES.md +++ b/docs/CODE-BOUNDARIES.md @@ -136,6 +136,9 @@ socket/watchdog on server close and re-reads configuration after restart. The portable `gods-eye-view/sources/adsb-lol` export normalizes existing aircraft records without importing Node middleware or a renderer. Browser layer/controller separation is outside this server extraction. +The portable `gods-eye-view/sources/planespotters` export reads a Planespotters +photo answer (upstream or a server's cached shape) into one host-checked, +credited thumbnail; it has no fetch, DOM or Node dependency. ## Place-search and routing providers diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 91b7a56a41..5a92f2663d 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -2812,6 +2812,17 @@ in `ais-store.js`. Common response caps, request coalescing and query parsing have their own modules. `server/providers/local.js` composes these with the remaining providers and retains existing named compatibility exports. +The tracked flight also gets a photo. The browser asks Planespotters for it +directly (`src/sources/live/standalone.js`, read by +`src/data/planespottersPhoto.js`), once per aircraft, and the CONTEXT panel's +CONTACTS view shows it under the flight's name with the photographer's credit +and a link to the photo's page. Military aircraft and a converted TR-3B are +never looked up. A flight lookup (type, route or photo) whose source failed +temporarily is asked again after a 60-second cool-down while the aircraft +stays in view or tracked; an answer, found or not, and a permanent refusal +stay final for the session. A route belongs to the callsign it was looked up +for, so a callsign change drops the old route. See `DATA_SOURCES.md`. + `gods-eye-view/server/providers/live` is a Node-only entry for the existing plugins and shared request helpers. Importing it starts no sockets or timers. The existing aircraft normalizer is separately available through the portable diff --git a/package.json b/package.json index 76808c084b..84b34d5285 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "node": "./server/providers/live.js" }, "./sources/adsb-lol": "./src/data/adsbLolFallback.js", + "./sources/planespotters": "./src/data/planespottersPhoto.js", "./server/providers/places": { "node": "./server/providers/places.js" }, diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 703aca438b..85ca44bddc 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -242,6 +242,11 @@ "modules": ["src/data/adsbLolFallback.js", "src/sources/adsbFields.js"], "external": [] }, + "planespotters-source": { + "exports": ["./sources/planespotters"], + "modules": ["src/data/planespottersPhoto.js"], + "external": [] + }, "place-providers": { "runtime": "node", "exports": ["./server/providers/places"], @@ -1395,7 +1400,8 @@ "src/sources/live/contract.js", "src/sources/live/index.js", "src/sources/live/standalone.js", - "src/sources/live/vessels.js" + "src/sources/live/vessels.js", + "src/data/planespottersPhoto.js" ], "external": [] }, @@ -1462,7 +1468,8 @@ "src/i18n/locales/zh-Hant.json", "src/ui/unitLabels.js", "src/time/worldClock.js", - "src/time/julian.js" + "src/time/julian.js", + "src/data/planespottersPhoto.js" ], "external": ["cesium"] }, @@ -3438,7 +3445,8 @@ "src/layers/satellites/classes.js", "src/layers/satellites/sensors.js", "src/data/ucsSatellites.js", - "src/data/imagingSensors.js" + "src/data/imagingSensors.js", + "src/data/planespottersPhoto.js" ], "external": [ "hls.js", @@ -4098,7 +4106,8 @@ "src/layers/satellites/classes.js", "src/layers/satellites/sensors.js", "src/data/ucsSatellites.js", - "src/data/imagingSensors.js" + "src/data/imagingSensors.js", + "src/data/planespottersPhoto.js" ], "external": [ "hls.js", @@ -5244,7 +5253,8 @@ "src/layers/satellites/classes.js", "src/layers/satellites/sensors.js", "src/data/ucsSatellites.js", - "src/data/imagingSensors.js" + "src/data/imagingSensors.js", + "src/data/planespottersPhoto.js" ], "external": ["@mapbox/vector-tile", "pbf"] }, diff --git a/scripts/qa-cockpit-utility.mjs b/scripts/qa-cockpit-utility.mjs index c5a94018fa..a342a5cdf6 100644 --- a/scripts/qa-cockpit-utility.mjs +++ b/scripts/qa-cockpit-utility.mjs @@ -4,6 +4,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import puppeteer from 'puppeteer'; +import { stubPlanespotters } from './qa-photo-stub.mjs'; const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const shotsDir = path.join(repoRoot, 'qa-shots', 'cockpit-utility'); @@ -29,6 +30,7 @@ const browser = await puppeteer.launch({ ], }); const page = await browser.newPage(); +await stubPlanespotters(page); const failures = []; const consoleErrors = []; const localHttpErrors = []; @@ -825,6 +827,7 @@ try { // a legitimate retained snapshot cannot satisfy or invalidate a FIRST-fetch // assertion when camera motion supersedes the manager's initial update. const readinessPage = await browser.newPage(); + await stubPlanespotters(readinessPage); let deferredInstallationReadiness; try { await readinessPage.setViewport({ width: 1440, height: 900 }); diff --git a/scripts/qa-context-arrivals.mjs b/scripts/qa-context-arrivals.mjs index 72a6ffab8a..704d34a6b3 100644 --- a/scripts/qa-context-arrivals.mjs +++ b/scripts/qa-context-arrivals.mjs @@ -28,6 +28,7 @@ import fs from 'node:fs'; import path from 'node:path'; import puppeteer from 'puppeteer'; +import { stubPlanespotters } from './qa-photo-stub.mjs'; import { createScreencast, moveCamera } from './qa-journey-recorder.mjs'; const argv = process.argv.slice(2); @@ -77,6 +78,7 @@ const browser = await puppeteer.launch({ async function openPage({ aircraft = false } = {}) { const page = await browser.newPage(); + await stubPlanespotters(page); await page.setViewport({ width: 1440, height: 900 }); page.on('console', (message) => { if (message.type() === 'error') result.consoleErrors.push(message.text()); diff --git a/scripts/qa-emergency-squawk.mjs b/scripts/qa-emergency-squawk.mjs index f877ea6594..aeedd61252 100644 --- a/scripts/qa-emergency-squawk.mjs +++ b/scripts/qa-emergency-squawk.mjs @@ -27,6 +27,7 @@ */ import puppeteer from 'puppeteer'; +import { stubPlanespotters } from './qa-photo-stub.mjs'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -223,6 +224,7 @@ async function main() { const errors = []; try { const page = await browser.newPage(); + await stubPlanespotters(page); await page.setViewport({ width: 1440, height: 900 }); page.on('pageerror', (e) => errors.push(e.message)); const { lon, lat } = CENTER; diff --git a/scripts/qa-focus-evidence.mjs b/scripts/qa-focus-evidence.mjs index 1baaf60837..cae1c5c724 100644 --- a/scripts/qa-focus-evidence.mjs +++ b/scripts/qa-focus-evidence.mjs @@ -21,6 +21,7 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import puppeteer from 'puppeteer'; +import { stubPlanespotters } from './qa-photo-stub.mjs'; const argv = process.argv.slice(2); const getOpt = (name, fallback = null) => { @@ -651,6 +652,7 @@ async function main() { ], }); const page = await browser.newPage(); + await stubPlanespotters(page); await page.setViewport(VIEWPORT); const consoleMessages = []; page.on('console', (message) => { diff --git a/scripts/qa-heading-b3.mjs b/scripts/qa-heading-b3.mjs index cbba1b88ef..fb33654b13 100644 --- a/scripts/qa-heading-b3.mjs +++ b/scripts/qa-heading-b3.mjs @@ -99,6 +99,7 @@ import fs from 'node:fs'; import path from 'node:path'; import puppeteer from 'puppeteer'; +import { stubPlanespotters } from './qa-photo-stub.mjs'; // --------------------------------------------------------------------------- // Args (same shape as track-regression.mjs) @@ -466,6 +467,7 @@ async function main() { const failedResponses = []; try { const page = await browser.newPage(); + await stubPlanespotters(page); await page.setViewport({ width: 1280, height: 800 }); page.on('console', (msg) => { if (msg.type() === 'error') { diff --git a/scripts/qa-photo-stub.mjs b/scripts/qa-photo-stub.mjs new file mode 100644 index 0000000000..43dd2becbd --- /dev/null +++ b/scripts/qa-photo-stub.mjs @@ -0,0 +1,78 @@ +/** + * Keep browser QA off third-party aircraft photo services. + * + * Tracking a civil flight asks Planespotters for the aircraft's photo. QA + * runs track synthetic hexes, so a real request only adds a third-party + * dependency and, when the service refuses a headless browser, a console + * error that fails the "no console errors" checks. Every photo lookup is + * answered with no photos instead, without leaving the browser. + */ + +/** Origin of the aircraft photo lookup. */ +export const PLANESPOTTERS_ORIGIN = 'https://api.planespotters.net'; + +/** The answer every stubbed lookup gets: no photos for this aircraft. */ +export const PLANESPOTTERS_EMPTY_BODY = JSON.stringify({ photos: [] }); + +/** Whether a URL is a photo lookup the stub answers. */ +export function isPlanespottersRequest(url) { + try { + return new URL(String(url)).origin === PLANESPOTTERS_ORIGIN; + } catch { + return false; + } +} + +/** + * Answer an intercepted photo lookup from a page that already uses request + * interception. Returns false for any other request, which the caller + * handles as before. + * @param {import('puppeteer').HTTPRequest} request + * @returns {boolean} Whether the request was answered. + */ +export function respondToPlanespotters(request) { + if (!isPlanespottersRequest(request.url())) return false; + request.respond({ + status: 200, + contentType: 'application/json', + headers: { 'Access-Control-Allow-Origin': '*' }, + body: PLANESPOTTERS_EMPTY_BODY, + }); + return true; +} + +/** + * Stub photo lookups in a page that does not intercept requests: wraps + * `fetch` before any app code runs, so a lookup never reaches the network. + * Composes with other `fetch` shims in either order. + * @param {import('puppeteer').Page} page + * @returns {Promise} + */ +export async function stubPlanespotters(page) { + await page.evaluateOnNewDocument( + (origin, body) => { + const original = window.fetch.bind(window); + window.fetch = (input, init) => { + const href = + typeof input === 'string' ? input : input?.url || String(input); + let target = ''; + try { + target = new URL(href, location.href).origin; + } catch { + /* not a URL */ + } + if (target === origin) { + return Promise.resolve( + new Response(body, { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }), + ); + } + return original(input, init); + }; + }, + PLANESPOTTERS_ORIGIN, + PLANESPOTTERS_EMPTY_BODY, + ); +} diff --git a/scripts/qa-sprites-b5.mjs b/scripts/qa-sprites-b5.mjs index a70eb1b2db..7e5b824c0b 100644 --- a/scripts/qa-sprites-b5.mjs +++ b/scripts/qa-sprites-b5.mjs @@ -32,6 +32,7 @@ import fs from 'node:fs'; import path from 'node:path'; import puppeteer from 'puppeteer'; +import { stubPlanespotters } from './qa-photo-stub.mjs'; import { classifyAircraft, CLASS_SCALE_2D, CLASS_SCALE_3D, CLASS_MODEL_REAL } from '../src/data/aircraftClass.js'; // Hangar fleet (2026-08-16): real per-class GLBs render at scale 1; military // heavies (airliner/quadjet/glider) render airplane.glb at 1 x class; only @@ -186,6 +187,7 @@ async function main() { const httpErrors = []; try { const page = await browser.newPage(); + await stubPlanespotters(page); await page.setViewport({ width: 1280, height: 800 }); page.on('console', (msg) => { if (msg.type() === 'error') { diff --git a/scripts/track-regression.mjs b/scripts/track-regression.mjs index 16c345db5a..d2e04609b3 100644 --- a/scripts/track-regression.mjs +++ b/scripts/track-regression.mjs @@ -94,6 +94,7 @@ import fs from 'node:fs'; import puppeteer from 'puppeteer'; +import { respondToPlanespotters } from './qa-photo-stub.mjs'; import { arrivalAngleViolated, arrivalRotationPassed } from '../src/tooling/trackArrivalObservation.mjs'; import { classifyAircraft, CLASS_SCALE_3D, CLASS_MODEL_REAL } from '../src/data/aircraftClass.js'; import { ensureGeoidReady, geoidHeight } from '../src/data/geoid.js'; @@ -287,6 +288,8 @@ async function main() { }); return; } + // Aircraft photo lookups never reach the third party: no photos. + if (respondToPlanespotters(request)) return; if (url.origin === APP_ORIGIN && url.pathname === '/api/openai/hud-summary') { request.respond({ status: 200, diff --git a/src/data/dataCredits.js b/src/data/dataCredits.js index 6b972fc28a..7413f1bab0 100644 --- a/src/data/dataCredits.js +++ b/src/data/dataCredits.js @@ -134,6 +134,13 @@ export const DATA_CREDITS = [ 'copied, published, or incorporated into other databases without the ' + 'explicit permission of David J Taylor, Edinburgh', }, + { + key: 'planespotters', + html: + 'Aircraft photos: ' + + 'Planespotters.net ' + + '· each photo is © its photographer, credited beside it', + }, { key: 'aisstream', html: diff --git a/src/data/dataCredits.test.mjs b/src/data/dataCredits.test.mjs index ef20250fc5..e0c85623a4 100644 --- a/src/data/dataCredits.test.mjs +++ b/src/data/dataCredits.test.mjs @@ -43,6 +43,13 @@ test('adsbdb is credited and carries its published route-data restriction', () = assert.match(credit.html, /href="https:\/\/www\.adsbdb\.com"/); }); +test('Planespotters is credited with a plain followable link', () => { + const credit = DATA_CREDITS.find((entry) => entry.key === 'planespotters'); + assert.ok(credit, 'the tracked aircraft photos come from Planespotters'); + assert.match(credit.html, /href="https:\/\/www\.planespotters\.net"/); + assert.doesNotMatch(credit.html, /nofollow/); +}); + test('the UCS Satellite Database is acknowledged with its version and webpage', () => { // UCS database manual, section 3: references name the version (the Excel // file's name) and link www.ucsusa.org/satellite_database. diff --git a/src/data/flights.js b/src/data/flights.js index 6e2d35dbc5..815ae41ed6 100644 --- a/src/data/flights.js +++ b/src/data/flights.js @@ -40,5 +40,7 @@ export const _driveFleetModelHandoffForTest = flightsLayer.testing._driveFleetModelHandoffForTest; export const _ensureFleetModelForTest = flightsLayer.testing._ensureFleetModelForTest; +export const _resetEnrichmentForTest = + flightsLayer.testing._resetEnrichmentForTest; export const mapAnalystRecord = flightsLayer.mapAnalystRecord; export default flightsLayer; diff --git a/src/data/flights.test.mjs b/src/data/flights.test.mjs index 1d6007e8f3..5005723d9b 100644 --- a/src/data/flights.test.mjs +++ b/src/data/flights.test.mjs @@ -1,7 +1,7 @@ // src/data/flights.test.mjs // Focused tests for the pure analyst-record mapper (analyst query engine seam). // Pure function — no viewer/DOM needed; imported directly. -import { test } from 'node:test'; +import { after, afterEach, before, test } from 'node:test'; import assert from 'node:assert/strict'; import * as Cesium from 'cesium'; import flightsLayer, { @@ -14,9 +14,14 @@ import flightsLayer, { _setTrackedFlightRefreshStateForTest, _floorGroundedDisplayPositionForTest, _clearDisplayFloorStateForTest, + _resetEnrichmentForTest, mapAnalystRecord, } from './flights.js'; -import { setMilitaryLayerActive } from './militaryRegistry.js'; +import { + isMilitaryLayerActive, + registerMilitaryIcaos, + setMilitaryLayerActive, +} from './militaryRegistry.js'; import { GROUND_FLOOR_LIFT_M, reportMeshFloorCell, @@ -31,6 +36,31 @@ import { initTrackedReadout, } from './trackedReadout.js'; +// Unit tests never reach the network. A test that tracks a plane queues its +// enrichment (type, route, photo), so every test ends on an empty queue, and a +// fetch of any absolute URL fails the test it happened in. A test that needs +// answers installs its own fetch and restores this one. +const nodeFetch = globalThis.fetch; +const networkRequests = []; +before(() => { + globalThis.fetch = async (url) => { + const href = String(url?.url ?? url); + if (/^https?:\/\//i.test(href)) networkRequests.push(href); + throw new TypeError(`Failed to parse URL from ${href}`); + }; +}); +afterEach(() => { + _resetEnrichmentForTest(); + assert.deepEqual( + networkRequests.splice(0), + [], + 'no test reaches the network', + ); +}); +after(() => { + globalThis.fetch = nodeFetch; +}); + test('share-Follow absence requires an accepted OpenSky snapshot', async () => { _setFlightTrackingRefreshOutcomeForTest({ status: 'source-unavailable' }); assert.equal( @@ -404,6 +434,232 @@ test('flights poll refreshes tracked callsign/FL/kts and marks a missed poll STA } }); +test('a tracked plane whose photo lookup failed asks again on the first poll after the cool-down', async (t) => { + const icao24 = 'b2c3d4'; + const realNow = Date.now.bind(Date); + let offsetMs = 0; + t.mock.method(Date, 'now', () => realNow() + offsetMs); + const entity = { gevLabelModel: { title: 'OLD', details: [] } }; + const viewer = { camera: { positionCartographic: null }, scene: {} }; + _setTrackedFlightRefreshStateForTest({ + icao24, + entity, + billboard: { + position: Cesium.Cartesian3.fromDegrees(-97.7, 30.2, 9_000), + color: Cesium.Color.WHITE, + show: false, + }, + billboardCollection: { show: false, remove() {} }, + viewer, + meta: { + callsign: 'UAL9', + altitude: 9_000, + renderAltitudeM: 9_050, + velocity: 180, + true_track: 80, + klass: 'airliner', + onGround: false, + wasAirborne: true, + turnRateDps: 0, + rawLat: 30.2, + rawLon: -97.7, + }, + }); + let callsign = 'UAL9 '; + const photoRequests = []; + const routeRequests = []; + const guardFetch = globalThis.fetch; + globalThis.fetch = async (url) => { + url = String(url); + if (url.startsWith('https://api.planespotters.net/')) { + photoRequests.push(url); + return { ok: false, status: 503, json: async () => ({}) }; + } + if (url.startsWith('/api/adsbdb/route/UAL')) routeRequests.push(url); + if (!url.startsWith('/api/flights')) + return { ok: true, status: 200, json: async () => ({ found: false }) }; + const nowSec = Math.floor(Date.now() / 1000); + return { + ok: true, + status: 200, + headers: { get: () => null }, + json: async () => ({ + time: nowSec, + states: [ + [ + icao24, + callsign, + 'United States', + nowSec, + nowSec, + -97.6, + 30.3, + 10_668, + false, + 250, + 95, + 5, + null, + 10_700, + null, + null, + null, + 5, + ], + ], + }), + }; + }; + // Lookups drip out one per 200 ms. Wait for what must arrive (with a + // generous deadline, so a loaded machine cannot fail it), then a little + // longer so anything that must NOT arrive would have. + const until = async (ready) => { + const deadline = realNow() + 5_000; + while (!ready() && realNow() < deadline) + await new Promise((done) => setTimeout(done, 20)); + await new Promise((done) => setTimeout(done, 450)); + }; + try { + await flightsLayer.update(viewer); + await until(() => photoRequests.length >= 1 && routeRequests.length >= 1); + assert.equal(photoRequests.length, 1, 'the first poll asks for the photo'); + assert.deepEqual(routeRequests, ['/api/adsbdb/route/UAL9']); + + // Well inside the 60 s cool-down, and well past it below, so real time + // spent between polls cannot move either side across the line. + offsetMs += 30_000; + callsign = 'UAL10 '; + await flightsLayer.update(viewer); + await until(() => routeRequests.length >= 2); + assert.equal(photoRequests.length, 1, 'not within the cool-down'); + assert.deepEqual( + routeRequests, + ['/api/adsbdb/route/UAL9', '/api/adsbdb/route/UAL10'], + 'the route follows the callsign the poll just recorded', + ); + + offsetMs += 60_000; + await flightsLayer.update(viewer); + await until(() => photoRequests.length >= 2); + assert.deepEqual( + photoRequests, + [ + 'https://api.planespotters.net/pub/photos/hex/b2c3d4', + 'https://api.planespotters.net/pub/photos/hex/b2c3d4', + ], + 'asked again on the first poll after the cool-down', + ); + } finally { + globalThis.fetch = guardFetch; + // The moved clock dated this layer's dispatch and cool-downs into the + // future; reset before the real clock comes back. + _resetEnrichmentForTest(); + t.mock.restoreAll(); + } +}); + +test('a known-military aircraft tracked in the flights layer is never looked up and shows no photo', async () => { + const icao24 = 'ae5e01'; + // The registry has no way to forget one hex (only a whole-registry reset, + // which would also drop its source), so the test uses a hex no other test + // reads and restores the layer-active flag it changes. + const militaryWasActive = isMilitaryLayerActive(); + registerMilitaryIcaos([icao24]); + setMilitaryLayerActive(false); + const viewer = { camera: { positionCartographic: null }, scene: {} }; + _setTrackedFlightRefreshStateForTest({ + icao24, + entity: { gevLabelModel: { title: 'OLD', details: [] } }, + billboard: { + position: Cesium.Cartesian3.fromDegrees(-97.7, 30.2, 9_000), + color: Cesium.Color.WHITE, + show: false, + }, + billboardCollection: { show: false, remove() {} }, + viewer, + meta: { + callsign: 'RCH123', + altitude: 9_000, + renderAltitudeM: 9_050, + velocity: 180, + true_track: 80, + klass: 'airliner', + onGround: false, + wasAirborne: true, + turnRateDps: 0, + rawLat: 30.2, + rawLon: -97.7, + // Even a photo already on the record is never shown. + photo: { + src: 'https://t.plnspttrs.net/1/ae5e01_280.jpg', + width: 280, + height: 186, + photographer: 'Jane Doe', + link: 'https://www.planespotters.net/photo/1/x', + }, + }, + }); + const photoRequests = []; + const routeRequests = []; + const guardFetch = globalThis.fetch; + globalThis.fetch = async (url) => { + url = String(url); + if (url.startsWith('https://api.planespotters.net/')) { + photoRequests.push(url); + return { ok: false, status: 503, json: async () => ({}) }; + } + if (url.startsWith('/api/adsbdb/route/')) routeRequests.push(url); + if (!url.startsWith('/api/flights')) + return { ok: true, status: 200, json: async () => ({ found: false }) }; + const nowSec = Math.floor(Date.now() / 1000); + return { + ok: true, + status: 200, + headers: { get: () => null }, + json: async () => ({ + time: nowSec, + states: [ + [ + icao24, + 'RCH123 ', + 'United States', + nowSec, + nowSec, + -97.6, + 30.3, + 10_668, + false, + 250, + 95, + 5, + null, + 10_700, + null, + null, + null, + 5, + ], + ], + }), + }; + }; + try { + await flightsLayer.update(viewer); + // A photo lookup would go out ahead of the route; wait for the route. + const deadline = Date.now() + 5_000; + while (!routeRequests.length && Date.now() < deadline) + await new Promise((done) => setTimeout(done, 20)); + assert.deepEqual(routeRequests, ['/api/adsbdb/route/RCH123']); + assert.deepEqual(photoRequests, [], 'no photo lookup for a military hex'); + assert.equal(flightsLayer.getTrackedInfo()?.icao24, icao24); + assert.equal(flightsLayer.getTrackedInfo()?.photo, null); + assert.equal(flightsLayer.getTrackedSubject()?.photo, null); + } finally { + globalThis.fetch = guardFetch; + setMilitaryLayerActive(militaryWasActive); + } +}); + test('real civil track path creates no native label and publishes every cached host line', async () => { const icao24 = 'civ001'; const position = Cesium.Cartesian3.fromDegrees(-97.6699, 30.1945, 10_668); diff --git a/src/data/militaryAwareness.test.mjs b/src/data/militaryAwareness.test.mjs index 98743b03c2..430ca3362c 100644 --- a/src/data/militaryAwareness.test.mjs +++ b/src/data/militaryAwareness.test.mjs @@ -425,7 +425,7 @@ test('a dependency the user adopts stays on when Contacts turns off', async () = assert.deepEqual( released, AWARENESS_DEPENDENCIES.filter((layerId) => layerId !== 'flights').sort(), - 'the adopted layer is the user\'s now; the rest are still released', + "the adopted layer is the user's now; the rest are still released", ); } finally { runtime.restore(); @@ -1118,6 +1118,92 @@ test('production military tracked-subject label falls back to registration befor } }); +test('the tracked airliner’s photo reaches the Contacts panel when it lands after selection', async () => { + const id = 'a1f2c3'; + const position = Cesium.Cartesian3.fromDegrees(-97.71, 30.21, 10_668); + const sourceViewer = { camera: { positionCartographic: null }, scene: {} }; + const runtime = installAwarenessRuntime(); + const restores = []; + const meta = { + callsign: 'AAL100', + altitude: 10_668, + renderAltitudeM: 10_700, + velocity: 250, + true_track: 95, + klass: 'airliner', + onGround: false, + wasAirborne: true, + turnRateDps: 0, + rawLat: 30.21, + rawLon: -97.71, + photo: null, + }; + + try { + _setTrackedFlightRefreshStateForTest({ + icao24: id, + entity: null, + billboard: { position, color: Cesium.Color.WHITE, show: true }, + billboardCollection: { show: true, remove() {} }, + viewer: sourceViewer, + meta, + }); + runtime.viewer.trackedEntity = { gevTrackedId: `flights:${id}` }; + replaceMethod( + militaryFlightsLayer, + 'getTrackedSubject', + () => null, + restores, + ); + replaceMethod(flightsLayer, 'trackById', () => true, restores); + replaceMethod(militaryFlightsLayer, 'trackById', () => true, restores); + + militaryAwarenessLayer.setParams({ passive: false }); + await nextTurn(); + assert.equal(runtime.panel().view?.kind, 'results'); + assert.equal(runtime.panel().view.photo, null, 'no photo before it lands'); + + // An unchanged refresh stays quiet. + const settledPublishes = runtime.panel().publishes; + await militaryAwarenessLayer.update(); + assert.equal(runtime.panel().publishes, settledPublishes); + + // The photo lands while the plane holds still: render-worthy on its own. + meta.photo = { + src: 'https://t.plnspttrs.net/1/a1f2c3_280.jpg', + width: 280, + height: 186, + photographer: 'Jane Doe', + link: 'https://www.planespotters.net/photo/1/n100aa', + }; + await militaryAwarenessLayer.update(); + assert.deepEqual(runtime.panel().view.photo, { + src: 'https://t.plnspttrs.net/1/a1f2c3_280.jpg', + width: 280, + height: 186, + link: 'https://www.planespotters.net/photo/1/n100aa', + credit: 'Photo © Jane Doe', + }); + + // And it repaints once, not on every refresh. + const shownPublishes = runtime.panel().publishes; + await militaryAwarenessLayer.update(); + assert.equal(runtime.panel().publishes, shownPublishes); + } finally { + restores.reverse().forEach((restore) => restore()); + _setTrackedFlightRefreshStateForTest({ + icao24: id, + entity: null, + billboard: { position, show: true }, + billboardCollection: { show: false, remove() {} }, + viewer: sourceViewer, + meta: {}, + tracked: false, + }); + runtime.restore(); + } +}); + test('a cached Context subject re-reads its label when enrichment lands after selection', async () => { // The subject snapshot is captured once at selection. Selecting a // callsign-less aircraft BEFORE adsbdb enrichment answers used to freeze the diff --git a/src/data/planespottersPhoto.js b/src/data/planespottersPhoto.js new file mode 100644 index 0000000000..8346df49f0 --- /dev/null +++ b/src/data/planespottersPhoto.js @@ -0,0 +1,121 @@ +/** + * @module planespottersPhoto + * @description Reads a Planespotters photo answer into the one credited + * thumbnail every surface shows. Planespotters lets the thumbnail be hotlinked + * on the condition that the photographer is credited next to it and the image + * links back to the photo's page, so a photo without a photographer, or whose + * image or page is not on Planespotters' own hosts, is "no photo": nothing + * arbitrary is ever shown or linked. + * + * Accepts the upstream answer (`GET https://api.planespotters.net/pub/photos/hex/{hex}`, + * `{photos: [...]}`), the cached server shape + * (`{found, thumbnail_large?, thumbnail: {src, width, height}, photographer, + * link}`), and an + * already-read photo (`{found, src, width, height, photographer, link}`). + * Pure: no fetch, no DOM. + */ + +/** The image host: Planespotters' thumbnail CDN and its subdomains. */ +const IMAGE_HOST = 'plnspttrs.net'; +/** The only page host a photo may link to. */ +const PAGE_HOST = 'www.planespotters.net'; + +const NO_PHOTO = Object.freeze({ found: false }); + +const isObject = (value) => Boolean(value) && typeof value === 'object'; + +/** The parsed `https:` URL, or null for anything else or with userinfo/port. */ +function httpsUrl(value) { + if (typeof value !== 'string' || !value) return null; + let url; + try { + url = new URL(value); + } catch { + return null; + } + if (url.protocol !== 'https:' || url.username || url.password || url.port) + return null; + return url; +} + +function imageSrc(value) { + const url = httpsUrl(value); + return url && + (url.hostname === IMAGE_HOST || url.hostname.endsWith(`.${IMAGE_HOST}`)) + ? url.href + : null; +} + +function pageLink(value) { + const url = httpsUrl(value); + return url && url.hostname === PAGE_HOST ? url.href : null; +} + +function dimension(value) { + const number = Number(value); + return value != null && Number.isFinite(number) && number > 0 + ? Math.round(number) + : null; +} + +/** One candidate `{src, width, height, photographer, link}`, checked. */ +function checked({ src, width, height, photographer, link }) { + const credit = typeof photographer === 'string' ? photographer.trim() : ''; + const image = imageSrc(src); + const page = pageLink(link); + if (!credit || !image || !page) return null; + return { + found: true, + src: image, + width: dimension(width), + height: dimension(height), + photographer: credit, + link: page, + }; +} + +/** The upstream photo's candidates, large thumbnail first. */ +function upstreamCandidates(photo) { + if (!photo || typeof photo !== 'object') return []; + return [photo.thumbnail_large, photo.thumbnail] + .filter((thumb) => thumb && typeof thumb === 'object') + .map((thumb) => ({ + src: thumb.src, + width: thumb.size?.width, + height: thumb.size?.height, + photographer: photo.photographer, + link: photo.link, + })); +} + +/** + * Read a Planespotters answer into the first photo that passes the checks. + * @param {*} payload Upstream, cached-server, or already-read photo. + * @returns {{found: true, src: string, width: ?number, height: ?number, + * photographer: string, link: string} | {found: false}} + */ +export function parsePlanespottersPhoto(payload) { + if (!payload || typeof payload !== 'object') return NO_PHOTO; + let candidates; + if (Array.isArray(payload.photos)) { + candidates = payload.photos.flatMap(upstreamCandidates); + } else if (payload.found !== true) { + return NO_PHOTO; + } else if (isObject(payload.thumbnail) || isObject(payload.thumbnail_large)) { + // Large first, as for the upstream answer; each must pass the checks. + candidates = [payload.thumbnail_large, payload.thumbnail] + .filter(isObject) + .map((thumb) => ({ + ...thumb, + photographer: payload.photographer, + link: payload.link, + })); + } else { + candidates = [payload]; + } + for (const candidate of candidates) { + const photo = checked(candidate); + if (photo) return photo; + } + return NO_PHOTO; +} diff --git a/src/data/planespottersPhoto.test.mjs b/src/data/planespottersPhoto.test.mjs new file mode 100644 index 0000000000..e051367f28 --- /dev/null +++ b/src/data/planespottersPhoto.test.mjs @@ -0,0 +1,200 @@ +// src/data/planespottersPhoto.test.mjs — the Planespotters photo answer is read +// into one credited thumbnail, and nothing outside Planespotters' own hosts is +// ever shown or linked. +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { parsePlanespottersPhoto } from './planespottersPhoto.js'; + +const UPSTREAM = Object.freeze({ + photos: [ + { + id: '1745410', + thumbnail: { + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_t.jpg', + size: { width: 200, height: 133 }, + }, + thumbnail_large: { + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_280.jpg', + size: { width: 420, height: 280 }, + }, + link: 'https://www.planespotters.net/photo/1745410/n160an-american-airlines-airbus-a321-231-wl?utm_source=api', + photographer: 'Jan Seler', + }, + ], +}); + +const PHOTO = Object.freeze({ + found: true, + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_280.jpg', + width: 420, + height: 280, + photographer: 'Jan Seler', + link: 'https://www.planespotters.net/photo/1745410/n160an-american-airlines-airbus-a321-231-wl?utm_source=api', +}); + +const photo = (overrides) => ({ + photos: [{ ...UPSTREAM.photos[0], ...overrides }], +}); + +test('the upstream answer maps to the large thumbnail, its size, credit and link', () => { + assert.deepEqual(parsePlanespottersPhoto(UPSTREAM), PHOTO); +}); + +test('the small thumbnail stands in when the large one is missing', () => { + assert.deepEqual(parsePlanespottersPhoto(photo({ thumbnail_large: null })), { + ...PHOTO, + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_t.jpg', + width: 200, + height: 133, + }); +}); + +test('a server’s cached shape reads the same way', () => { + assert.deepEqual( + parsePlanespottersPhoto({ + found: true, + thumbnail: { src: PHOTO.src, width: 420, height: 280 }, + photographer: 'Jan Seler', + link: PHOTO.link, + }), + PHOTO, + ); + assert.deepEqual(parsePlanespottersPhoto({ found: false }), { + found: false, + }); +}); + +test('a server’s cached shape prefers its large thumbnail', () => { + assert.deepEqual( + parsePlanespottersPhoto({ + found: true, + thumbnail: { + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_t.jpg', + width: 200, + height: 133, + }, + thumbnail_large: { src: PHOTO.src, width: 420, height: 280 }, + photographer: 'Jan Seler', + link: PHOTO.link, + }), + PHOTO, + ); +}); + +test('a server’s cached shape falls back to its small thumbnail when the large one fails the checks', () => { + const small = { + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_t.jpg', + width: 200, + height: 133, + }; + for (const thumbnail_large of [ + { src: 'https://evil.example/a.jpg', width: 420, height: 280 }, + null, + ]) { + assert.deepEqual( + parsePlanespottersPhoto({ + found: true, + thumbnail: small, + thumbnail_large, + photographer: 'Jan Seler', + link: PHOTO.link, + }), + { ...PHOTO, ...small }, + JSON.stringify(thumbnail_large), + ); + } +}); + +test('no photo, junk, and missing fields are "no photo"', () => { + for (const payload of [ + { photos: [] }, + {}, + null, + undefined, + 'nope', + { photos: 'nope' }, + { photos: [null] }, + photo({ photographer: '' }), + photo({ photographer: ' ' }), + photo({ photographer: 42 }), + photo({ link: '' }), + photo({ thumbnail: null, thumbnail_large: null }), + ]) { + assert.deepEqual( + parsePlanespottersPhoto(payload), + { found: false }, + JSON.stringify(payload), + ); + } +}); + +test('a src outside https *.plnspttrs.net is dropped', () => { + for (const src of [ + 'http://t.plnspttrs.net/a.jpg', + 'https://plnspttrs.net.evil.example/a.jpg', + 'https://evil.example/t.plnspttrs.net/a.jpg', + 'https://t.plnspttrs.net.evil.example/a.jpg', + 'https://user@t.plnspttrs.net/a.jpg', + 'https://t.plnspttrs.net:8443/a.jpg', + 'javascript:alert(1)', + '//t.plnspttrs.net/a.jpg', + 'not a url', + ]) { + assert.deepEqual( + parsePlanespottersPhoto( + photo({ + thumbnail_large: { src, size: { width: 420, height: 280 } }, + thumbnail: { src, size: { width: 200, height: 133 } }, + }), + ), + { found: false }, + src, + ); + } +}); + +test('a link anywhere but https://www.planespotters.net is dropped', () => { + for (const link of [ + 'http://www.planespotters.net/photo/1', + 'https://planespotters.net/photo/1', + 'https://www.planespotters.net.evil.example/photo/1', + 'https://evil.example/?u=https://www.planespotters.net/', + 'https://user:pw@www.planespotters.net/photo/1', + 'https://www.planespotters.net:444/photo/1', + 'javascript:alert(1)', + ]) { + assert.deepEqual( + parsePlanespottersPhoto(photo({ link })), + { found: false }, + link, + ); + } +}); + +test('the first photo that passes the checks is the one shown', () => { + const second = { + ...UPSTREAM.photos[0], + photographer: 'Second Spotter', + }; + assert.deepEqual( + parsePlanespottersPhoto({ + photos: [ + { ...UPSTREAM.photos[0], link: 'https://evil.example/' }, + second, + ], + }), + { ...PHOTO, photographer: 'Second Spotter' }, + ); +}); + +test('a missing size is null and the credit is trimmed', () => { + assert.deepEqual( + parsePlanespottersPhoto( + photo({ + photographer: ' Jan Seler ', + thumbnail_large: { src: PHOTO.src }, + }), + ), + { ...PHOTO, width: null, height: null }, + ); +}); diff --git a/src/i18n/locales/ar.json b/src/i18n/locales/ar.json index 83e163cde2..59a18415fd 100644 --- a/src/i18n/locales/ar.json +++ b/src/i18n/locales/ar.json @@ -3619,5 +3619,6 @@ "1 wk/s": "أسبوع/ث", "Play speed": "سرعة التشغيل", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "مرّر أو اقرص للتكبير، واسحب للتنقل · انقر نقرًا مزدوجًا لرؤية الكل", - "1 min/s": "دقيقة/ث" + "1 min/s": "دقيقة/ث", + "Photo © {photographer}": "صورة © {photographer}" } diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index c21a9f936e..02d6fdb73f 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -3311,5 +3311,6 @@ "1 wk/s": "1 Wo./s", "Play speed": "Wiedergabegeschwindigkeit", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "Scrollen oder mit zwei Fingern zoomen, ziehen zum Verschieben · Doppelklick zeigt alles", - "1 min/s": "1 Min./s" + "1 min/s": "1 Min./s", + "Photo © {photographer}": "Foto © {photographer}" } diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index c060630e2b..a007bec4ee 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -3388,5 +3388,6 @@ "1 wk/s": "1 sem/s", "Play speed": "Velocidad de reproducción", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "Desplaza o pellizca para ampliar, arrastra para moverte · doble clic para verlo todo", - "1 min/s": "1 min/s" + "1 min/s": "1 min/s", + "Photo © {photographer}": "Foto © {photographer}" } diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index e0731d11a6..f394eaf98c 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -3388,5 +3388,6 @@ "1 wk/s": "1 sem/s", "Play speed": "Vitesse de lecture", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "Faites défiler ou pincez pour zoomer, glissez pour vous déplacer · double-clic pour tout voir", - "1 min/s": "1 min/s" + "1 min/s": "1 min/s", + "Photo © {photographer}": "Photo © {photographer}" } diff --git a/src/i18n/locales/it.json b/src/i18n/locales/it.json index 3ff2a83138..8122e2c471 100644 --- a/src/i18n/locales/it.json +++ b/src/i18n/locales/it.json @@ -3388,5 +3388,6 @@ "1 wk/s": "1 sett/s", "Play speed": "Velocità di riproduzione", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "Scorri o pizzica per lo zoom, trascina per spostarti · doppio clic per vedere tutto", - "1 min/s": "1 min/s" + "1 min/s": "1 min/s", + "Photo © {photographer}": "Foto © {photographer}" } diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index a4bd4522bb..9c716ec48c 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -3234,5 +3234,6 @@ "1 wk/s": "1週間/秒", "Play speed": "再生速度", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "スクロールまたはピンチでズーム、ドラッグで移動 · ダブルクリックで全体表示", - "1 min/s": "1分/秒" + "1 min/s": "1分/秒", + "Photo © {photographer}": "写真 © {photographer}" } diff --git a/src/i18n/locales/pt.json b/src/i18n/locales/pt.json index e1578d66d1..1afd6d3829 100644 --- a/src/i18n/locales/pt.json +++ b/src/i18n/locales/pt.json @@ -3388,5 +3388,6 @@ "1 wk/s": "1 sem/s", "Play speed": "Velocidade de reprodução", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "Role ou faça pinça para ampliar, arraste para se mover · clique duplo para ver tudo", - "1 min/s": "1 min/s" + "1 min/s": "1 min/s", + "Photo © {photographer}": "Foto © {photographer}" } diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 43639b06fa..d6af529c03 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -3465,5 +3465,6 @@ "1 wk/s": "1 нед/с", "Play speed": "Скорость воспроизведения", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "Прокрутите или сведите пальцы для масштаба, перетащите для перемещения · двойной щелчок — показать всё", - "1 min/s": "1 мин/с" + "1 min/s": "1 мин/с", + "Photo © {photographer}": "Фото © {photographer}" } diff --git a/src/i18n/locales/uk.json b/src/i18n/locales/uk.json index a991488535..6826eb2fa5 100644 --- a/src/i18n/locales/uk.json +++ b/src/i18n/locales/uk.json @@ -3465,5 +3465,6 @@ "1 wk/s": "1 тиж/с", "Play speed": "Швидкість відтворення", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "Прокрутіть або зведіть пальці для масштабу, перетягніть для переміщення · подвійне клацання — показати все", - "1 min/s": "1 хв/с" + "1 min/s": "1 хв/с", + "Photo © {photographer}": "Фото © {photographer}" } diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index e7d9ca3843..d0af7ee5ec 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -3234,5 +3234,6 @@ "1 wk/s": "1 周/秒", "Play speed": "播放速度", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "滚动或双指缩放,拖动以移动 · 双击查看全部", - "1 min/s": "1 分钟/秒" + "1 min/s": "1 分钟/秒", + "Photo © {photographer}": "照片 © {photographer}" } diff --git a/src/i18n/locales/zh-Hant.json b/src/i18n/locales/zh-Hant.json index 1042a0d356..c0e22141bd 100644 --- a/src/i18n/locales/zh-Hant.json +++ b/src/i18n/locales/zh-Hant.json @@ -3234,5 +3234,6 @@ "1 wk/s": "1 週/秒", "Play speed": "播放速度", "Scroll or pinch to zoom, drag to move along · double-click to see it all": "捲動或雙指縮放,拖曳以移動 · 按兩下查看全部", - "1 min/s": "1 分鐘/秒" + "1 min/s": "1 分鐘/秒", + "Photo © {photographer}": "照片 © {photographer}" } diff --git a/src/i18n/same-as-english.json b/src/i18n/same-as-english.json index 8c2a2bd758..458354169f 100644 --- a/src/i18n/same-as-english.json +++ b/src/i18n/same-as-english.json @@ -586,7 +586,8 @@ "Ⅱ PAUSE", "≥ {value} MW", "▲ {frp} MW", - "SATELLITE" + "SATELLITE", + "Photo © {photographer}" ], "it": [ "1 min/s", diff --git a/src/layers/awareness/panel.js b/src/layers/awareness/panel.js index 5396a0390a..fbc9725c9f 100644 --- a/src/layers/awareness/panel.js +++ b/src/layers/awareness/panel.js @@ -182,6 +182,28 @@ export function createPanel({ state: layerState, parts }) { : null; } + /** The tracked airliner's photo with its credit, or null. The subject + * refresh resolves it; only the subject it was resolved for shows it. */ + function presentPhoto(subject) { + const held = layerState.subjectPhoto; + if ( + !held || + held.layerId !== subject.layerId || + String(held.id) !== String(subject.id) + ) + return null; + const { photo } = held; + return { + src: photo.src, + width: photo.width ?? null, + height: photo.height ?? null, + link: photo.link, + credit: t('Photo © {photographer}', { + photographer: photo.photographer, + }), + }; + } + function renderResults() { if (!layerState.enabled || !layerState.results) return hidePanel(); ensurePanel(); @@ -191,6 +213,7 @@ export function createPanel({ state: layerState, parts }) { kind: 'results', subject: `${subject.label} · ${t('{distance} FLIGHT / VESSEL WINDOW', { distance: presentAwarenessDistance(AWARENESS_RADIUS_M) })}`, subjectNames: presentNames(subject.memberNames), + photo: presentPhoto(subject), navigation: presentNavigation(), rows: cohorts.map(presentRow), note: t( diff --git a/src/layers/awareness/panel.test.mjs b/src/layers/awareness/panel.test.mjs index eaaac70e90..4fa2c448c5 100644 --- a/src/layers/awareness/panel.test.mjs +++ b/src/layers/awareness/panel.test.mjs @@ -1,6 +1,7 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { createPanel } from './panel.js'; +import { createSubject } from './subject.js'; test('a Contacts row names its provider as the Layers panel does, with its feed state', () => { const cohort = (id, source, sourceStatus) => ({ @@ -36,3 +37,119 @@ test('a Contacts row names its provider as the Layers panel does, with its feed ); state.offPanelLocale?.(); }); + +const PHOTO = Object.freeze({ + src: 'https://t.plnspttrs.net/1/abc123_280.jpg', + width: 280, + height: 186, + photographer: 'Jane Doe', + link: 'https://www.planespotters.net/photo/1/n123ab', +}); + +/** The published Contacts view for one subject and the refresh's photo. */ +function photoView(subject, subjectPhoto) { + const state = { + enabled: true, + results: { subject, cohorts: [] }, + subjectPhoto, + cohortPages: new Map(), + panelListeners: new Set(), + panelSignature: '', + navigationIndex: 0, + }; + const parts = { + navigation: { canNavigateNext: () => false }, + rendering: { hideDirectionOverlay() {} }, + }; + createPanel({ state, parts }).renderResults(); + state.offPanelLocale?.(); + return state.panelView; +} + +const FLIGHT = Object.freeze({ + layerId: 'flights', + id: 'abc123', + label: 'N123AB', +}); + +test('the Contacts view carries the tracked flight’s photo with its credit', () => { + const view = photoView(FLIGHT, { + layerId: 'flights', + id: 'abc123', + photo: PHOTO, + }); + assert.deepEqual(view.photo, { + src: PHOTO.src, + width: 280, + height: 186, + link: PHOTO.link, + credit: 'Photo © Jane Doe', + }); +}); + +test('the Contacts view has no photo without one, or with another subject’s', () => { + assert.equal(photoView(FLIGHT, null).photo, null); + assert.equal( + photoView(FLIGHT, { layerId: 'flights', id: 'def456', photo: PHOTO }).photo, + null, + ); + assert.equal( + photoView( + { layerId: 'ais-live-vessels', id: 'abc123', label: 'VESSEL' }, + { layerId: 'flights', id: 'abc123', photo: PHOTO }, + ).photo, + null, + ); +}); + +test('only the tracked flight has a photo: not a vessel, an installation, a military aircraft or another flight', () => { + const tracked = { + layerId: 'flights', + id: 'abc123', + label: 'N123AB', + photo: PHOTO, + }; + let current = tracked; + let lookups = 0; + const flights = { + getTrackedSubject: () => { + lookups += 1; + return current; + }, + }; + const military = { + getTrackedSubject: () => ({ ...tracked, layerId: 'military' }), + }; + const { resolveSubjectPhoto } = createSubject({ + state: {}, + services: { flights, military, vessels: {}, installations: {} }, + parts: { + navigation: { + isFlightLayer: (id) => id === 'flights' || id === 'military', + }, + }, + }); + assert.deepEqual( + resolveSubjectPhoto({ layerId: 'flights', id: 'abc123' }), + PHOTO, + ); + assert.equal(lookups, 1); + assert.equal(resolveSubjectPhoto({ layerId: 'flights', id: 'def456' }), null); + assert.equal( + resolveSubjectPhoto({ layerId: 'ais-live-vessels', id: 'abc123' }), + null, + ); + assert.equal( + resolveSubjectPhoto({ layerId: 'military-installations', id: 'abc123' }), + null, + ); + assert.equal( + resolveSubjectPhoto({ layerId: 'military', id: 'abc123' }), + null, + ); + assert.equal(resolveSubjectPhoto(null), null); + current = null; + assert.equal(resolveSubjectPhoto({ layerId: 'flights', id: 'abc123' }), null); + current = { ...tracked, photo: null }; + assert.equal(resolveSubjectPhoto({ layerId: 'flights', id: 'abc123' }), null); +}); diff --git a/src/layers/awareness/state.js b/src/layers/awareness/state.js index adc8969436..d950e7a84b 100644 --- a/src/layers/awareness/state.js +++ b/src/layers/awareness/state.js @@ -29,6 +29,8 @@ export function createState({ services }) { /** Stops following the manager's adoptions (see watchAdoptions). */ unwatchAdoptions: null, subject: null, + /** The tracked flight's photo with the subject it belongs to, or null. */ + subjectPhoto: null, results: null, visual: null, /** Whether layer views replace the panel's initial markup yet. */ diff --git a/src/layers/awareness/subject.js b/src/layers/awareness/subject.js index 60f622e297..050d144c27 100644 --- a/src/layers/awareness/subject.js +++ b/src/layers/awareness/subject.js @@ -378,19 +378,48 @@ export function createSubject({ state: layerState, services, parts, source }) { * * Identity (`subject.id`) is NEVER re-derived — only the rendered string. * @param {{layerId: string, id: string, label: string}} subject Current subject. + * @param {?object} [tracked] The subject's tracked descriptor, when the + * caller already has it (see trackedSubjectOf). * @returns {string} The current label, or the cached one when the owning layer * has no tracked subject (e.g. a cross-layer handoff is in flight). */ - function resolveSubjectLabel(subject) { - if (!parts.navigation.isFlightLayer(subject?.layerId)) - return subject?.label; + function resolveSubjectLabel(subject, tracked = trackedSubjectOf(subject)) { + return tracked?.label || subject?.label; + } + + /** + * The owning flight layer's tracked-subject descriptor when it describes + * this subject, else null. Built once per refresh and shared by the label + * and the photo. + * @param {{layerId: string, id: string}|null} subject Current subject. + * @returns {?{id: string, label: string, photo?: ?object}} + */ + function trackedSubjectOf(subject) { + if (!parts.navigation.isFlightLayer(subject?.layerId)) return null; const layer = subject.layerId === 'flights' ? flightsLayer : militaryFlightsLayer; const tracked = layer.getTrackedSubject?.(); - if (tracked?.label && String(tracked.id) === String(subject.id)) - return tracked.label; - return subject.label; + return tracked && String(tracked.id) === String(subject.id) + ? tracked + : null; + } + + /** + * The tracked airliner's Planespotters photo, for the Contacts panel. + * + * Only the flights layer looks photos up, and only for the plane it tracks; + * a vessel, an installation, a military aircraft or an untracked flight has + * none. + * @param {{layerId: string, id: string}|null} subject Current subject. + * @param {?object} [tracked] The subject's tracked descriptor, when the + * caller already has it. + * @returns {?{src: string, width: ?number, height: ?number, photographer: string, link: string}} + */ + function resolveSubjectPhoto(subject, tracked = trackedSubjectOf(subject)) { + return subject?.layerId === 'flights' && tracked?.photo + ? tracked.photo + : null; } /** Refresh proximity counts/distances against the subject's current live position. */ @@ -417,8 +446,21 @@ export function createSubject({ state: layerState, services, parts, source }) { if (presence === SUBJECT_PRESENCE.LIVE) layerState.subjectMissing = false; else if (presence === SUBJECT_PRESENCE.MISSING) layerState.subjectMissing = true; - const nextLabel = resolveSubjectLabel(layerState.subject); + const tracked = trackedSubjectOf(layerState.subject); + const nextLabel = resolveSubjectLabel(layerState.subject, tracked); const labelChanged = nextLabel !== layerState.subject.label; + // The panel reads the photo from here, with the subject it belongs to. + const photo = resolveSubjectPhoto(layerState.subject, tracked); + layerState.subjectPhoto = photo + ? { + layerId: layerState.subject.layerId, + id: layerState.subject.id, + photo, + } + : null; + // A photo arriving after selection is render-worthy on its own, as a label. + const photoChanged = + (photo?.src ?? null) !== (layerState.panelView?.photo?.src ?? null); layerState.subject = { ...layerState.subject, position, label: nextLabel }; const movementM = layerState.lastEvaluatedPosition ? Cesium.Cartesian3.distance(layerState.lastEvaluatedPosition, position) @@ -439,7 +481,7 @@ export function createSubject({ state: layerState, services, parts, source }) { // kept the ICAO hex until unrelated movement, a source-revision bump, or // page rotation happened to repaint it. Gated on an ACTUAL change so the // common no-op refresh (every 750 ms) still costs no repaint. - if (labelChanged) parts.panel.renderResults(); + if (labelChanged || photoChanged) parts.panel.renderResults(); parts.rendering.scheduleDirectionOverlayUpdate(force); return; } @@ -502,6 +544,7 @@ export function createSubject({ state: layerState, services, parts, source }) { militaryInstallationsLayer.setContextAnchor?.(null); layerState.autoFocusRetryPending = false; layerState.subject = null; + layerState.subjectPhoto = null; layerState.subjectMissing = false; layerState.results = null; layerState.navigationHistory = []; @@ -528,6 +571,7 @@ export function createSubject({ state: layerState, services, parts, source }) { resolveSubjectPosition, collectionSubjectPosition, resolveSubjectLabel, + resolveSubjectPhoto, refreshSelectedSubject, subjectFromContext, markSubjectEvicted, diff --git a/src/layers/flights/enrichment.js b/src/layers/flights/enrichment.js index aaf8ceb38d..1132c36c86 100644 --- a/src/layers/flights/enrichment.js +++ b/src/layers/flights/enrichment.js @@ -1,5 +1,6 @@ import { classifyAircraft } from '../../data/aircraftClass.js'; import { horizonOccluder } from '../../data/iconOrientation.js'; +import { parsePlanespottersPhoto } from '../../data/planespottersPhoto.js'; import * as Cesium from 'cesium'; import { ENRICH_MAX_INFLIGHT, @@ -8,6 +9,7 @@ import { ENRICH_AMBIENT_REFILL_TOKENS, ENRICH_AMBIENT_REFILL_WINDOW_MS, ENRICH_AMBIENT_PER_SWEEP, + ENRICH_RETRY_COOLDOWN_MS, } from './policy.js'; export function createEnrichment({ @@ -17,11 +19,62 @@ export function createEnrichment({ layer, resolveAsset, }) { - function _enqueueEnrich(key, query, onData, priority = false) { + const { isMilitaryIcao } = services.militaryRegistry; + const { isTr3b } = services.aircraftPresentation; + /** + * Whether `key` is answered, queued, or cooling down after a failure. A + * key past its cool-down is released here so it can be asked again. + * @param {string} key Lookup key. + * @returns {boolean} + */ + function _enrichHeld(key) { + if (flightState._enrichSeen.has(key)) return true; + const retryAfter = flightState._enrichRetryAfter.get(key); + if (retryAfter === undefined) return false; + if (Date.now() < retryAfter) return true; + flightState._enrichRetryAfter.delete(key); + return false; + } + + /** + * Whether a source failure is permanent: an unsupported lookup, or an HTTP + * 4xx other than 401/403 (an authorization refusal that may clear), 408 + * (timeout) and 429 (rate limited). Anything else, including an error without a + * status, is temporary. + * @param {*} error The rejection, as `LiveSourceError` / `httpError` carry it. + * @returns {boolean} + */ + function _enrichFailureIsFinal(error) { + if (error?.code === 'unsupported') return true; + const status = Number(error?.status); + return ( + Number.isInteger(status) && + status >= 400 && + status < 500 && + status !== 401 && + status !== 403 && + status !== 408 && + status !== 429 + ); + } + + /** + * Ask each key at most once per session, except that a lookup whose source + * failed temporarily (rejected or threw) may be asked again after + * ENRICH_RETRY_COOLDOWN_MS; an answer, found or not, and a permanent + * refusal (see _enrichFailureIsFinal) are final. + * @param {string} key Session-unique lookup key. + * @param {object} query The source's enrichment query. + * @param {function(object):void} onData Receives a `found` answer. + * @param {boolean} [priority] Front of the queue. + * @param {function(*):?object} [read] Reads the source's answer first, for + * a lookup whose answer may arrive in more than one shape. + */ + function _enqueueEnrich(key, query, onData, priority = false, read = null) { if (flightState.lifetime.signal.aborted) return; - if (flightState._enrichSeen.has(key)) return; + if (_enrichHeld(key)) return; flightState._enrichSeen.add(key); - const job = { query, onData }; + const job = { key, query, onData, read }; // Priority (tracked / model-eligible) goes to the FRONT so a deep ambient // backlog can never delay the plane the user just clicked or zoomed into. if (priority) flightState._enrichQueue.unshift(job); @@ -61,9 +114,24 @@ export function createEnrichment({ signal: lifetime.signal, }); }) - .then((data) => { - if (!lifetime.signal.aborted && data && data.found) job.onData(data); - }) + .then( + (answer) => { + const data = job.read ? job.read(answer) : answer; + if (!lifetime.signal.aborted && data && data.found) + job.onData(data); + }, + (error) => { + // The source failed: release the key after a cool-down. A layer + // teardown is not a failure and schedules nothing, and a + // permanent refusal is as final as an answer. + if (lifetime.signal.aborted || _enrichFailureIsFinal(error)) return; + flightState._enrichSeen.delete(job.key); + flightState._enrichRetryAfter.set( + job.key, + Date.now() + ENRICH_RETRY_COOLDOWN_MS, + ); + }, + ) .catch(() => { /* enrichment never surfaces errors */ }) @@ -119,6 +187,14 @@ export function createEnrichment({ (data) => { const meta = flightState.records.data.get(icao24); if (!meta) return; + // A late answer for a callsign the plane no longer flies is dropped. + if ( + String(meta.callsign || '') + .trim() + .toUpperCase() !== cs + ) + return; + meta.routeCallsign = cs; meta.airline = data.airline || meta.airline; if (data.origin && data.destination) meta.route = { origin: data.origin, destination: data.destination }; @@ -129,6 +205,31 @@ export function createEnrichment({ ); // route lookups only fire for the TRACKED plane — front of the queue } + /** The tracked plane's photo from Planespotters, asked once per hex at the + * front of the queue like its route. A miss is final; a temporary failure + * is asked again after the cool-down. A military aircraft or a converted + * TR-3B is never looked up. The answer is read with + * `parsePlanespottersPhoto` whatever shape the source returns (the upstream + * answer, a server's cached shape, or an already-read photo), so only a + * checked photo is ever stored. */ + function _requestPhotoEnrichment(icao24) { + if (!/^[0-9a-f]{6}$/i.test(icao24)) return; + const id = icao24.toLowerCase(); + if (isMilitaryIcao(id) || isTr3b(id)) return; + _enqueueEnrich( + `p:${id}`, + { kind: 'photo', id }, + (data) => { + const meta = flightState.records.data.get(id); + if (!meta) return; // evicted while the lookup was in flight + const { src, width, height, photographer, link } = data; + meta.photo = { src, width, height, photographer, link }; + }, + true, + parsePlanespottersPhoto, + ); + } + /** QA seam: headless harnesses (scripts/qa-enrich-ambient.mjs) shrink the * bucket knobs via window.__GEV_ENRICH_AMBIENT_QA = {ceil, refillTokens, * windowMs} — they cannot wait out a real 5-minute window. Read lazily each @@ -196,7 +297,9 @@ export function createEnrichment({ ); const cand = []; for (const [icao24, bb] of flightState._billboards) { - if (flightState._enrichSeen.has(`t:${icao24}`)) continue; // answered / queued / negative this session + // Answered, queued, negative this session, or cooling down after a + // failure: never spend a token on it. + if (_enrichHeld(`t:${icao24}`)) continue; if (!/^[0-9a-f]{6}$/i.test(icao24)) continue; // adsbdb keys are 6-char hex only if (flightState.records.data.get(icao24)?.onGround) continue; // ground traffic never spends ambient budget (click-to-enrich still works) if (!bb.position || !occluder.isPointVisible(bb.position)) continue; // beyond the limb @@ -233,6 +336,7 @@ export function createEnrichment({ _drainEnrich, _requestTypeEnrichment, _requestRouteEnrichment, + _requestPhotoEnrichment, _ambientBudgetKnobs, _refillAmbientBudget, _sweepAmbientEnrichment, diff --git a/src/layers/flights/lifecycle.js b/src/layers/flights/lifecycle.js index 0ca9446472..87e3e356a5 100644 --- a/src/layers/flights/lifecycle.js +++ b/src/layers/flights/lifecycle.js @@ -312,6 +312,7 @@ export function createLifecycle({ flightState._displayFloorState.clear(); flightState._enrichQueue.length = 0; flightState._enrichSeen.clear(); + flightState._enrichRetryAfter.clear(); if (flightState._enrichDripTimer) { clearTimeout(flightState._enrichDripTimer); flightState._enrichDripTimer = null; diff --git a/src/layers/flights/ownership.test.mjs b/src/layers/flights/ownership.test.mjs index 16c1a9cc6f..9b0c1a6065 100644 --- a/src/layers/flights/ownership.test.mjs +++ b/src/layers/flights/ownership.test.mjs @@ -4,6 +4,7 @@ import { createCivilFlightLayer } from './index.js'; import { createFlightState } from './state.js'; import { createEnrichment } from './enrichment.js'; import { createTracking } from './tracking.js'; +import { LiveSourceError } from '../../sources/live/contract.js'; function services() { const names = [ @@ -29,6 +30,14 @@ function services() { }; } +/** The services enrichment reads: which hexes are military or a TR-3B. */ +function enrichServices({ military = [], tr3b = [] } = {}) { + return { + militaryRegistry: { isMilitaryIcao: (id) => military.includes(id) }, + aircraftPresentation: { isTr3b: (id) => tr3b.includes(id) }, + }; +} + test('constructing independent flight layers performs no source request and isolates selection', () => { let requests = 0; const source = { @@ -90,7 +99,11 @@ test('aborted enrichment cannot write into a later lifecycle or decrement its ac }, }; const flightState = createFlightState({ source, services: services() }); - const enrichment = createEnrichment({ flightState, services: {}, parts: {} }); + const enrichment = createEnrichment({ + flightState, + services: enrichServices(), + parts: {}, + }); let writes = 0; enrichment._enqueueEnrich( 'test', @@ -118,7 +131,11 @@ test('a synchronous enrichment failure stays bounded and releases its slot', asy }, }, }); - const enrichment = createEnrichment({ flightState, services: {}, parts: {} }); + const enrichment = createEnrichment({ + flightState, + services: enrichServices(), + parts: {}, + }); assert.doesNotThrow(() => enrichment._enqueueEnrich('test', {}, () => assert.fail()), ); @@ -146,3 +163,336 @@ test('voice context reads a track that rounds to north as 0°, not 360°', () => '0°', ); }); + +test('the tracked plane’s photo is asked once per hex and lands on its record', async () => { + const queries = []; + let answer = { + found: true, + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_280.jpg', + width: 420, + height: 280, + photographer: 'Jan Seler', + link: 'https://www.planespotters.net/photo/1745410/x?utm_source=api', + }; + const flightState = createFlightState({ + services: services(), + source: { + async getEnrichment(query) { + queries.push(query); + if (answer instanceof Error) throw answer; + return answer; + }, + }, + }); + const enrichment = createEnrichment({ + flightState, + services: enrichServices(), + parts: {}, + }); + flightState.records.data.set('a0f1bb', { callsign: 'AAL1' }); + flightState._trackedIcao = 'a0f1bb'; + flightState._trackedEntity = {}; + enrichment._requestPhotoEnrichment('A0F1BB'); + enrichment._requestPhotoEnrichment('a0f1bb'); + await new Promise((done) => setImmediate(done)); + assert.deepEqual(queries, [{ kind: 'photo', id: 'a0f1bb' }]); + assert.deepEqual(flightState.records.data.get('a0f1bb').photo, { + src: answer.src, + width: 420, + height: 280, + photographer: 'Jan Seler', + link: answer.link, + }); + + // A failure is not asked again within its cool-down. + answer = new Error('outage'); + flightState.records.data.set('abc123', {}); + enrichment._requestPhotoEnrichment('abc123'); + await new Promise((done) => setTimeout(done, 300)); + enrichment._requestPhotoEnrichment('abc123'); + await new Promise((done) => setImmediate(done)); + assert.equal(queries.length, 2); + assert.equal(flightState.records.data.get('abc123').photo, undefined); + enrichment._requestPhotoEnrichment('not-hex'); + assert.equal(queries.length, 2); + flightState.lifetime.abort(); +}); + +test('a military aircraft or a converted TR-3B is never looked up for a photo', async () => { + const queries = []; + const flightState = createFlightState({ + services: services(), + source: { + async getEnrichment(query) { + queries.push(query); + return { found: false }; + }, + }, + }); + const enrichment = createEnrichment({ + flightState, + services: enrichServices({ military: ['ae1234'], tr3b: ['a0f1bb'] }), + parts: {}, + }); + for (const id of ['ae1234', 'a0f1bb']) { + flightState.records.data.set(id, {}); + enrichment._requestPhotoEnrichment(id); + } + enrichment._requestPhotoEnrichment('AE1234'); + await new Promise((done) => setImmediate(done)); + assert.deepEqual(queries, []); + assert.equal(flightState._enrichSeen.size, 0); + flightState.lifetime.abort(); +}); + +test('a photo answer in the upstream shape or a server’s cached shape lands checked', async () => { + const SRC = 'https://t.plnspttrs.net/33043/1745410_822dfe330c_280.jpg'; + const LINK = 'https://www.planespotters.net/photo/1745410/x?utm_source=api'; + const answers = { + a0f1bb: { + photos: [ + { + thumbnail_large: { src: SRC, size: { width: 420, height: 280 } }, + link: LINK, + photographer: 'Jan Seler', + }, + ], + }, + abc123: { + found: true, + thumbnail: { src: SRC, width: 420, height: 280 }, + photographer: 'Jan Seler', + link: LINK, + }, + def456: { + found: true, + thumbnail: { src: 'https://evil.example/a.jpg', width: 1, height: 1 }, + photographer: 'Jan Seler', + link: LINK, + }, + fed789: { photos: [] }, + }; + const flightState = createFlightState({ + services: services(), + source: { getEnrichment: async ({ id }) => answers[id] }, + }); + const enrichment = createEnrichment({ + flightState, + services: enrichServices(), + parts: {}, + }); + const ids = Object.keys(answers); + for (const id of ids) flightState.records.data.set(id, {}); + for (const id of ids) { + enrichment._requestPhotoEnrichment(id); + // One dispatch per drip gap. + await new Promise((done) => setTimeout(done, 250)); + } + const photo = { + src: SRC, + width: 420, + height: 280, + photographer: 'Jan Seler', + link: LINK, + }; + assert.deepEqual(flightState.records.data.get('a0f1bb').photo, photo); + assert.deepEqual(flightState.records.data.get('abc123').photo, photo); + assert.equal(flightState.records.data.get('def456').photo, undefined); + assert.equal(flightState.records.data.get('fed789').photo, undefined); + flightState.lifetime.abort(); +}); + +/** An enrichment queue over `answer(query)` with a hand-driven clock. */ +function enrichmentClock(t, answer) { + let now = 1_000_000; + t.mock.method(Date, 'now', () => now); + const queries = []; + const flightState = createFlightState({ + services: services(), + source: { + getEnrichment(query) { + queries.push(query.id); + return answer(query); + }, + }, + }); + const enrichment = createEnrichment({ + flightState, + services: enrichServices(), + parts: { tracking: { _updateTrackedLabelModel() {} } }, + }); + const settle = () => new Promise((done) => setImmediate(done)); + const advance = (ms) => { + now += ms; + }; + return { flightState, enrichment, queries, settle, advance }; +} + +test('a failed lookup is asked again only after its cool-down', async (t) => { + let fail = true; + const { flightState, enrichment, queries, settle, advance } = enrichmentClock( + t, + async () => { + if (fail) throw new Error('503'); + return { found: true, typeCode: 'A321' }; + }, + ); + flightState.records.data.set('a0f1bb', {}); + enrichment._requestTypeEnrichment('a0f1bb'); + await settle(); + assert.deepEqual(queries, ['a0f1bb']); + advance(59_000); + enrichment._requestTypeEnrichment('a0f1bb'); + await settle(); + assert.deepEqual(queries, ['a0f1bb'], 'not within the cool-down'); + fail = false; + advance(1_000); + enrichment._requestTypeEnrichment('a0f1bb'); + await settle(); + assert.deepEqual(queries, ['a0f1bb', 'a0f1bb'], 'asked again after it'); + assert.equal(flightState.records.data.get('a0f1bb').typeCode, 'A321'); + advance(120_000); + enrichment._requestTypeEnrichment('a0f1bb'); + await settle(); + assert.equal(queries.length, 2, 'an answer is final'); + assert.equal(flightState._enrichActive, 0); + flightState.lifetime.abort(); +}); + +test('a synchronous source failure cools down like a rejected one', async (t) => { + const { flightState, enrichment, queries, settle, advance } = enrichmentClock( + t, + () => { + throw new Error('boom'); + }, + ); + enrichment._requestPhotoEnrichment('a0f1bb'); + await settle(); + advance(60_000); + enrichment._requestPhotoEnrichment('a0f1bb'); + await settle(); + assert.deepEqual(queries, ['a0f1bb', 'a0f1bb']); + flightState.lifetime.abort(); +}); + +test('a "not found" answer is never asked again', async (t) => { + const { flightState, enrichment, queries, settle, advance } = enrichmentClock( + t, + async ({ kind }) => (kind === 'photo' ? { photos: [] } : { found: false }), + ); + enrichment._requestTypeEnrichment('a0f1bb'); + await settle(); + advance(1_000); // past the dispatch drip + enrichment._requestPhotoEnrichment('a0f1bb'); + await settle(); + assert.equal(queries.length, 2); + advance(3_600_000); + enrichment._requestTypeEnrichment('a0f1bb'); + enrichment._requestPhotoEnrichment('a0f1bb'); + await settle(); + assert.equal(queries.length, 2); + assert.equal(flightState._enrichRetryAfter.size, 0); + flightState.lifetime.abort(); +}); + +test('a lookup cut off by the layer’s teardown schedules no retry', async (t) => { + let release; + const { flightState, enrichment, settle } = enrichmentClock( + t, + (query) => + new Promise((_resolve, reject) => { + release = () => reject(new DOMException('aborted', 'AbortError')); + }), + ); + enrichment._requestTypeEnrichment('a0f1bb'); + await settle(); + flightState.lifetime.abort(); + release(); + await settle(); + assert.equal(flightState._enrichRetryAfter.size, 0); + assert.equal(flightState._enrichSeen.has('t:a0f1bb'), true); +}); + +test('a permanent refusal is final; a timeout, rate limit, outage or authorization refusal cools down', async (t) => { + const errors = { + aaaaa1: new LiveSourceError('denied', 'adsbdb HTTP 404', { status: 404 }), + aaaaa2: new LiveSourceError('unsupported', 'Enrichment unavailable'), + aaaaa3: new LiveSourceError('limited', 'adsbdb rate limited', { + status: 429, + }), + aaaaa4: new LiveSourceError('unavailable', 'adsbdb HTTP 503', { + status: 503, + }), + aaaaa5: new LiveSourceError('unavailable', 'adsbdb HTTP 408', { + status: 408, + }), + aaaaa6: new Error('network'), + aaaaa7: new LiveSourceError('denied', 'Unauthorized', { status: 401 }), + aaaaa8: new LiveSourceError('denied', 'Forbidden', { status: 403 }), + }; + const { flightState, enrichment, queries, settle, advance } = enrichmentClock( + t, + async ({ id }) => { + throw errors[id]; + }, + ); + const ids = Object.keys(errors); + for (const id of ids) { + enrichment._requestTypeEnrichment(id); + await settle(); + advance(1_000); // past the dispatch drip + } + assert.deepEqual(queries, ids); + advance(60_000); + for (const id of ids) { + enrichment._requestTypeEnrichment(id); + await settle(); + advance(1_000); + } + assert.deepEqual( + queries.slice(ids.length), + ['aaaaa3', 'aaaaa4', 'aaaaa5', 'aaaaa6', 'aaaaa7', 'aaaaa8'], + 'a 404 and an unsupported lookup are never asked again', + ); + assert.equal(flightState._enrichSeen.has('t:aaaaa1'), true); + assert.equal(flightState._enrichRetryAfter.has('t:aaaaa1'), false); + flightState.lifetime.abort(); +}); + +test('a route answer for a callsign the plane no longer flies is dropped', async (t) => { + const pending = []; + const { flightState, enrichment, settle, advance } = enrichmentClock( + t, + (query) => new Promise((resolve) => pending.push({ query, resolve })), + ); + const meta = { callsign: 'UAL9' }; + flightState.records.data.set('a0f1bb', meta); + enrichment._requestRouteEnrichment('a0f1bb'); + await settle(); + meta.callsign = 'UAL10'; // the next poll's callsign + advance(1_000); + enrichment._requestRouteEnrichment('a0f1bb'); + await settle(); + assert.deepEqual( + pending.map(({ query }) => query.id), + ['UAL9', 'UAL10'], + ); + const route = (code) => ({ + found: true, + airline: `${code} Air`, + origin: { code: `${code}O` }, + destination: { code: `${code}D` }, + }); + pending[0].resolve(route('OLD')); + await settle(); + assert.equal(meta.route, undefined, 'the late UAL9 answer is ignored'); + assert.equal(meta.airline, undefined); + pending[1].resolve(route('NEW')); + await settle(); + assert.deepEqual(meta.route, { + origin: { code: 'NEWO' }, + destination: { code: 'NEWD' }, + }); + assert.equal(meta.routeCallsign, 'UAL10'); + flightState.lifetime.abort(); +}); diff --git a/src/layers/flights/policy.js b/src/layers/flights/policy.js index 9f0e810bd9..de44b806a8 100644 --- a/src/layers/flights/policy.js +++ b/src/layers/flights/policy.js @@ -254,6 +254,11 @@ export const ENRICH_MAX_INFLIGHT = 4; export const ENRICH_DISPATCH_GAP_MS = 200; +/** A lookup whose source failed (an outage, a timeout, a restarting server) may + * be asked again after this long; a real "not found" answer never is. */ + +export const ENRICH_RETRY_COOLDOWN_MS = 60_000; + // --------------------------------------------------------------------------- // Ambient fleet type enrichment (2026-07-02 field data: OpenSky's live // category field is 0/"no info" for ~94% of planes, so ambient classification diff --git a/src/layers/flights/queries.js b/src/layers/flights/queries.js index 89b91f1257..a696238dc1 100644 --- a/src/layers/flights/queries.js +++ b/src/layers/flights/queries.js @@ -24,7 +24,8 @@ export function createQueries({ layer, resolveAsset, }) { - const { tr3bTypeLabel, tr3bAircraftClass } = services.aircraftPresentation; + const { isTr3b, tr3bTypeLabel, tr3bAircraftClass } = + services.aircraftPresentation; const { formatFlightLevel } = services.labels; const { isMilitaryIcao } = services.militaryRegistry; const { applyTrackedCameraFrame } = services.camera; @@ -208,6 +209,12 @@ export function createQueries({ destination: { ...info.route.destination }, } : null, + // The airframe's Planespotters photo for the Context panel; a military + // aircraft or a converted TR-3B (it would name the real one) shows none. + photo: + info?.photo && !isTr3b(icao24) && !isMilitaryIcao(icao24) + ? { ...info.photo } + : null, }; } @@ -875,8 +882,9 @@ export function createQueries({ /** * Describe the currently tracked aircraft at its dead-reckoned position. - * @returns {{icao24: string, callsign: string|null, latitude: number, longitude: number, altitudeM: number, velocityMps: number|null, track: number|null, verticalRateMps: number|null}|null} - * Tracked aircraft info, or null when nothing is tracked. + * @returns {{icao24: string, callsign: string|null, latitude: number, longitude: number, altitudeM: number, velocityMps: number|null, track: number|null, verticalRateMps: number|null, photo: {src: string, width: number|null, height: number|null, photographer: string, link: string}|null}|null} + * Tracked aircraft info, or null when nothing is tracked. `photo` is the + * airframe's credited Planespotters photo, or null. */ getTrackedInfo() { if (!flightState._trackedIcao) return null; @@ -906,6 +914,8 @@ export function createQueries({ _toCleanText(described.registration) || described.icao24, position: Cesium.Cartesian3.clone(described.position), + // The airframe's photo for the Context panel, or null. + photo: described.photo, }; }, diff --git a/src/layers/flights/records.js b/src/layers/flights/records.js index 709cd69ed2..fdd2d67c88 100644 --- a/src/layers/flights/records.js +++ b/src/layers/flights/records.js @@ -198,10 +198,16 @@ export class FlightRecords { !!prevMeta && (prevMeta.onGround === true) !== onGround; // Store flight metadata for click-to-track labels const cat = stickyNumber(category, prevMeta?.category, null); + const nextCallsign = stickyText(callsign, prevMeta?.callsign); + // A route (and its airline) belongs to the callsign it was looked up for; + // a new callsign drops it, so an old flight's route never shows under it. + const routeHeld = + Boolean(prevMeta?.routeCallsign) && + prevMeta.routeCallsign === nextCallsign.toUpperCase(); const meta = { sourceReference: observation.reference, observedReceiptMs: Date.now(), - callsign: stickyText(callsign, prevMeta?.callsign), + callsign: nextCallsign, altitude: alt, // geoAltitudeM/renderAltitudeM are ADDITIVE fields alongside the // untouched aviation `altitude` — never rename/replace it (labels, @@ -256,8 +262,11 @@ export class FlightRecords { typeCode: prevMeta?.typeCode ?? null, typeName: prevMeta?.typeName ?? null, registration: prevMeta?.registration ?? null, - airline: prevMeta?.airline ?? null, - route: prevMeta?.route ?? null, + airline: routeHeld ? (prevMeta.airline ?? null) : null, + route: routeHeld ? (prevMeta.route ?? null) : null, + routeCallsign: routeHeld ? prevMeta.routeCallsign : null, + // Planespotters photo of the tracked airframe (Core asks it directly). + photo: prevMeta?.photo ?? null, // The RAW poll fix lat/lon (this tick's OpenSky state-vector // coords, pre-dead-reckon) — kept distinct from the continuously // dead-reckoned billboard position for any consumer that needs the diff --git a/src/layers/flights/records.test.mjs b/src/layers/flights/records.test.mjs index 638c6f843f..f74574e966 100644 --- a/src/layers/flights/records.test.mjs +++ b/src/layers/flights/records.test.mjs @@ -39,6 +39,7 @@ test('civil records keep aviation units separate from render height and survive assert.equal(first.meta.renderAltitudeM, 1040); assert.equal(first.fixEpochMs, 1700000000000); first.meta.typeCode = 'B738'; + first.meta.photo = { src: 'https://t.plnspttrs.net/1/2_280.jpg' }; const second = store.receive( observation({ callsign: '', @@ -55,6 +56,7 @@ test('civil records keep aviation units separate from render height and survive assert.equal(second.meta.velocity, 120); assert.equal(second.meta.true_track, 90); assert.equal(second.meta.typeCode, 'B738'); + assert.equal(second.meta.photo, first.meta.photo, 'the photo survives polls'); assert.equal(Object.hasOwn(second.meta, 'cullPosition'), false); assert.deepEqual(JSON.parse(JSON.stringify(second.meta)), second.meta); }); @@ -140,3 +142,25 @@ test('civil emergency status follows the latest poll instead of sticking', () => assert.equal(next.meta.squawk, '2000'); assert.equal(next.meta.emergency, null); }); + +test('a route belongs to its callsign: a new callsign drops it, a blank one keeps it', () => { + const store = records(); + store.geoidReady = true; + const first = store.receive(observation({ callsign: 'UAL9' }), view()); + first.meta.route = { origin: { code: 'AUS' }, destination: { code: 'DEN' } }; + first.meta.airline = 'United'; + first.meta.routeCallsign = 'UAL9'; + const same = store.receive(observation({ callsign: 'UAL9 ' }), view()); + assert.equal(same.meta.route, first.meta.route); + const blank = store.receive(observation({ callsign: '' }), view()); + assert.equal( + blank.meta.route, + first.meta.route, + 'a dropped callsign is sticky', + ); + assert.equal(blank.meta.airline, 'United'); + const next = store.receive(observation({ callsign: 'UAL10' }), view()); + assert.equal(next.meta.route, null, 'the old route never shows under UAL10'); + assert.equal(next.meta.airline, null); + assert.equal(next.meta.routeCallsign, null); +}); diff --git a/src/layers/flights/snapshotRenderer.js b/src/layers/flights/snapshotRenderer.js index d48d127741..414e6a0f6e 100644 --- a/src/layers/flights/snapshotRenderer.js +++ b/src/layers/flights/snapshotRenderer.js @@ -230,6 +230,13 @@ export function createFlightSnapshotRenderer({ // (position updates automatically via dead-reckoning CallbackProperty) if (isTracked && flightState._trackedEntity) { tracking._updateTrackedLabelModel(icao24); + // Re-ask the tracked plane's lookups each poll. Answered and queued + // keys return at once; a lookup whose source failed runs again once + // its cool-down has passed, and the route uses the callsign this + // snapshot just recorded. + enrichment._requestTypeEnrichment(icao24, true); + enrichment._requestRouteEnrichment(icao24); + enrichment._requestPhotoEnrichment(icao24); } } diff --git a/src/layers/flights/state.js b/src/layers/flights/state.js index c259c44f16..81b849f4b6 100644 --- a/src/layers/flights/state.js +++ b/src/layers/flights/state.js @@ -342,6 +342,10 @@ export function createFlightState({ source, services }) { flightState._enrichSeen = new Set(); + /** Lookup key -> epoch ms before which a failed lookup is not asked again. */ + + flightState._enrichRetryAfter = new Map(); + flightState._enrichAmbientBudget = ENRICH_AMBIENT_BUDGET_CEIL; /** Epoch ms the bucket last accounted a refill window from (0 = unset). */ diff --git a/src/layers/flights/testing.js b/src/layers/flights/testing.js index ccb109ae1c..60c5de10c9 100644 --- a/src/layers/flights/testing.js +++ b/src/layers/flights/testing.js @@ -190,8 +190,20 @@ export function createTesting({ ); } - /** Exercise the exact asynchronous fleet loader and return its admitted model. */ + /** Forget every enrichment lookup and the dispatch clock, so a test that + * moved `Date.now` leaves no future-dated drip or cool-down behind. */ + function _resetEnrichmentForTest() { + flightState._enrichQueue.length = 0; + flightState._enrichSeen.clear(); + flightState._enrichRetryAfter.clear(); + flightState._enrichLastDispatchMs = 0; + if (flightState._enrichDripTimer) { + clearTimeout(flightState._enrichDripTimer); + flightState._enrichDripTimer = null; + } + } + /** Exercise the exact asynchronous fleet loader and return its admitted model. */ async function _ensureFleetModelForTest(icao24) { await parts.rendering._ensureModel(icao24); return flightState._models.get(icao24) || null; @@ -212,5 +224,6 @@ export function createTesting({ _trackedBillboardColorForTest, _driveFleetModelHandoffForTest, _ensureFleetModelForTest, + _resetEnrichmentForTest, }; } diff --git a/src/layers/flights/tracking.js b/src/layers/flights/tracking.js index f81249e885..9fbde6a3fe 100644 --- a/src/layers/flights/tracking.js +++ b/src/layers/flights/tracking.js @@ -1060,6 +1060,7 @@ export function createTracking({ // starts one. parts.enrichment._requestTypeEnrichment(icao24, true); // tracked plane — front of the enrichment queue parts.enrichment._requestRouteEnrichment(icao24); + parts.enrichment._requestPhotoEnrichment(icao24); // Round 2 (owner): grounded contacts get trails too — a landed-but-taxiing // aircraft's history is retrievable on select. Grounded flights positions // are already surface-clamped (the surfaceM chain), so seeds/appends drape. diff --git a/src/sources/live/contract.test.mjs b/src/sources/live/contract.test.mjs index f42a00ec35..416b42a374 100644 --- a/src/sources/live/contract.test.mjs +++ b/src/sources/live/contract.test.mjs @@ -412,3 +412,77 @@ test('squawks are validated and omitted OpenSky status differs from an explicit assert.equal(quiet.squawk, null); assert.equal(quiet.emergency, null); }); + +test('a photo enrichment asks Planespotters directly and returns the checked photo', async () => { + const requests = []; + const source = createFlightSource({ + fetchImpl: async (url, init) => { + requests.push({ url, init }); + return response({ + photos: [ + { + thumbnail_large: { + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_280.jpg', + size: { width: 420, height: 280 }, + }, + link: 'https://www.planespotters.net/photo/1745410/x?utm_source=api', + photographer: 'Jan Seler', + }, + ], + }); + }, + }); + const signal = new AbortController().signal; + const photo = await source.getEnrichment( + { kind: 'photo', id: 'a0f1bb' }, + { signal }, + ); + assert.equal( + requests[0].url, + 'https://api.planespotters.net/pub/photos/hex/a0f1bb', + ); + assert.ok(requests[0].init.signal, 'the request is cancellable'); + assert.equal(requests[0].init.credentials, 'omit'); + assert.deepEqual(photo, { + found: true, + src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_280.jpg', + width: 420, + height: 280, + photographer: 'Jan Seler', + link: 'https://www.planespotters.net/photo/1745410/x?utm_source=api', + }); +}); + +test('a photo enrichment reads an empty answer as no photo and refuses a bad hex', async () => { + let calls = 0; + const source = createFlightSource({ + fetchImpl: async (_url, _init) => { + calls++; + return response({ photos: [] }); + }, + }); + assert.deepEqual( + await source.getEnrichment({ kind: 'photo', id: 'a0f1bb' }), + { found: false }, + ); + await assert.rejects(source.getEnrichment({ kind: 'photo', id: '../x' }), { + code: 'unsupported', + }); + assert.equal(calls, 1); +}); + +test('a photo enrichment outage rejects without echoing the body', async () => { + for (const status of [403, 429, 502]) { + const source = createFlightSource({ + fetchImpl: async () => response({ error: 'sensitive' }, {}, status), + }); + await assert.rejects( + source.getEnrichment({ kind: 'photo', id: 'a0f1bb' }), + (error) => { + assert.equal(error.status, status); + assert.equal(error.message.includes('sensitive'), false); + return true; + }, + ); + } +}); diff --git a/src/sources/live/standalone.js b/src/sources/live/standalone.js index d76ecf3fa3..b244266b08 100644 --- a/src/sources/live/standalone.js +++ b/src/sources/live/standalone.js @@ -11,10 +11,37 @@ import { readsbIdentities, } from './aircraft.js'; import { normalizeVesselTrack, vesselSnapshot } from './vessels.js'; +import { parsePlanespottersPhoto } from '../../data/planespottersPhoto.js'; const defaultFetch = (...args) => globalThis.fetch(...args); const header = (response, name) => response.headers?.get?.(name); +/** Planespotters' public photo lookup, called straight from the browser (it + * answers with `access-control-allow-origin: *`). */ +const PLANESPOTTERS_PHOTOS = 'https://api.planespotters.net/pub/photos/hex/'; +/** A photo is decoration: a slow answer gives up rather than hold an + * enrichment slot. */ +const PHOTO_TIMEOUT_MS = 8000; + +/** The tracked plane's Planespotters photo, read and host-checked. */ +async function planespottersPhoto(fetchImpl, hex, signal) { + const id = String(hex || '').toLowerCase(); + if (!/^[0-9a-f]{6}$/.test(id)) + throw new LiveSourceError('unsupported', 'Enrichment unavailable'); + const timeout = AbortSignal.timeout(PHOTO_TIMEOUT_MS); + const { response, payload } = await readResponse( + fetchImpl, + PLANESPOTTERS_PHOTOS + id, + { + signal: signal ? AbortSignal.any([signal, timeout]) : timeout, + credentials: 'omit', + }, + 'Planespotters', + ); + if (!response.ok) throw httpError(response, 'Planespotters'); + return parsePlanespottersPhoto(payload); +} + function openSkyError(response) { const error = httpError(response, 'Flights'); const mode = String( @@ -106,6 +133,8 @@ export function createFlightSource({ }; }, async getEnrichment(query, { signal } = {}) { + if (query.kind === 'photo') + return planespottersPhoto(fetchImpl, query.id, signal); if (!['type', 'route'].includes(query.kind)) throw new LiveSourceError('unsupported', 'Enrichment unavailable'); const { response, payload } = await readResponse( diff --git a/src/ui/awarenessPanel.test.mjs b/src/ui/awarenessPanel.test.mjs index 101711c661..53cf0ad94b 100644 --- a/src/ui/awarenessPanel.test.mjs +++ b/src/ui/awarenessPanel.test.mjs @@ -245,3 +245,73 @@ test('a repaint that leaves focus outside the panel does not pull it back', asyn 'an empty cohort renders no list', ); }); + +const photo = (extra = {}) => ({ + src: 'https://t.plnspttrs.net/1/abc123_280.jpg', + width: 280, + height: 186, + link: 'https://www.planespotters.net/photo/1/n123ab', + credit: 'Photo © Jane Doe', + ...extra, +}); + +test('a tracked flight’s photo shows under its name, credited and linked to its page', async (t) => { + const { panel, publish } = fixture(t); + await publish({ ...results(), photo: photo() }); + const root = panel(); + const link = root.querySelector('a.military-awareness-photo'); + assert.ok(link, 'the photo renders'); + assert.equal( + root.querySelector('.military-awareness-subject').nextElementSibling, + link, + 'directly under the subject line', + ); + assert.equal(link.getAttribute('href'), photo().link); + assert.equal(link.getAttribute('target'), '_blank'); + assert.equal(link.getAttribute('rel'), 'noopener'); + const img = link.querySelector('img'); + assert.equal(img.getAttribute('src'), photo().src); + assert.equal(img.getAttribute('alt'), ''); + assert.equal(img.getAttribute('width'), '280'); + assert.equal(img.getAttribute('height'), '186'); + assert.equal(link.querySelector('small').textContent, 'Photo © Jane Doe'); +}); + +test('no photo renders without one', async (t) => { + const { panel, publish } = fixture(t); + await publish({ ...results(), photo: null }); + assert.equal(panel().querySelector('.military-awareness-photo'), null); +}); + +test('a photo whose image fails to load is hidden until another arrives', async (t) => { + const { panel, publish } = fixture(t); + await publish({ ...results(), photo: photo() }); + panel() + .querySelector('.military-awareness-photo img') + .dispatchEvent(new Event('error')); + await nextTick(); + assert.equal(panel().querySelector('.military-awareness-photo'), null); + // A repaint with the same photo keeps it hidden. + await publish({ ...results({ previousDisabled: false }), photo: photo() }); + assert.equal(panel().querySelector('.military-awareness-photo'), null); + // Another plane's photo shows. + const next = photo({ src: 'https://t.plnspttrs.net/2/def456_280.jpg' }); + await publish({ ...results(), photo: next }); + assert.equal( + panel().querySelector('.military-awareness-photo img').getAttribute('src'), + next.src, + ); +}); + +test('a late error from a previous photo’s image does not hide the current one', async (t) => { + const { panel, publish } = fixture(t); + const previous = photo(); + const current = photo({ src: 'https://t.plnspttrs.net/2/def456_280.jpg' }); + await publish({ ...results(), photo: current }); + // The error belongs to the image that failed: here, one still on the old src. + const img = panel().querySelector('.military-awareness-photo img'); + img.setAttribute('src', previous.src); + img.dispatchEvent(new Event('error')); + await nextTick(); + assert.ok(panel().querySelector('.military-awareness-photo')); +}); diff --git a/src/ui/styles/radio.css b/src/ui/styles/radio.css index 91611bf4ad..e9af111f1b 100644 --- a/src/ui/styles/radio.css +++ b/src/ui/styles/radio.css @@ -360,6 +360,31 @@ html:not([lang='en']) .radio-transport button { margin: 0 0 7px; color: #fff; } +.military-awareness-photo { + display: block; + margin: 0 0 8px; + color: #a9b7c7; + text-decoration: none; +} +.military-awareness-photo img { + display: block; + width: 100%; + height: auto; + border: 1px solid rgba(98, 181, 255, 0.34); + border-radius: 4px; +} +.military-awareness-photo small { + display: block; + margin-top: 3px; +} +.military-awareness-photo:hover small, +.military-awareness-photo:focus-visible small { + color: #fff; +} +.military-awareness-photo:focus-visible { + outline: 1px solid rgba(127, 200, 255, 0.85); + outline-offset: 2px; +} .military-awareness-controls { display: grid; grid-template-columns: 1fr 1fr 1fr; diff --git a/src/ui/views/panels/AwarenessPanel.vue b/src/ui/views/panels/AwarenessPanel.vue index cb4fa7f62d..7179cb2513 100644 --- a/src/ui/views/panels/AwarenessPanel.vue +++ b/src/ui/views/panels/AwarenessPanel.vue @@ -11,6 +11,13 @@ import AwarenessNames from './AwarenessNames.vue'; const { awareness: view, awarenessLayer: layer } = storeToRefs(useContextStore()); const user = { origin: 'user' }; const root = ref(null); +// A photo whose image failed to load stays hidden until another one arrives. +// The failing image's own src is recorded, so a late error from a previous +// photo never hides the current one. +const failedPhoto = ref(''); +const fail = (event) => { + failedPhoto.value = event.target.getAttribute('src'); +}; // A live repaint keeps focus on the same control by identity: browsers drop // focus from a node Vue moves, removes or disables, so the control is found @@ -52,6 +59,10 @@ onUpdated(() => {