diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ee00d8392..98d32365f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,26 +1,10 @@
# Changelog
-- Local FM seek finds stations after wrapping around 87.5–108 MHz, covers both
- band edges, skips the starting station and rejects spectra from an earlier
- tune (Aditya, @Rohilalala, #1174).
-- Local RTL-SDR keeps USB reads queued in order and bounds pending decoder
- work. A stalled or overloaded decoder stops with an explicit error; stopping
- terminates its worker and rejects late audio. FM playback buffers short
- scheduling gaps, caps its audio queue at 256 ms, and reduces display updates
- and spectrum calculations while listening.
-
-- Add Bogotá (Tembici, 250 stations) and Santiago de Chile (Bike Itaú, 200
- stations) to the GBFS bikeshare registry, the layer's first stations in
- Colombia and Chile. Both are PBSC feeds like the Brazilian Bike Itaú cities,
- so no proxy change is needed. Both feeds also list depot stations on other
- continents (São Paulo, Madrid) as in service; stations outside a city's load
- radius are now dropped instead of drawn as live docks.
-
-- Add Barcelona's bike share to the GBFS registry: Bicing (543 stations, the
- city's PBSC system) and AMBici (237 e-bike stations across the metropolitan
- area, run by nextbike). Both are keyless GBFS 2.3 feeds listed in
- MobilityData's systems catalogue; AMBici's is CC0. `gbfs.nextbike.net` joins
- the proxy allowlist. These are the layer's first stations in Spain.
+- The tracked-aircraft descriptor now publishes `verticalRateMps`, on both the
+ civil and military layers, so a consumer reading `getTrackedInfo()` no longer
+ has to reach past it into the raw poll record for climb/descent. Reported,
+ never derived: an aircraft that has not transmitted a rate reads as `null`
+ rather than a level-flight `0`.
- Add nine Ontario transit feeds: TTC, MiWay, Hamilton HSR, Durham Region,
YRT/Viva, Guelph, Burlington, Barrie and Kingston, each carrying its own
diff --git a/changelog.d/1135-director-save-status-run-results.md b/changelog.d/1135-director-save-status-run-results.md
new file mode 100644
index 0000000000..aa3c6f0e6a
--- /dev/null
+++ b/changelog.d/1135-director-save-status-run-results.md
@@ -0,0 +1,5 @@
+- Scenes keep the "Scene not saved" status when a capture, update, append or
+ import cannot be saved, and an unreadable saved project no longer overwrites
+ the recovery checkpoint. `startScene()` resolves to its documented result,
+ `afterShotId` works without an explicit scene, and `scenesRun` counts the
+ distinct scenes queued (djabhi31, #1135).
diff --git a/changelog.d/1142-antimeridian-fire-perimeters.md b/changelog.d/1142-antimeridian-fire-perimeters.md
new file mode 100644
index 0000000000..8b847163e1
--- /dev/null
+++ b/changelog.d/1142-antimeridian-fire-perimeters.md
@@ -0,0 +1,6 @@
+- Fire-perimeter queries handle outlines and holes crossing the antimeridian:
+ areas enclosed near ±180° are included, areas at the opposite meridian are
+ excluded, and returned perimeter coordinates stay near the dateline. Incident
+ cards use the same circular longitude mean and compare multipart outline
+ areas along short longitude edges, keeping the card on the largest polygon
+ (Arianna Method, @ariannamethod, #1142).
diff --git a/changelog.d/1172-cctv-missing-numbers.md b/changelog.d/1172-cctv-missing-numbers.md
new file mode 100644
index 0000000000..d401021e91
--- /dev/null
+++ b/changelog.d/1172-cctv-missing-numbers.md
@@ -0,0 +1,13 @@
+- Keep missing CCTV numbers unknown instead of reading them as zero. `Number`
+ turns null, blank strings and booleans into 0 or 1, and the camera source
+ list sends an unknown number as JSON null, so a source-pack camera that left
+ out its pose reached the browser as zeros clamped to each field's floor —
+ facing north, pitch −2°, FOV 20°, range 120 m, mount 6 m and ground 0 m —
+ instead of the defaults (id-hash heading, −17°, 74°, 700 m, 24 m and the
+ city's ground); a null or blank position placed the camera at 0,0. The
+ server's `toFiniteNumber` and the browser's `safeNumber` now treat absent,
+ blank and boolean values as missing. The same conversion also stops a
+ Tallinn row with a null heading reading as a confident north-facing camera,
+ a Caltrans camera with a blank elevation losing its 150 m ground prior, and
+ a TfL or Catalonia camera with a null or blank coordinate being kept at 0,0
+ or on the zero meridian (omerbberk, #1172).
diff --git a/changelog.d/1173-antimeridian-ground-floor.md b/changelog.d/1173-antimeridian-ground-floor.md
new file mode 100644
index 0000000000..939559bb59
--- /dev/null
+++ b/changelog.d/1173-antimeridian-ground-floor.md
@@ -0,0 +1,10 @@
+- Flights' ground floor works across the antimeridian. The viewer-distance
+ check behind the 150 km floor radius and its copy in the photoreal mesh-floor
+ sampler subtracted longitudes without wrapping, so two points 21 km apart
+ across 180° measured about 38,000 km and low or grounded aircraft just across
+ the line from the viewer were never floored. A contact's display corridor
+ walked a segment across 180° the long way round, spending its cell budget on
+ ground behind the contact, and a contact on the seam lost its cell hysteresis.
+ SEARCH NEARBY SITES on a view across 180° searched Google Places around
+ longitude 0, on the far side of the globe, with a radius sized from the view's
+ height alone; it now searches the view (Aditya, @Rohilalala, #1173).
diff --git a/changelog.d/970-recent-imagery-details-scroll.md b/changelog.d/970-recent-imagery-details-scroll.md
new file mode 100644
index 0000000000..761e265c04
--- /dev/null
+++ b/changelog.d/970-recent-imagery-details-scroll.md
@@ -0,0 +1,3 @@
+- Recent Imagery: opening DETAILS scrolls its card into view when it opens below
+ the fold. The panel used to restore the previous scroll position right after
+ the reveal, so the card stayed out of sight (Ian Blenke, #970).
diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md
index 4d1e678d3d..e54668413d 100644
--- a/docs/CURRENT-STATE.md
+++ b/docs/CURRENT-STATE.md
@@ -108,6 +108,18 @@ Catalog calls check their cancellation signal immediately before executing a
tool. Already-cancelled queries do not start; cancellation after execution starts
continues to follow the existing tool and caller behavior.
+Fire-perimeter queries test polygon interiors and holes on continuous unwrapped
+longitudes, matching the short-edge convention used for boundary intersections.
+An outline crossing ±180° contains nearby boxes and radius areas without also
+containing their counterparts near Greenwich. Returned perimeter coordinates
+use a circular mean for longitude, including multipart outlines. Incident cards
+also use a circular longitude mean over the largest outer ring (excluding its
+repeated closing vertex). Their relative-area comparison follows short longitude
+edges so a small dateline-crossing part cannot outweigh a larger ordinary part.
+Regression coverage lives in `src/tools/area.test.mjs`,
+`src/tools/queries/environment.test.mjs` and
+`src/layers/perimeters/cards.test.mjs`.
+
## Cyber HUD — September 30, 2026
Display > HUD > Layout includes Cyber, also available through the HUD voice
@@ -849,6 +861,13 @@ use the supplied asset resolver, including the preload path. Enrichment receives
an abort signal and cannot update a later lifecycle after destruction. Existing
camera, terrain floor, trail, selection and measured model-size policies remain.
+The tracked-aircraft descriptor both flight layers hand to the cockpit carries
+`verticalRateMps` beside `velocityMps` and `track`. Civil records store the rate as
+`verticalRate` and military records as `verticalRateMps`; the query seam maps both to
+one name, so `resolveTrackedAircraftInfo` returns a single shape for either layer. The
+rate is reported, never derived: a blank poll keeps the last transmitted value and an
+absent rate stays null rather than reading as level flight.
+
## Transponder emergency highlighting
`src/data/aircraftEmergency.js` derives one status per poll from the Mode A
@@ -1352,6 +1371,19 @@ Node-only package entries expose both provider factories. Routes, payloads,
fallback behavior and existing dev/preview hook registration are preserved;
browser rendering is unchanged.
+## CCTV missing numeric fields
+
+CCTV numbers are read as missing when they are absent, null, blank or boolean,
+on the server (`toFiniteNumber`, every pack and the file/env source packs) and
+in the browser (`safeNumber`). `/api/cctv/sources` sends an unknown number as
+JSON null; the browser then uses the bundled seed camera's value when one
+shares the id, else the field's default — id-hash heading, pitch −17°, FOV 74°
+(which a matched datasheet can still replace), range 700 m, mount 24 m, the
+city's ground elevation — rather than reading zero and clamping it to the
+field's floor. A camera with a missing latitude or longitude and no seed
+position is skipped by the browser catalog instead of being placed at 0,0.
+Real zeros, including `"0"`, are kept.
+
## Terrain, traffic, fire and bike-share provider modules
Local composition now imports separate Node modules for Re:Earth heights,
@@ -3208,7 +3240,11 @@ test:track` 43 tracking invariants · headless QA harnesses under
> metres low. `qa-floor-verify.mjs` now **exits non-zero on FAIL** (1 = FAIL,
> 2 = INCONCLUSIVE); it previously exited 0 on every verdict, which is how the
> burial stayed invisible. It also honours `QA_BASE_URL` and puppeteer's
-> pinned Chrome-for-Testing, like the other harnesses.
+> pinned Chrome-for-Testing, like the other harnesses. The viewer-distance
+> gate, the corridor walk and cell hysteresis take the short way across 180°
+> (`src/data/approxDistance.js` is the one distance both the flights records
+> and the mesh-floor sampler use), so contacts just across the antimeridian
+> are floored like any other.
> - **2026-07-16:** the FIRMS Active Fires layer is **LIVE** —
> the bundled 2026-05-25 snapshot (58 MB) is deleted; a new `/api/firms` proxy
> (vite.config.js) merges VIIRS NOAA-20/NOAA-21/Suomi-NPP NRT world CSVs
@@ -4236,7 +4272,7 @@ silently demoting every later lookup for the session.
- The internal Context coordinator is available in every visual style. Its dedicated right-side `CONTEXT` chooser exposes the neutral shell; the coordinator is not duplicated in Data Layers and does not enable a live-data dependency until a mode is selected.
- The expanded `CONTEXT` view offers mutually exclusive `CONTACTS` and `SPACE MISSIONS` modes. Selecting `CONTACTS` enables the context-owned Flights, Military Flights, AIS Vessels, and Mapped Installations dependencies only when they are not already user-enabled; selecting `SPACE MISSIONS` enables the recent-launch layer and its Satellite dependency. `CONTACTS` cycles the nearest supported contact of whatever type is selected. Satellites are deliberately excluded from those Awareness cohorts and keep their own tracking UX. Selecting the active mode again returns to the neutral chooser and releases only mode-owned dependencies.
- If a civilian or military aircraft is already tracked when `CONTACTS` becomes operational, that source-owned track is adopted as the Context subject before nearest-contact autofocus. Context rechecks the tracker after its dependencies settle, so a newer selection wins, while an explicit clear during activation prevents fallback from silently selecting a replacement. Cockpit entry remains unavailable until that Context transaction has settled, so its camera takeover cannot clear Cesium tracking before adoption. Adoption does not recreate tracking or transfer camera ownership; it initializes the normal 250 km ring, history, proximity results, and Cockpit Previous/Next state for the original aircraft.
-- `SEARCH NEARBY SITES` retains the bounded OSM results and makes one user-initiated, view-biased Google Maps Places text search for “military installation.” Google results are source-stamped, deduplicated against OSM by rounded location/name, and remain mapped context rather than operational claims. If Places is unavailable or the API is not enabled for the supplied key, OSM context remains available.
+- `SEARCH NEARBY SITES` retains the bounded OSM results and makes one user-initiated, view-biased Google Maps Places text search for “military installation.” Google results are source-stamped, deduplicated against OSM by rounded location/name, and remain mapped context rather than operational claims. If Places is unavailable or the API is not enabled for the supplied key, OSM context remains available. A view across the antimeridian is searched around its own centre, with a radius from its real width.
- The expanded desktop header omits the redundant `ON` label; the active mode button carries state. Expanded Contact results also omit the duplicate `GLOBAL CONTEXT` / `CONTEXT ONLY` status row and begin with the selected subject and its 250 km scope. Global Context does not fabricate a selected-entity model preview: the provisional hand-authored aircraft wireframe was removed because it was not geometry extracted from the selected entity's actual asset.
- Dependency ownership is reversible: disabling Global Context releases only dependencies it enabled, while user-enabled layers remain on. This also removes the Military-layer suppression handoff when Global Context owned Military, allowing an already-enabled civilian Flights layer to resume its normal mixed rendering. If OpenSky is unavailable and has no last-good cache, Flights requests a capped 250 nm adsb.lol point snapshot around the current view anchor and labels that provenance explicitly; it never relabels military-feed rows as civilian data. If both inputs fail, Flights remains `UNKNOWN`.
- Space Missions is replay-isolated: Rocket Launches and Satellites are the only Data Layers permitted while the mode is active. Direct UI and voice entry capture the same pre-entry snapshot; internal dependency and restoration enables do not create a user-owned Context session. Entry waits for incompatible layers to shut down, direct incompatible enables are blocked before lifecycle work, and the entry gate remains active through the complete Rocket Launches enable. A newer same-target ON request takes ownership of the pending entry without releasing its isolation snapshot, including when it arrives while the prior request is awaiting the adoption guard. A caller abort, resource cancellation, newer OFF, or layer teardown waits for exact manager settlement and restores that snapshot without resurrecting Rocket Launches. If an abort lands after only part of a restore settles, Context completes the same exact target without the stale caller signal and then replays newer explicit layer intent. Dedicated Voice Context cancellation reports a stable cancelled result plus the current Context state; generic layer visibility additionally exposes manager phase, reason, successor, and lifecycle details. Once an exact voice visibility intent commits, a newer voice turn cannot relabel it as cancelled while Context settlement completes; pre-commit aborts remain cancellable and final lifecycle mismatches remain failures. Clear Selected Layers reserves its complete captured OFF set before sequential teardown; a newer absolute request of any origin supersedes only its layer reservation and remains authoritative. A rejected layer teardown retains the truthful enabled state, rolls already-stopped siblings back to the captured pre-entry set, and aborts replay; rapid exit/re-entry serializes the full Satellite enabled-state and parameter restore before a new snapshot is taken. Contacts remains additive and restores user-enabled layers normally.
@@ -4829,7 +4865,7 @@ pins and share links already supply complete boxes.
- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied.
- **Rendering.** `rendering.js` owns at most two GIBS layers on the host `src/maps/imageryHost.js` resolves: `viewer.imageryLayers` while the globe shows, the photoreal tileset's `imageryLayers` while it is hidden, or none (the panel says so). Layers are rebuilt on a new host, never re-parented. `MapSourceController.subscribe()` fires after every settled stack switch (silent switches and fallbacks included) and the layer rebinds on it. Tile requests pass a six-slot semaphore of our own (Cesium's global limits are untouched). Under `requestRenderMode` a deferred tile needs a later frame, but a deferral must never request one itself or a stalled tile keeps the scene rendering every frame: a request that finds the semaphore full asks for nothing (the settling request asks for one frame), and a tile Cesium itself deferred goes through one coalesced 250 ms retry. Thumbnails: three fetches at once, sixteen decoded images, least-recently-used where a `get` read is never a use; eviction keeps the probe result. The strip's visible window is probed around the focused card; the pinned and previewed days are probed wherever they sit, at the focused card's priority, so a pin restored or assigned off-screen still drapes.
- **Esri surface and the swipe.** While any image is on the map (a preview included) the layer holds the map lease (`acquireImageryComparison`, owner `recent-imagery`, `esri-if-photoreal`): on Google 3D the map switches to Esri, because 30 m pixels over 3D buildings do not read, and Cesium's split only works on the globe. The lease is handed back, and Google 3D restored unless the operator changed maps meanwhile, when the last image leaves the map or the layer is disabled; the notice line says so while it holds. While a day is shown the imagery keeps Esri: a manual switch that lands on Google 3D is answered at once with a new lease under the same policy (`keepEsri`), the notice reads `Imagery stays on Esri · CLEAR to use Google 3D`, and the divider never suspends because of a map switch. It re-leases once per switch generation and only for a manual one (`MapSourceController#getSwitchOrigin()` is `manual` for an outside `setStack`, `automatic` for the controller's own fallback or recovery), never for the lease's own switch and never while releasing, so CLEAR and disable still return to Google 3D; a lease another owner holds stays refused. When Esri fails and the controller falls back to Google 3D on its own, the layer lets the lease go without restoring anything, both days drape on the tileset without a swipe and the guidance reads `Esri map unavailable · no swipe`; only the next manual switch to Google 3D takes Esri again, so a failing Esri map is never retried in a loop. Switching between globe stacks (Esri, OSM, Bing) only rebinds. On a tileset host both images drape without a swipe. The split control (`createImagerySplit`, labels A / B, or IMAGE / BASEMAP) exists only while a swipe is live, recentres on every new comparison (not while scrubbing the second day), except once for a split restored from a link. There is no keyboard shortcut (Space is the app's push-to-talk): SWAP (`#ri-swap`, in the controls row, its slot reserved and the button disabled while no swipe is live) trades the two sides, A to the right and B to the left, or the image to the right of the basemap, and a second click restores; the hint reads `Drag the divider · SWAP trades sides`. The swap is not in the share link, and every new comparison starts unswapped. One opacity applies to both drapes. Another owner holding the lease is reported and the images still drape.
-- **Panel.** `#recent-imagery-panel` is static rail markup in `src/ui/templates/context.html` beside `#weather-panel`, registered in `PanelLayoutController`, `PanelChrome` and the share panel state (`ui` token `i`), hidden while the layer is off and opened on first appearance unless a stored or shared collapse choice exists (`dataset.collapsedPreference`). `LayerPanel.attachRecentImagery(factory)` mounts the readout (`createRecentImageryPanel` in `src/ui/recentImagery.js`) into its `data-rail-scroller` body, as the weather readout is mounted. The body is a fixed stack in which no block changes height and no control moves in any state: `#ri-actions` (SELECT BOX · USE VIEW · CLEAR, rail-card actions), `#ri-notice` (one line: `#ri-notice-text` with the refusal, error, CLEAR notice or the Esri note, and `#ri-zoom-in` in a fixed slot at its right end, reserved unless an oversized box or view can be fitted), `#ri-strip` (day cards newest first: thumbnail, date, sensor, cloud, START HERE, PREVIEW, and a SHOW chip or A and B chips; ← → Home End move, S / A / B pin, Enter previews), `#ri-hint` (one line: the next step), `#ri-selection` (`#ri-mode` IMAGE · VS BASEMAP · A / B, then `#ri-slot-a` and `#ri-slot-b` with `#ri-unpin-a` / `#ri-unpin-b` kept in place when empty), `#ri-controls` (`#ri-opacity`, EXPORT / EXPORT A and EXPORT B) and `#ri-details`, a collapsed rail card holding the focused day's acquisition, coverage and granules, catalog notes, the empty-days toggle and the imagery credit. Absent controls are reserved (invisible), never removed. Every render preserves the body's `scrollTop`.
+- **Panel.** `#recent-imagery-panel` is static rail markup in `src/ui/templates/context.html` beside `#weather-panel`, registered in `PanelLayoutController`, `PanelChrome` and the share panel state (`ui` token `i`), hidden while the layer is off and opened on first appearance unless a stored or shared collapse choice exists (`dataset.collapsedPreference`). `LayerPanel.attachRecentImagery(factory)` mounts the readout (`createRecentImageryPanel` in `src/ui/recentImagery.js`) into its `data-rail-scroller` body, as the weather readout is mounted. The body is a fixed stack in which no block changes height and no control moves in any state: `#ri-actions` (SELECT BOX · USE VIEW · CLEAR, rail-card actions), `#ri-notice` (one line: `#ri-notice-text` with the refusal, error, CLEAR notice or the Esri note, and `#ri-zoom-in` in a fixed slot at its right end, reserved unless an oversized box or view can be fitted), `#ri-strip` (day cards newest first: thumbnail, date, sensor, cloud, START HERE, PREVIEW, and a SHOW chip or A and B chips; ← → Home End move, S / A / B pin, Enter previews), `#ri-hint` (one line: the next step), `#ri-selection` (`#ri-mode` IMAGE · VS BASEMAP · A / B, then `#ri-slot-a` and `#ri-slot-b` with `#ri-unpin-a` / `#ri-unpin-b` kept in place when empty), `#ri-controls` (`#ri-opacity`, EXPORT / EXPORT A and EXPORT B) and `#ri-details`, a collapsed rail card holding the focused day's acquisition, coverage and granules, catalog notes, the empty-days toggle and the imagery credit. Absent controls are reserved (invisible), never removed. Every render preserves the body's `scrollTop`; opening DETAILS then scrolls its card into view once.
- **Share links.** Layer options (token `1`): box edges as integers at degrees × 100000, pins `a` and `b` as compact days (`S20260918`), `m` mode (0 image, 1 basemap, 2 A / B), `p` split percent (share-link only: never stored locally) and `v` for the daily overview. Row chips: `MORE DETAIL · 30 m` (on) and `DAILY OVERVIEW · 250 m` (off).
- Regression surface: the colocated `*.test.mjs` beside each module (shared doubles in `src/layers/recentImagery/testDoubles.mjs`; `src/ui/recentImagery.test.mjs` includes a DOM-structure guard: every control keeps its place in the tree, nothing is hidden, and every fixed-height block keeps the class the stylesheet fixes its height by; it has no layout, so it cannot see movement), `src/ui/layerPanel.test.mjs` (mount), `src/maps/controller.test.mjs` (`subscribe`), `src/data/layerState.test.mjs` (codec), `src/sharelink.celestial.test.mjs` (panel token), and the live gate `scripts/qa-recent-imagery.mjs`, which also measures every control's rect, relative to the panel, across the transitions within 1 px; that measurement is the real layout-shift check. `QA_RECENT_IMAGERY_SLOW_RENDER=1` gives loaded software renderers a 4 s zoom deadline and an 8-sample stability tail; the default stays 2 s and 12 samples.
diff --git a/scripts/format-scope.json b/scripts/format-scope.json
index a2b3e01f89..8bcc4c04df 100644
--- a/scripts/format-scope.json
+++ b/scripts/format-scope.json
@@ -117,6 +117,7 @@
"server/providers/cctv/constants.js",
"server/providers/cctv/media.js",
"server/providers/cctv/normalize.js",
+ "src/data/cctvMissingNumbers.test.mjs",
"server/providers/cctv/sources.js",
"server/providers/radio.js",
"server/providers/radio/catalog.js",
diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json
index a9c49f6c38..75ed60f180 100644
--- a/scripts/package-boundaries.json
+++ b/scripts/package-boundaries.json
@@ -901,6 +901,7 @@
"src/data/aircraftIcons.js",
"src/data/aircraftMeta.js",
"src/data/aircraftNearbyPolicy.js",
+ "src/data/approxDistance.js",
"src/data/cockpitAirLod.js",
"src/data/cockpitContactDot.js",
"src/data/contactMatch.js",
@@ -1649,6 +1650,7 @@
"src/ui/radioPanelPlacement.js",
"src/cyberSonarGpu.js",
"src/scenes/nepalEvidencePack.js",
+ "src/data/approxDistance.js",
"src/data/bhoteKoshiEvent.js",
"src/ui/imagerySplit.js",
"src/data/bhoteKoshiEmbeddedMedia.js",
@@ -2500,6 +2502,7 @@
"exports": ["./application/layers"],
"modules": [
"src/cyberSonar.js",
+ "src/data/approxDistance.js",
"src/data/bhoteKoshiEvent.js",
"src/ui/imagerySplit.js",
"src/maps/imageryComparison.js",
@@ -3067,6 +3070,7 @@
"src/app/operations.js",
"src/sources/sourceSlot.js",
"src/app/surfaceServices.js",
+ "src/data/approxDistance.js",
"src/data/dataCredits.js",
"src/data/geoid.js",
"src/data/local_data/natural_earth/marine.json",
@@ -3226,6 +3230,7 @@
"src/layers/flights/records.js",
"src/layers/flights/recordPolicy.js",
"src/data/aircraftMeta.js",
+ "src/data/approxDistance.js",
"src/data/renderAltitude.js",
"src/data/aircraftClass.js",
"src/data/aircraftEmergency.js"
@@ -3236,7 +3241,8 @@
"exports": ["./layers/flights/ingestion"],
"modules": [
"src/layers/flights/ingestion.js",
- "src/layers/flights/recordPolicy.js"
+ "src/layers/flights/recordPolicy.js",
+ "src/data/approxDistance.js"
],
"external": []
},
@@ -3547,6 +3553,7 @@
"src/cyberSonar.js",
"src/app/sourceSlot.js",
"src/celestialRing.js",
+ "src/data/approxDistance.js",
"src/data/cameraSensitivity.js",
"src/data/contactPlayback.js",
"src/data/contactTrailRenderer.js",
diff --git a/server/providers/cctv/normalize.js b/server/providers/cctv/normalize.js
index 6c54622e97..2d4e16e112 100644
--- a/server/providers/cctv/normalize.js
+++ b/server/providers/cctv/normalize.js
@@ -39,11 +39,21 @@ export function escapeXml(text) {
/**
* Coerce a value to a finite number, returning fallback if NaN/Infinity.
*
+ * Absent, blank and boolean values take the fallback too: `Number` reads
+ * null, '' and false as 0, which would turn a missing coordinate, heading or
+ * elevation into a real zero.
+ *
* @param {*} value
* @param {number} [fallback=NaN]
* @returns {number}
*/
export function toFiniteNumber(value, fallback = NaN) {
+ if (
+ value == null ||
+ typeof value === 'boolean' ||
+ (typeof value === 'string' && !value.trim())
+ )
+ return fallback;
const num = Number(value);
return Number.isFinite(num) ? num : fallback;
}
diff --git a/src/data/approxDistance.js b/src/data/approxDistance.js
new file mode 100644
index 0000000000..d581589a5d
--- /dev/null
+++ b/src/data/approxDistance.js
@@ -0,0 +1,12 @@
+/**
+ * Local equirectangular distance in km, for viewer-proximity gates. Takes the
+ * short way round, so points either side of 180° stay close.
+ */
+export function approxDistanceKm(lat1, lon1, lat2, lon2) {
+ const dLat = (lat2 - lat1) * 111.32;
+ let dLonDeg = lon2 - lon1;
+ dLonDeg -= 360 * Math.round(dLonDeg / 360);
+ const dLon =
+ dLonDeg * 111.32 * Math.cos((((lat1 + lat2) / 2) * Math.PI) / 180);
+ return Math.hypot(dLat, dLon);
+}
diff --git a/src/data/cctvMissingNumbers.test.mjs b/src/data/cctvMissingNumbers.test.mjs
new file mode 100644
index 0000000000..68911110f8
--- /dev/null
+++ b/src/data/cctvMissingNumbers.test.mjs
@@ -0,0 +1,252 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import {
+ fallbackHeadingFromId,
+ isLikelyCataloniaCoordinate,
+ toFiniteNumber,
+} from '../../server/providers/cctv/normalize.js';
+import {
+ loadCaltransSourcesFromOpenData,
+ loadTallinnSourcesFromCatalog,
+ loadTflSourcesFromOpenData,
+ parseCataloniaXml,
+} from '../../server/providers/cctv/sources.js';
+import { cctvProxy } from '../../server/providers/cctv.js';
+import { createCatalog } from '../layers/cctv/catalog.js';
+import { createModel } from '../layers/cctv/model.js';
+
+/** Values `Number` reads as 0 (or 1) although they carry no number. */
+const ABSENT = [null, undefined, '', ' ', false, true];
+
+/** Set env vars for one test and restore them afterwards. */
+function withEnv(t, env) {
+ for (const [name, value] of Object.entries(env)) {
+ const previous = process.env[name];
+ t.after(() => {
+ if (previous === undefined) delete process.env[name];
+ else process.env[name] = previous;
+ });
+ if (value === undefined) delete process.env[name];
+ else process.env[name] = value;
+ }
+}
+
+/** Silence the loaders' progress and failure logging. */
+function quiet(t) {
+ t.mock.method(console, 'log', () => {});
+ t.mock.method(console, 'warn', () => {});
+}
+
+/** The production browser model; only the catalog's pose pass is stubbed. */
+function browserModel() {
+ const parts = {};
+ parts.model = createModel({
+ state: {},
+ services: { focus: {} },
+ parts,
+ source: {},
+ });
+ return parts.model;
+}
+
+/** The browser catalog over the production model. */
+function browserCatalog(model, cityPois = {}) {
+ return createCatalog({
+ state: {},
+ services: { locations: { CITY_POIS: cityPois } },
+ parts: { model: { ...model, ensureCameraPose: () => {} } },
+ source: {},
+ });
+}
+
+/** GET /api/cctv/sources through the real proxy middleware. */
+async function requestSources(plugin) {
+ let handler;
+ plugin.configureServer({
+ middlewares: {
+ use(_route, fn) {
+ handler = fn;
+ },
+ },
+ });
+ const res = {
+ writeHead(status, headers) {
+ Object.assign(this, { status, headers });
+ },
+ end(body) {
+ this.body = body;
+ },
+ };
+ await handler({ url: '/sources', method: 'GET' }, res);
+ assert.equal(res.status, 200);
+ return JSON.parse(res.body);
+}
+
+test('absent, blank and boolean values take the fallback on both sides of the source list', () => {
+ const { safeNumber } = browserModel();
+ for (const value of ABSENT) {
+ assert.ok(Number.isNaN(toFiniteNumber(value)), `server ${String(value)}`);
+ assert.equal(toFiniteNumber(value, 15), 15, `server ${String(value)}`);
+ assert.ok(Number.isNaN(safeNumber(value)), `browser ${String(value)}`);
+ assert.equal(safeNumber(value, 74), 74, `browser ${String(value)}`);
+ }
+ for (const [value, expected] of [
+ [0, 0],
+ ['0', 0],
+ [-17, -17],
+ [' 12.5 ', 12.5],
+ ]) {
+ assert.equal(toFiniteNumber(value, 99), expected);
+ assert.equal(safeNumber(value, 99), expected);
+ }
+});
+
+test('a source-pack camera that omits or nulls its pose gets the browser defaults, not the clamp floors', async (t) => {
+ quiet(t);
+ const pose = {
+ headingDeg: null,
+ pitchDeg: null,
+ fovDeg: null,
+ rangeM: null,
+ mountHeightM: null,
+ groundElevationM: null,
+ };
+ const at = { cityId: 'austin', lat: 30.2672, lon: -97.7431 };
+ withEnv(t, {
+ CCTV_SOURCES_FILE: path.join(tmpdir(), 'gev-no-such-pack.json'),
+ CCTV_SOURCES_JSON: JSON.stringify([
+ { id: 'pack-pose-omitted', ...at, feedType: 'image' },
+ { id: 'pack-pose-null', ...at, ...pose, feedType: 'image' },
+ { id: 'pack-coords-null', lat: null, lon: null, feedType: 'image' },
+ { id: 'pack-coords-blank', lat: '', lon: ' ', feedType: 'image' },
+ ]),
+ });
+
+ const body = await requestSources(cctvProxy({ sourceRoot: tmpdir() }));
+ const model = browserModel();
+ const cameras = browserCatalog(model, {
+ austin: { name: 'Austin', groundElevation: 150 },
+ }).buildCatalogFromSources(body.sources);
+ const byId = new Map(cameras.map((camera) => [camera.id, camera]));
+
+ for (const id of ['pack-pose-omitted', 'pack-pose-null']) {
+ const camera = byId.get(id);
+ assert.ok(camera, id);
+ assert.equal(camera.headingDeg, model.headingFromId(id), id);
+ assert.equal(camera.pitchDeg, -17, id);
+ assert.equal(camera.fovDeg, 74, id);
+ assert.equal(camera.rangeM, 700, id);
+ assert.equal(camera.mountHeightM, 24, id);
+ assert.equal(camera.groundElevationM, 150, id);
+ }
+ // No position is not a camera in the Gulf of Guinea.
+ assert.equal(byId.has('pack-coords-null'), false);
+ assert.equal(byId.has('pack-coords-blank'), false);
+});
+
+test('Tallinn rows with a null heading or ground keep the low-confidence prior', (t) => {
+ quiet(t);
+ const root = mkdtempSync(path.join(tmpdir(), 'gev-tallinn-'));
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ const file = path.join(root, 'tallinn.json');
+ writeFileSync(
+ file,
+ JSON.stringify([
+ {
+ id: 'tln-null-heading',
+ lat: 59.437,
+ lon: 24.753,
+ headingDeg: null,
+ groundElevationM: null,
+ url: 'https://ristmikud.tallinn.ee/last/cam001.jpg',
+ },
+ ]),
+ );
+ withEnv(t, { CCTV_TALLINN_SOURCES_FILE: file });
+
+ const [camera] = loadTallinnSourcesFromCatalog({ sourceRoot: root });
+ assert.equal(camera.headingConfidence, 'low');
+ assert.equal(camera.headingDeg, fallbackHeadingFromId('tln-null-heading'));
+ assert.equal(camera.groundElevationM, 15);
+});
+
+test('TfL JamCams with null coordinates are dropped instead of placed at 0,0', async (t) => {
+ quiet(t);
+ const jamCam = (id, lat, lon) => ({
+ id: `JamCams_${id}`,
+ commonName: `JamCam ${id}`,
+ lat,
+ lon,
+ additionalProperties: [
+ { key: 'available', value: 'true' },
+ {
+ key: 'imageUrl',
+ value: `https://s3-eu-west-1.amazonaws.com/jamcams.tfl.gov.uk/${id}.jpg`,
+ },
+ ],
+ });
+ t.mock.method(globalThis, 'fetch', async () =>
+ Response.json([
+ jamCam('00001.00001', 51.5072, -0.1276),
+ jamCam('00001.00002', null, null),
+ jamCam('00001.00003', 51.5072, ''),
+ ]),
+ );
+
+ const cameras = await loadTflSourcesFromOpenData();
+ assert.deepEqual(
+ cameras.map((camera) => camera.id),
+ ['tfl-00001.00001'],
+ );
+});
+
+test('a Catalonia feature with a blank longitude is not read as the zero meridian', () => {
+ const feature = (coordinates) => `
+
+ ${coordinates}
+ https://example.org/cam.jpg
+
+ `;
+ const [blank, valid] = parseCataloniaXml(
+ feature(',41.5') + feature('2.17,41.39'),
+ );
+ // 0 °E at 41.5 °N is inside the Catalonia box, so a zero would pass it.
+ assert.ok(Number.isNaN(blank.lon));
+ assert.equal(isLikelyCataloniaCoordinate(blank.lat, blank.lon), false);
+ assert.equal(isLikelyCataloniaCoordinate(valid.lat, valid.lon), true);
+});
+
+test('a Caltrans camera with a blank elevation keeps the 150 m ground prior', async (t) => {
+ quiet(t);
+ withEnv(t, { CCTV_CALTRANS_DISTRICTS: '4' });
+ t.mock.method(globalThis, 'fetch', async () =>
+ Response.json({
+ data: [
+ {
+ cctv: {
+ inService: 'true',
+ location: {
+ latitude: '37.8044',
+ longitude: '-122.2712',
+ elevation: '',
+ locationName: 'TV101 -- I-880 : Test Ave',
+ },
+ imageData: {
+ static: {
+ currentImageURL:
+ 'https://cwwp2.dot.ca.gov/data/d4/cctv/image/tv101/tv101.jpg',
+ },
+ },
+ },
+ },
+ ],
+ }),
+ );
+
+ const [camera] = await loadCaltransSourcesFromOpenData();
+ assert.ok(camera);
+ assert.equal(camera.groundElevationM, 150);
+});
diff --git a/src/data/flights.test.mjs b/src/data/flights.test.mjs
index c325ea7445..7fe197c303 100644
--- a/src/data/flights.test.mjs
+++ b/src/data/flights.test.mjs
@@ -726,7 +726,15 @@ const LABEL_ICAO = 'ae1fa4';
const LABEL_POSITION = Cesium.Cartesian3.fromDegrees(-97.71, 30.21, 10_668);
/** Seed one civil contact through the production refresh seam. */
-function seedLabelContact({ callsign, registration, tracked = false }) {
+function seedLabelContact({
+ callsign,
+ registration,
+ tracked = false,
+ // Per-test metadata overrides, spread last so a test can set a field to
+ // `undefined` to model "the feed never sent it" — a default parameter
+ // could not express that, it would just re-supply the default.
+ meta: metaOverrides = {},
+}) {
_setTrackedFlightRefreshStateForTest({
icao24: LABEL_ICAO,
entity: null,
@@ -752,6 +760,7 @@ function seedLabelContact({ callsign, registration, tracked = false }) {
turnRateDps: 0,
rawLat: 30.21,
rawLon: -97.71,
+ ...metaOverrides,
},
});
}
@@ -825,6 +834,44 @@ test('civil label chain: the cockpit descriptor exposes a trimmed registration',
assert.equal(flightsLayer.getTrackedInfo()?.registration, null);
});
+test('the tracked descriptor publishes the reported vertical rate', () => {
+ // `mapAnalystRecord` has always published `verticalRateMps`; the tracked
+ // seam did not, so a consumer that needs climb/descent (a flight-phase
+ // classifier, the cockpit) had to reach past getTrackedInfo() into the
+ // raw record. Both seams now answer with the same field name and unit.
+ seedLabelContact({
+ callsign: 'SWA696',
+ registration: 'N123AB',
+ tracked: true,
+ meta: { verticalRate: -6.4 },
+ });
+ assert.equal(flightsLayer.getTrackedInfo()?.verticalRateMps, -6.4);
+ assert.equal(
+ mapAnalystRecord(LABEL_ICAO, { verticalRate: -6.4 }).verticalRateMps,
+ -6.4,
+ 'the analyst seam and the tracked seam must agree',
+ );
+});
+
+test('an unreported vertical rate stays null, never a level-flight zero', () => {
+ // Absent is not level. `stickyNumber` seeds this field with null, so a
+ // contact that has never transmitted a rate must not read as 0 m/s — a
+ // phase classifier would call that cruise while the aircraft climbs.
+ for (const missing of [undefined, null, Number.NaN]) {
+ seedLabelContact({
+ callsign: 'SWA696',
+ registration: 'N123AB',
+ tracked: true,
+ meta: { verticalRate: missing },
+ });
+ assert.equal(
+ flightsLayer.getTrackedInfo()?.verticalRateMps,
+ null,
+ `vertical rate ${String(missing)} must publish as null`,
+ );
+ }
+});
+
test('civil label chain: identity stays icao24 while the label moves', () => {
for (const fixture of [
{ callsign: 'SWA696', registration: 'N123AB' },
diff --git a/src/data/groundFloor.test.mjs b/src/data/groundFloor.test.mjs
index e118549c3e..4644f57cac 100644
--- a/src/data/groundFloor.test.mjs
+++ b/src/data/groundFloor.test.mjs
@@ -257,6 +257,32 @@ test('stickyFloorCell does not stick to a far-away stale cell', () => {
assert.deepEqual(stickyFloorCell(30.2004, -97.6604, prev), { lat: 30.2, lon: -97.66 });
});
+// --- Antimeridian ------------------------------------------------------------
+// Raw longitude arithmetic walks a segment across 180° the long way round and
+// reads a contact on the seam as half a world from its previous cell.
+
+test('corridorFloorCells walks across the antimeridian, not the long way round', () => {
+ for (const [from, to, across, behind] of [
+ [179.999, -179.998, -179.999, 179.998],
+ [-179.999, 179.998, 179.999, -179.998],
+ ]) {
+ const cells = corridorFloorCells([{ lat: -16.69, lon: from }, { lat: -16.69, lon: to }]);
+ const lons = cells.map((c) => c.lon);
+ assert.equal(lons[0], from);
+ assert.equal(lons.at(-1), to);
+ assert.ok(lons.includes(across), `crosses through ${across}: ${lons}`);
+ assert.ok(!lons.includes(behind), `never walks back through ${behind}: ${lons}`);
+ assert.ok(lons.every((lon) => Math.abs(lon) <= 180), `normalised: ${lons}`);
+ }
+});
+
+test('stickyFloorCell holds across the antimeridian', () => {
+ for (const [prevLon, lon] of [[180, -179.9998], [-180, 179.9998]]) {
+ const prev = { lat: -16.69, lon: prevLon };
+ assert.deepEqual(stickyFloorCell(-16.69, lon, prev), prev);
+ }
+});
+
// --- F2: corridor budget fairness ------------------------------------------
// The first cut spent the budget in Map insertion order and decremented it
// BEFORE deduping, so parked contacts (whose corridor is the fix cell the poll
diff --git a/src/data/meshFloorSampler.test.mjs b/src/data/meshFloorSampler.test.mjs
index 8c629e50f3..f651d72f8c 100644
--- a/src/data/meshFloorSampler.test.mjs
+++ b/src/data/meshFloorSampler.test.mjs
@@ -128,3 +128,12 @@ test('sampler: outside the google-3d regime nothing is sampled at all', () => {
setMeshFloorPreferred(true);
assert.equal(cachedMeshFloor(cell.lat, cell.lon), null);
});
+
+test('sampler: a cell just across the antimeridian is still near the viewer', () => {
+ reset();
+ let calls = 0;
+ const scene = fakeScene(() => { calls += 1; return undefined; });
+ sampleMeshFloorCells(scene, [{ lat: -16.8, lon: -179.999 }], { viewerLat: -16.8, viewerLon: 179.999 });
+ 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');
+});
diff --git a/src/data/militaryFlights.test.mjs b/src/data/militaryFlights.test.mjs
index 0c518eb5f2..d04061793c 100644
--- a/src/data/militaryFlights.test.mjs
+++ b/src/data/militaryFlights.test.mjs
@@ -834,3 +834,48 @@ test('two contacts matching at the same strength resolve deterministically', ()
'and the same query resolves the same way every time',
);
});
+
+test('the military tracked descriptor publishes the reported vertical rate', () => {
+ // Shape parity with the civil layer's getTrackedInfo(). The two layers store
+ // the rate under different record keys (`verticalRateMps` here,
+ // `verticalRate` there), so `resolveTrackedAircraftInfo` only hands back one
+ // shape if BOTH descriptors map it — a consumer that reads the field off the
+ // civil seam and finds it missing on the military one would silently treat
+ // every military contact as level flight.
+ const seedRate = (verticalRateMps) =>
+ _setTrackedMilitaryRefreshStateForTest({
+ icao24: 'ae7f01',
+ entity: { gevLabelModel: { title: 'TEST', details: [] } },
+ billboard: {
+ position: Cesium.Cartesian3.fromDegrees(-97.0, 31.0, 8_000),
+ color: Cesium.Color.WHITE,
+ show: true,
+ },
+ billboardCollection: { show: true, remove() {} },
+ viewer: { camera: { positionCartographic: null }, scene: {} },
+ meta: {
+ callsign: 'RCH512',
+ rawLat: 31,
+ rawLon: -97,
+ altitudeFt: 26_000,
+ speedMps: 220,
+ track: 95,
+ onGround: false,
+ verticalRateMps,
+ },
+ });
+
+ seedRate(12.7);
+ assert.equal(militaryFlightsLayer.getTrackedInfo()?.verticalRateMps, 12.7);
+
+ // Absent is not level: a contact that has never transmitted a rate must read
+ // as null, not as a 0 m/s a phase classifier would call cruise.
+ for (const missing of [undefined, null, Number.NaN]) {
+ seedRate(missing);
+ assert.equal(
+ militaryFlightsLayer.getTrackedInfo()?.verticalRateMps,
+ null,
+ `vertical rate ${String(missing)} must publish as null`,
+ );
+ }
+});
diff --git a/src/data/rocketLaunches.test.mjs b/src/data/rocketLaunches.test.mjs
index a1a3fab44b..ccfd280e25 100644
--- a/src/data/rocketLaunches.test.mjs
+++ b/src/data/rocketLaunches.test.mjs
@@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import { gstime } from 'satellite.js';
+import { createModel } from '../layers/launches/model.js';
import rocketLaunchesLayer, {
_setRocketMissionOverlayHostForTest,
_setSelectedRocketMissionForTest,
@@ -728,6 +729,126 @@ test('normalizes detailed payload and stage recovery records', () => {
assert.equal(launches[0].recoveryStages[0].lon, -76.2);
});
+test('finiteCoordinate normalizes finite numbers and rejects non-numeric or non-finite inputs', () => {
+ const model = createModel({});
+ assert.equal(model.finiteCoordinate(42.5), 42.5);
+ assert.equal(model.finiteCoordinate('28.5619'), 28.5619);
+ assert.equal(model.finiteCoordinate('-80.5772'), -80.5772);
+ assert.equal(model.finiteCoordinate(0), 0);
+ assert.equal(model.finiteCoordinate('0'), 0);
+ assert.equal(model.finiteCoordinate(undefined), null);
+ assert.equal(model.finiteCoordinate('invalid'), null);
+ assert.equal(model.finiteCoordinate('TBD'), null);
+ assert.equal(model.finiteCoordinate(Number.NaN), null);
+ assert.equal(model.finiteCoordinate(Number.POSITIVE_INFINITY), null);
+ assert.equal(model.finiteCoordinate(Number.NEGATIVE_INFINITY), null);
+});
+
+test('normalizes recovery stage coordinates, downrange distance, and flight numbers with non-finite fallbacks', () => {
+ const launches = normalizeRocketLaunches(
+ {
+ results: [
+ {
+ id: 'recovery-fallbacks',
+ name: 'Falcon 9 | Edge Case Stage Normalization',
+ net: '2026-07-20T10:00:00Z',
+ pad: { latitude: '28.608', longitude: '-80.604' },
+ rocket: {
+ launcher_stage: [
+ {
+ id: 88,
+ type: { name: 'Booster' },
+ launcher_flight_number: 'invalid-flight',
+ landing: {
+ attempt: true,
+ success: false,
+ downrange_distance: 'TBD',
+ landing_location: {
+ name: 'Ocean Impact',
+ latitude: 'N/A',
+ longitude: undefined,
+ },
+ },
+ },
+ {
+ id: 89,
+ type: { name: 'Expended Stage' },
+ landing: {
+ attempt: false,
+ type: { name: 'Expendable' },
+ },
+ },
+ ],
+ },
+ },
+ ],
+ },
+ NOW,
+ );
+
+ assert.equal(launches[0].recoveryStages.length, 2);
+
+ const booster = launches[0].recoveryStages[0];
+ assert.equal(booster.status, 'LOST');
+ assert.equal(booster.success, false);
+ assert.equal(booster.attempted, true);
+ assert.equal(booster.flightNumber, null);
+ assert.equal(booster.downrangeKm, null);
+ assert.equal(booster.lat, null);
+ assert.equal(booster.lon, null);
+
+ const expendable = launches[0].recoveryStages[1];
+ assert.equal(expendable.status, 'EXPENDABLE');
+ assert.equal(expendable.attempted, false);
+ assert.equal(expendable.success, null);
+});
+
+test('normalizes payload amounts and fractional string masses', () => {
+ const launches = normalizeRocketLaunches(
+ {
+ results: [
+ {
+ id: 'payload-edge-cases',
+ name: 'Electron | Mixed Payloads',
+ net: '2026-07-20T10:00:00Z',
+ pad: { latitude: '-39.26', longitude: '177.86' },
+ rocket: {
+ payloads: [
+ {
+ id: 601,
+ amount: 'not-a-number',
+ payload: { id: 11, name: 'Unknown Amount Payload' },
+ },
+ {
+ id: 602,
+ amount: 3,
+ payload: { id: 12, name: 'Triple Payload' },
+ },
+ {
+ id: 603,
+ payload: {
+ id: 13,
+ name: 'Valid Fractional Mass Payload',
+ mass: '12.75',
+ },
+ },
+ ],
+ },
+ },
+ ],
+ },
+ NOW,
+ );
+
+ // Blank, negative and non-numeric masses are pinned by "missing payload
+ // details stay unknown without inventing mass or classification".
+ const payloads = launches[0].payloads;
+ assert.equal(payloads.length, 3);
+ assert.equal(payloads[0].amount, 1);
+ assert.equal(payloads[1].amount, 3);
+ assert.equal(payloads[2].massKg, 12.75);
+});
+
test('keeps payload and recovery collections empty when LL2 does not disclose them', () => {
const launches = normalizeRocketLaunches({ results: [{
id: 'undisclosed',
diff --git a/src/layers/cctv/model.js b/src/layers/cctv/model.js
index 48c8cddd48..bdf350b4e9 100644
--- a/src/layers/cctv/model.js
+++ b/src/layers/cctv/model.js
@@ -97,12 +97,23 @@ export function createModel({ state: layerState, services, parts, source }) {
/**
* Coerces a value to a finite number or returns the fallback.
+ *
+ * Absent, blank and boolean values return the fallback as well. The source
+ * list serializes an unknown number (NaN) as JSON null, and `Number(null)`
+ * is 0, so without this an unknown pose field arrived as zero and was
+ * clamped to the field's floor instead of taking its default.
* @param {*} value
* @param {number} [fallback=NaN]
* @returns {number}
*/
function safeNumber(value, fallback = NaN) {
+ if (
+ value == null ||
+ typeof value === 'boolean' ||
+ (typeof value === 'string' && !value.trim())
+ )
+ return fallback;
const n = Number(value);
return Number.isFinite(n) ? n : fallback;
}
diff --git a/src/layers/flights/queries.js b/src/layers/flights/queries.js
index 9c206a335b..552adbe011 100644
--- a/src/layers/flights/queries.js
+++ b/src/layers/flights/queries.js
@@ -114,7 +114,7 @@ export function createQueries({
* Build a public descriptor for one aircraft using its best current position
* (dead-reckoned when history exists, billboard position otherwise).
* @param {string} icao24 - ICAO 24-bit transponder address.
- * @returns {{icao24: string, callsign: string|null, position: Cesium.Cartesian3, latitude: number, longitude: number, altitudeM: number, velocityMps: number|null, track: number|null}|null}
+ * @returns {{icao24: string, callsign: string|null, position: Cesium.Cartesian3, latitude: number, longitude: number, altitudeM: number, velocityMps: number|null, track: number|null, verticalRateMps: number|null}|null}
* Descriptor with a cloned position, or null if the aircraft is unknown.
*/
@@ -164,6 +164,15 @@ export function createQueries({
onGround: info?.onGround === true,
velocityMps: displayed.speedMps,
track: displayed.trackDeg,
+ // Climb/descent rate, the one kinematic field `mapAnalystRecord` already
+ // published (as `verticalRateMps`) but this descriptor did not, so a
+ // consumer reading the tracked seam had to reach back into `_flightData`
+ // for it. Reported, never derived: `stickyNumber` in records.js keeps the
+ // last value across a blank poll, and an absent rate stays null rather
+ // than becoming a level-flight 0 the aircraft never transmitted.
+ verticalRateMps: Number.isFinite(info?.verticalRate)
+ ? info.verticalRate
+ : null,
stale: Boolean(
flightState.records.missingPolls.get(icao24) ||
flightState.feed._backoff,
@@ -856,7 +865,7 @@ 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}|null}
+ * @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.
*/
getTrackedInfo() {
diff --git a/src/layers/flights/recordPolicy.js b/src/layers/flights/recordPolicy.js
index ea284cb11a..e269639d01 100644
--- a/src/layers/flights/recordPolicy.js
+++ b/src/layers/flights/recordPolicy.js
@@ -13,9 +13,4 @@ export const MISSING_POLL_LIMIT = 3;
export const ERROR_BACKOFF_INTERVAL = 20000;
/** Local equirectangular distance used for viewer-proximate floor sampling. */
-export function approxDistanceKm(lat1, lon1, lat2, lon2) {
- const dLat = (lat2 - lat1) * 111.32;
- const dLon =
- (lon2 - lon1) * 111.32 * Math.cos((((lat1 + lat2) / 2) * Math.PI) / 180);
- return Math.hypot(dLat, dLon);
-}
+export { approxDistanceKm } from '../../data/approxDistance.js';
diff --git a/src/layers/flights/recordPolicy.test.mjs b/src/layers/flights/recordPolicy.test.mjs
new file mode 100644
index 0000000000..4cf74d3cf7
--- /dev/null
+++ b/src/layers/flights/recordPolicy.test.mjs
@@ -0,0 +1,18 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import {
+ approxDistanceKm,
+ GROUND_FLOOR_CLAMP_RADIUS_KM,
+} from './recordPolicy.js';
+
+test('approximate distance takes the short way across the antimeridian', () => {
+ // 0.2° of longitude at Taveuni, Fiji (16.8° S) is about 21 km.
+ for (const [lon1, lon2] of [
+ [179.9, -179.9],
+ [-179.9, 179.9],
+ ]) {
+ const km = approxDistanceKm(-16.8, lon1, -16.8, lon2);
+ assert.ok(Math.abs(km - 21.31) < 0.01, `${lon1} → ${lon2}: ${km} km`);
+ assert.ok(km <= GROUND_FLOOR_CLAMP_RADIUS_KM);
+ }
+});
diff --git a/src/layers/installations/ingestion.js b/src/layers/installations/ingestion.js
index 664d81943c..63862ddff5 100644
--- a/src/layers/installations/ingestion.js
+++ b/src/layers/installations/ingestion.js
@@ -134,15 +134,16 @@ export function createIngestion({
let placesError = null;
if (layerState.googleSearchRequested) {
layerState.googleSearchRequested = false;
+ // A view across 180° has west > east; its width runs through 180°.
+ const lonSpan = box.east - box.west + (box.east < box.west ? 360 : 0);
const latitude = (box.south + box.north) / 2;
- const longitude = (box.west + box.east) / 2;
+ let longitude = box.west + lonSpan / 2;
+ if (longitude > 180) longitude -= 360;
const radiusM = Math.min(
50000,
Math.max(
1000,
- Math.round(
- Math.max(box.north - box.south, box.east - box.west) * 55_000,
- ),
+ Math.round(Math.max(box.north - box.south, lonSpan) * 55_000),
),
);
try {
diff --git a/src/layers/installations/ingestion.test.mjs b/src/layers/installations/ingestion.test.mjs
new file mode 100644
index 0000000000..fbb90534c0
--- /dev/null
+++ b/src/layers/installations/ingestion.test.mjs
@@ -0,0 +1,51 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { createIngestion } from './ingestion.js';
+
+// Taveuni, Fiji: Cesium reports a view across 180° with west > east. Each view
+// is 0.4° wide and 0.2° tall; the last one does not cross 180°.
+for (const [west, east, centre] of [
+ [179.7, -179.9, 179.9],
+ [179.9, -179.7, -179.9],
+ [179.5, 179.9, 179.7],
+])
+ test(`a nearby search is centred on the view at ${centre}`, async () => {
+ const box = { south: -17, west, north: -16.8, east };
+ const searches = [];
+ const state = {
+ enabled: true,
+ viewer: {},
+ records: [],
+ googleSearchRequested: true,
+ };
+ const ingestion = createIngestion({
+ state,
+ source: {
+ getMappedSites: async () => ({ records: [], wide: true }),
+ searchNearby: async (query) => {
+ searches.push(query);
+ return { places: [] };
+ },
+ },
+ services: {
+ render: { governorRequestRender() {} },
+ ground: { resolveGroundFloorCellsBounded: async () => {} },
+ },
+ parts: {
+ viewport: {
+ loadArea: () => ({ box, coverage: {} }),
+ clearUnavailableRetry() {},
+ scheduleUnavailableRetry() {},
+ },
+ model: { installationWithinViewport: () => true },
+ rendering: { renderRecords() {}, warmInstallationFloors() {} },
+ },
+ });
+ await ingestion.loadInstallations();
+ assert.equal(searches.length, 1);
+ const { latitude, longitude, radiusM } = searches[0];
+ assert.ok(Math.abs(latitude + 16.9) < 1e-9);
+ assert.ok(Math.abs(longitude - centre) < 1e-9, `longitude ${longitude}`);
+ // The width, not the height, sets the radius.
+ assert.equal(radiusM, 22000);
+ });
diff --git a/src/layers/military/queries.js b/src/layers/military/queries.js
index f3393e748b..9c106e9276 100644
--- a/src/layers/military/queries.js
+++ b/src/layers/military/queries.js
@@ -88,7 +88,7 @@ export function createQueries({
* Build a public descriptor for one aircraft using its best current position
* (dead-reckoned when history exists, billboard position otherwise).
* @param {string} icao24 - ICAO hex identifier of the aircraft.
- * @returns {{icao24: string, callsign: string|null, position: Cesium.Cartesian3, latitude: number, longitude: number, altitudeM: number, velocityMps: number|null, track: number|null}|null}
+ * @returns {{icao24: string, callsign: string|null, position: Cesium.Cartesian3, latitude: number, longitude: number, altitudeM: number, velocityMps: number|null, track: number|null, verticalRateMps: number|null}|null}
* Descriptor with a cloned position, or null if the aircraft is unknown.
*/
@@ -131,6 +131,13 @@ export function createQueries({
onGround: info?.onGround === true,
velocityMps: displayed.speedMps,
track: displayed.trackDeg,
+ // Same field, same name, same null-when-absent rule as the civil
+ // descriptor — the two layers store the record under different keys
+ // (`verticalRateMps` here, `verticalRate` there), so only the mapping
+ // makes `resolveTrackedAircraftInfo` hand back one shape for both.
+ verticalRateMps: Number.isFinite(info?.verticalRateMps)
+ ? info.verticalRateMps
+ : null,
stale: Boolean(
flightState.records.missingPolls.get(icao24) ||
flightState.feed._backoff,
@@ -777,7 +784,7 @@ 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}|null}
+ * @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.
*/
getTrackedInfo() {
diff --git a/src/layers/perimeters/cards.js b/src/layers/perimeters/cards.js
index d5505ec8d1..aef5913ce5 100644
--- a/src/layers/perimeters/cards.js
+++ b/src/layers/perimeters/cards.js
@@ -11,20 +11,26 @@ export function containmentAccent(containedPct) {
return '#8bc34a';
}
-/** Shoelace area (degree², sign dropped) — relative sizes only. */
+/** Shoelace area along short longitude edges (degree², relative sizes only). */
function ringArea(ring) {
let sum = 0;
- for (let i = 0; i < ring.length - 1; i++) {
- const [x1, y1] = ring[i];
- const [x2, y2] = ring[i + 1];
+ let [x1, y1] = ring[0];
+ for (let i = 1; i < ring.length; i++) {
+ let delta = ring[i][0] - ring[i - 1][0];
+ if (delta > 180) delta -= 360;
+ else if (delta < -180) delta += 360;
+ const x2 = x1 + delta;
+ const y2 = ring[i][1];
sum += x1 * y2 - x2 * y1;
+ x1 = x2;
+ y1 = y2;
}
return Math.abs(sum / 2);
}
/**
- * Anchor point for the incident card: the centroid of the largest polygon's
- * outer ring. Degrees, so callers own the Cartesian conversion.
+ * Anchor point for the incident card: the vertex mean of the largest polygon's
+ * outer ring, with circular longitude. Callers own the Cartesian conversion.
* @param {Array>>} polygons - Normalized rows' polygons.
* @returns {{lon: number, lat: number}}
*/
@@ -41,14 +47,17 @@ export function perimeterAnchorDegrees(polygons) {
}
// Vertex mean over the closed ring (first == last point dropped): perimeters
// are compact enough that this stays inside or near the polygon.
- let lon = 0;
+ let sinLon = 0;
+ let cosLon = 0;
let lat = 0;
const count = best.length - 1;
+ const toRad = Math.PI / 180;
for (let i = 0; i < count; i++) {
- lon += best[i][0];
+ sinLon += Math.sin(best[i][0] * toRad);
+ cosLon += Math.cos(best[i][0] * toRad);
lat += best[i][1];
}
- return { lon: lon / count, lat: lat / count };
+ return { lon: Math.atan2(sinLon, cosLon) / toRad, lat: lat / count };
}
/**
diff --git a/src/layers/perimeters/cards.test.mjs b/src/layers/perimeters/cards.test.mjs
index 1b32a5e065..0e064bff03 100644
--- a/src/layers/perimeters/cards.test.mjs
+++ b/src/layers/perimeters/cards.test.mjs
@@ -16,12 +16,79 @@ const tiny = [
[-107.01, 34.0],
];
-test('the card anchors at the centroid of the largest polygon', () => {
+test('the card anchors at the vertex mean of the largest polygon', () => {
const anchor = perimeterAnchorDegrees([[tiny], [square]]);
assert.ok(Math.abs(anchor.lon - -108.1) < 1e-9);
assert.ok(Math.abs(anchor.lat - 35.1) < 1e-9);
});
+test('incident cards stay at the dateline for closed, reversed and rotated outlines', () => {
+ const vertices = [
+ [179, 10],
+ [-179, 10],
+ [-179, 12],
+ [179, 12],
+ ];
+ for (let start = 0; start < vertices.length; start++) {
+ const rotated = [...vertices.slice(start), ...vertices.slice(0, start)];
+ for (const points of [rotated, [...rotated].reverse()]) {
+ const anchor = perimeterAnchorDegrees([[points.concat([points[0]])]]);
+ assert.ok(Math.abs(Math.abs(anchor.lon) - 180) < 1e-9);
+ assert.ok(Math.abs(anchor.lat - 11) < 1e-9);
+ }
+ }
+});
+
+test('incident card longitude treats vertices at either sign of 180 as the same meridian', () => {
+ for (const boundary of [-180, 180]) {
+ const ring = [
+ [179, 10],
+ [boundary, 10],
+ [-179, 10],
+ [-179, 12],
+ [179, 12],
+ [179, 10],
+ ];
+ const anchor = perimeterAnchorDegrees([[ring]]);
+ assert.ok(Math.abs(Math.abs(anchor.lon) - 180) < 1e-9);
+ assert.ok(Math.abs(anchor.lat - 10.8) < 1e-9);
+ }
+});
+
+test('multipart cards compare polygon areas along short dateline edges', () => {
+ const ordinary = [
+ [10, 20],
+ [11, 20],
+ [11, 21],
+ [10, 21],
+ [10, 20],
+ ];
+ for (const width of [0.2, 2]) {
+ const crossing = [
+ [180 - width / 2, 10],
+ [-180 + width / 2, 10],
+ [-180 + width / 2, 10 + width],
+ [180 - width / 2, 10 + width],
+ [180 - width / 2, 10],
+ ];
+ for (const ring of [crossing, [...crossing].reverse()]) {
+ for (const polygons of [
+ [[ring], [ordinary]],
+ [[ordinary], [ring]],
+ ]) {
+ const anchor = perimeterAnchorDegrees(polygons);
+ if (width < 1) {
+ assert.ok(Math.abs(anchor.lon - 10.5) < 1e-9);
+ assert.ok(Math.abs(anchor.lat - 20.5) < 1e-9);
+ } else {
+ assert.ok(Math.abs(Math.abs(anchor.lon) - 180) < 1e-9);
+ assert.ok(Math.abs(anchor.lat - 11) < 1e-9);
+ }
+ }
+ }
+ }
+});
+
test('a full incident row renders name, size, containment, and ages', () => {
const now = 1758000000000;
const card = buildIncidentCard(
diff --git a/src/scenes/director.js b/src/scenes/director.js
index 1a6fed403a..000c02681f 100644
--- a/src/scenes/director.js
+++ b/src/scenes/director.js
@@ -189,20 +189,22 @@ export class SceneDirector {
...this._presentation,
hasRun: !!this._lastRunJson,
}));
- this._bootstrapLegacyShotPacks();
- // Upgrade only already-installed packs; unrelated Scenes are untouched.
- for (const scene of this._project.scenes) {
- for (const marker of [...(scene.appliedShotPacks || [])]) {
- const recipe = getSceneAppendRecipeById(marker.id);
- if (
- recipe?.expansionFromVersion &&
- marker.version > 0 &&
- marker.version <= recipe.expansionFromVersion
- ) {
- this.appendShotPack(scene.id, marker.id, {
- render: false,
- announce: false,
- });
+ if (!this._storageReadError) {
+ this._bootstrapLegacyShotPacks();
+ // Upgrade only already-installed packs; unrelated Scenes are untouched.
+ for (const scene of this._project.scenes) {
+ for (const marker of [...(scene.appliedShotPacks || [])]) {
+ const recipe = getSceneAppendRecipeById(marker.id);
+ if (
+ recipe?.expansionFromVersion &&
+ marker.version > 0 &&
+ marker.version <= recipe.expansionFromVersion
+ ) {
+ this.appendShotPack(scene.id, marker.id, {
+ render: false,
+ announce: false,
+ });
+ }
}
}
}
@@ -324,13 +326,14 @@ export class SceneDirector {
'Scene not saved — existing saved project could not be read. Export edits or import a valid file.',
),
);
- return;
+ return false;
}
this._project.updatedAt = new Date().toISOString();
try {
const payload = JSON.stringify(this._project);
parseSceneDocument(payload);
localStorage.setItem(STORAGE_KEY, payload);
+ return true;
} catch (e) {
// Private browsing / block-all-cookies / quota-exceeded throws here. The
// in-memory project stays usable this session, but persistence failed —
@@ -351,6 +354,7 @@ export class SceneDirector {
})
: undefined,
);
+ return false;
}
}
@@ -923,12 +927,12 @@ export class SceneDirector {
}
this._selectedSceneId = scene.id;
this._selectedShotId = appendedShots[0]?.id || this._selectedShotId;
- this._saveProject();
+ const saved = this._saveProject();
if (render) {
this._renderSceneSelect();
this._renderShotList();
}
- if (announce) {
+ if (announce && saved) {
this._updateStatus(
marker
? tn(
@@ -984,14 +988,16 @@ export class SceneDirector {
scene.shots.push(shot);
this._selectedShotId = shot.id;
- this._saveProject();
+ const saved = this._saveProject();
this._shotOutcome('shot-captured', scene, shot);
- this._updateStatus(
- t('Captured: {scene} / {shot}', {
- scene: displaySceneTitle(scene),
- shot: displayShotTitle(shot.title, shot, scene),
- }),
- );
+ if (saved) {
+ this._updateStatus(
+ t('Captured: {scene} / {shot}', {
+ scene: displaySceneTitle(scene),
+ shot: displayShotTitle(shot.title, shot, scene),
+ }),
+ );
+ }
}
/**
@@ -1017,14 +1023,16 @@ export class SceneDirector {
shot.visual = this.styleManager.getVisualState();
shot.layers = this._captureLayerStates();
- this._saveProject();
+ const saved = this._saveProject();
this._shotOutcome('shot-updated', scene, shot);
- this._updateStatus(
- t('Updated: {scene} / {shot}', {
- scene: displaySceneTitle(scene),
- shot: displayShotTitle(shot.title, shot, scene),
- }),
- );
+ if (saved) {
+ this._updateStatus(
+ t('Updated: {scene} / {shot}', {
+ scene: displaySceneTitle(scene),
+ shot: displayShotTitle(shot.title, shot, scene),
+ }),
+ );
+ }
}
/**
@@ -1755,13 +1763,13 @@ export class SceneDirector {
) {
if (this._running) return { started: false, reason: 'already-running' };
- let queue = this._buildPlaybackQueue(
- sceneId || this._selectedSceneId || this._project.scenes[0]?.id,
- { single },
- );
+ const startSceneId =
+ sceneId || this._selectedSceneId || this._project.scenes[0]?.id;
+ let queue = this._buildPlaybackQueue(startSceneId, { single });
if (afterShotId !== null) {
const index = queue.findIndex(
- ({ scene, shot }) => scene.id === sceneId && shot.id === afterShotId,
+ ({ scene, shot }) =>
+ scene.id === startSceneId && shot.id === afterShotId,
);
if (index < 0) return { started: false, reason: 'shot-not-found' };
queue = queue.slice(index + 1);
@@ -1834,7 +1842,7 @@ export class SceneDirector {
title: 'Editable Scene Run',
startedAt: new Date().toISOString(),
estimatedDurationSec,
- scenesRun: queue.length,
+ scenesRun: new Set(queue.map(({ scene }) => scene.id)).size,
events: [],
};
@@ -1842,6 +1850,7 @@ export class SceneDirector {
this._logEvent('scene_run_start', { count: queue.length });
this._setPlaybackKeyboardEnabled(true);
+ let runResult = { started: true, shots: queue.length };
try {
await playSceneQueue(queue, {
token,
@@ -1860,9 +1869,11 @@ export class SceneDirector {
this._logEvent('scene_run_error', {
message: error.message || 'unknown error',
});
+ runResult = { started: false, reason: 'run-failed' };
} finally {
this._finishRun();
}
+ return runResult;
}
/**
@@ -2090,9 +2101,9 @@ export class SceneDirector {
this._selectedShotId =
selection?.shotId || project.scenes[0]?.shots[0]?.id || null;
this._loadedSceneId = null;
- this._saveProject();
+ const saved = this._saveProject();
this._publish({ type: 'project-imported', project });
- this._updateStatus(t('Imported {file}', { file: file.name }));
+ if (saved) this._updateStatus(t('Imported {file}', { file: file.name }));
return true;
} catch (error) {
if (
diff --git a/src/scenes/director.test.mjs b/src/scenes/director.test.mjs
index 95552025f5..f72b43dc7f 100644
--- a/src/scenes/director.test.mjs
+++ b/src/scenes/director.test.mjs
@@ -601,8 +601,12 @@ const PROJECT_FIXTURE = {
}],
};
-/** Stub the browser globals the director touches, headlessly. */
-function installSceneRuntime(project = PROJECT_FIXTURE) {
+/**
+ * Stub the browser globals the director touches, headlessly. `storage` replaces
+ * the seeded entries (key -> raw string); setting `localStorage.full` makes
+ * every write throw a quota error.
+ */
+function installSceneRuntime(project = PROJECT_FIXTURE, { storage } = {}) {
const originalDocument = globalThis.document;
const originalLocalStorage = globalThis.localStorage;
const noopClassList = { add() {}, remove() {}, toggle() {}, contains: () => false };
@@ -614,10 +618,17 @@ function installSceneRuntime(project = PROJECT_FIXTURE) {
removeEventListener() {},
body: { classList: noopClassList, appendChild() {} },
};
- const stored = new Map([['godsEyeView.sceneProject.v2', JSON.stringify(project)]]);
+ const stored = new Map(storage
+ ? Object.entries(storage)
+ : [['godsEyeView.sceneProject.v2', JSON.stringify(project)]]);
globalThis.localStorage = {
+ stored,
+ full: false,
getItem: (key) => stored.get(key) ?? null,
- setItem: (key, value) => stored.set(key, value),
+ setItem(key, value) {
+ if (this.full) throw new DOMException('quota exceeded', 'QuotaExceededError');
+ stored.set(key, value);
+ },
removeItem: (key) => stored.delete(key),
};
@@ -718,7 +729,8 @@ async function settle(turns = 8) {
/** Build a director over doubles, with the fixture project loaded. */
function makeDirector(options = {}) {
- const restore = installSceneRuntime(options.project);
+ const restore = installSceneRuntime(options.project, { storage: options.storage });
+ const storage = globalThis.localStorage;
const viewer = fakeViewer();
const styleManager = fakeStyleManager(options.style);
const dataManager = fakeDataManager(options.data);
@@ -728,7 +740,7 @@ function makeDirector(options = {}) {
// Telemetry is only accumulated during a run; observable-failure assertions
// need the accumulator without driving a whole run.
director._activeRun = { events: [] };
- return { director, viewer, styleManager, dataManager, restore };
+ return { director, viewer, styleManager, dataManager, storage, restore };
}
test('only Play Shot or a scene run grants transient media authority; LOAD, Stop and replacement revoke it', async () => {
@@ -1584,3 +1596,65 @@ test('camera refusal starts no authored frame or playback clock', async () => {
assert.deepEqual(viewer.flights, []);
} finally { restore(); }
});
+
+test('an unreadable saved project does not overwrite its recovery checkpoint (#971)', async () => {
+ const unreadable = '{"version":99,"scenes":[]}';
+ const warn = console.warn;
+ console.warn = () => {};
+ const { director, storage, restore } = makeDirector({ storage: {
+ 'godsEyeView.sceneProject.v2': unreadable,
+ 'godsEyeView.sceneProject.checkpoint.v1': 'EARLIER-CHECKPOINT',
+ } });
+ try {
+ assert.equal(storage.stored.get('godsEyeView.sceneProject.v2'), unreadable);
+ assert.equal(storage.stored.get('godsEyeView.sceneProject.checkpoint.v1'), 'EARLIER-CHECKPOINT');
+ } finally { console.warn = warn; await director.destroy(); restore(); }
+});
+
+test('a capture, update or import that cannot be saved keeps the "Scene not saved" status (#971)', async () => {
+ const warn = console.warn;
+ console.warn = () => {};
+ const { director, storage, restore } = makeDirector();
+ let status = '';
+ director.subscribe(({ state }) => { status = state.status; });
+ try {
+ storage.full = true;
+ director._selectedSceneId = 'scene-1';
+ director._selectedShotId = 'shot-a';
+ director.captureShot();
+ assert.match(status, /^Scene not saved/, 'failed capture keeps the save failure');
+ director.updateSelectedShot();
+ assert.match(status, /^Scene not saved/, 'failed update keeps the save failure');
+ assert.equal(await director.importProjectFile(
+ { name: 'fixture.json' },
+ { prepared: { project: structuredClone(PROJECT_FIXTURE), assets: [] } },
+ ), true);
+ assert.match(status, /^Scene not saved/, 'failed import keeps the save failure');
+ } finally { console.warn = warn; await director.destroy(); restore(); }
+});
+
+test('startScene resolves its result, resumes after a shot without a scene id, and counts distinct scenes (#971)', async () => {
+ const { director, restore } = makeDirector();
+ try {
+ const options = { single: true, preview: false };
+ assert.deepEqual(await director.startScene('scene-1', options), { started: true, shots: 2 });
+ assert.equal(director._lastRun.scenesRun, 1, 'one scene with two shots is one scene run');
+ assert.deepEqual(
+ await director.startScene(undefined, { ...options, afterShotId: 'shot-a' }),
+ { started: true, shots: 1 },
+ );
+ } finally { await director.destroy(); restore(); }
+});
+
+test('a caught run failure resolves as run-failed, not success (#971)', async () => {
+ const { director, styleManager, restore } = makeDirector();
+ const warn = console.warn;
+ console.warn = () => {};
+ styleManager.applyVisualState = async () => { throw new Error('visual failed'); };
+ try {
+ assert.deepEqual(
+ await director.startScene('scene-1', { single: true, preview: false }),
+ { started: false, reason: 'run-failed' },
+ );
+ } finally { console.warn = warn; await director.destroy(); restore(); }
+});
diff --git a/src/services/groundFloor.js b/src/services/groundFloor.js
index 950c1b94e9..27b7dc5e4c 100644
--- a/src/services/groundFloor.js
+++ b/src/services/groundFloor.js
@@ -204,12 +204,16 @@ export function createGroundFloor({ terrain, signal }) {
* @returns {{lat: number, lon: number}} The cell to read.
*/
function stickyFloorCell(lat, lon, previousCell) {
- if (
- previousCell &&
- Math.abs(lat - previousCell.lat) <= 0.0005 + CELL_HYSTERESIS_DEG &&
- Math.abs(lon - previousCell.lon) <= 0.0005 + CELL_HYSTERESIS_DEG
- ) {
- return previousCell;
+ if (previousCell) {
+ // The short way round, so a contact on the 180° seam keeps its cell.
+ let dLon = lon - previousCell.lon;
+ dLon -= 360 * Math.round(dLon / 360);
+ if (
+ Math.abs(lat - previousCell.lat) <= 0.0005 + CELL_HYSTERESIS_DEG &&
+ Math.abs(dLon) <= 0.0005 + CELL_HYSTERESIS_DEG
+ ) {
+ return previousCell;
+ }
}
return coarseFloorCoord(lat, lon);
}
@@ -269,17 +273,20 @@ export function createGroundFloor({ terrain, signal }) {
const a = points[s];
const b = points[s + 1];
if (![a?.lat, a?.lon, b?.lat, b?.lon].every(Number.isFinite)) continue;
+ // The short way round, so a segment across 180° walks across it.
+ let dLon = b.lon - a.lon;
+ dLon -= 360 * Math.round(dLon / 360);
const steps = Math.ceil(
- Math.max(Math.abs(b.lat - a.lat), Math.abs(b.lon - a.lon)) /
+ Math.max(Math.abs(b.lat - a.lat), Math.abs(dLon)) /
CORRIDOR_WALK_STEP_DEG,
);
for (let i = 1; i <= steps; i++) {
if (out.length >= prefixLimit) break walk;
const t = i / steps;
- const cell = coarseFloorCoord(
- a.lat + (b.lat - a.lat) * t,
- a.lon + (b.lon - a.lon) * t,
- );
+ let lon = a.lon + dLon * t;
+ if (lon > 180) lon -= 360;
+ else if (lon < -180) lon += 360;
+ const cell = coarseFloorCoord(a.lat + (b.lat - a.lat) * t, lon);
const key = `${cell.lat},${cell.lon}`;
if (seen.has(key) || key === destKey) continue;
seen.add(key);
diff --git a/src/services/meshFloorSampler.js b/src/services/meshFloorSampler.js
index b1cf65f29e..e1416d288f 100644
--- a/src/services/meshFloorSampler.js
+++ b/src/services/meshFloorSampler.js
@@ -1,4 +1,5 @@
import * as Cesium from 'cesium';
+import { approxDistanceKm } from '../data/approxDistance.js';
/** Construct an instance-owned meshFloorSampler service with explicit dependencies. */
export function createMeshFloorSampler({
@@ -79,16 +80,6 @@ export function createMeshFloorSampler({
return false;
}
- /**
- * Equirectangular distance (km) — same approximation the flights clamp uses.
- */
- function _approxKm(lat1, lon1, lat2, lon2) {
- const dLat = (lat2 - lat1) * 111.32;
- const dLon =
- (lon2 - lon1) * 111.32 * Math.cos((((lat1 + lat2) / 2) * Math.PI) / 180);
- return Math.hypot(dLat, dLon);
- }
-
/**
* Samples the rendered mesh height for the coarse cells containing `points`,
* one-shot per cell, budget-capped, viewer-proximity-gated. Call ONCE per
@@ -133,7 +124,8 @@ export function createMeshFloorSampler({
if (
Number.isFinite(viewerLat) &&
Number.isFinite(viewerLon) &&
- _approxKm(viewerLat, viewerLon, cell.lat, cell.lon) > MAX_SAMPLE_DIST_KM
+ approxDistanceKm(viewerLat, viewerLon, cell.lat, cell.lon) >
+ MAX_SAMPLE_DIST_KM
) {
continue; // too far: tiles not streamed there, probe would be a guaranteed miss
}
diff --git a/src/tools/area.js b/src/tools/area.js
index 4af62a03ce..e83db33eb2 100644
--- a/src/tools/area.js
+++ b/src/tools/area.js
@@ -323,13 +323,30 @@ export function lineTouchesArea(coords, area) {
/** Whether a point lies inside a ring of `[lon, lat]` vertices (ray casting). */
function ringContains(ring, point) {
+ if (ring.length < 3) return false;
+ // Keep adjacent vertices on the same longitude sheet, as the edge tests do.
+ // Wrapping each vertex around the query point would split a dateline ring
+ // when queried from Greenwich and mistake its complement for its interior.
+ let previous = ring[0][0];
+ let west = previous;
+ let east = previous;
+ const vertices = ring.map(([lon, lat]) => {
+ if (Math.abs(lon - previous) > 180)
+ lon += 360 * Math.round((previous - lon) / 360);
+ previous = lon;
+ west = Math.min(west, lon);
+ east = Math.max(east, lon);
+ return [lon, lat];
+ });
+ const middle = (west + east) / 2;
+ const lon = point.lon + 360 * Math.round((middle - point.lon) / 360);
let inside = false;
- for (let i = 0, j = ring.length - 1; i < ring.length; j = i, i += 1) {
- const [xi, yi] = ring[i];
- const [xj, yj] = ring[j];
+ for (let i = 0, j = vertices.length - 1; i < vertices.length; j = i, i += 1) {
+ const [xi, yi] = vertices[i];
+ const [xj, yj] = vertices[j];
if (
yi > point.lat !== yj > point.lat &&
- point.lon < ((xj - xi) * (point.lat - yi)) / (yj - yi) + xi
+ lon < ((xj - xi) * (point.lat - yi)) / (yj - yi) + xi
)
inside = !inside;
}
diff --git a/src/tools/area.test.mjs b/src/tools/area.test.mjs
index 7ec551aae1..15e4bd0062 100644
--- a/src/tools/area.test.mjs
+++ b/src/tools/area.test.mjs
@@ -262,3 +262,78 @@ test('a box radius reaches every point of the box, however large', async () => {
const small = await resolveArea({ bbox: [-97.94, 30.1, -97.56, 30.52] });
assert.ok(areaRadiusKm(small) < 30);
});
+
+test('polygon containment follows the short edges across the antimeridian', async () => {
+ const ring = [
+ [179, -2],
+ [-179, -2],
+ [-179, 2],
+ [179, 2],
+ ];
+ const areas = [
+ [{ bbox: [179.4, -0.1, 179.6, 0.1] }, true],
+ [{ bbox: [-179.6, -0.1, -179.4, 0.1] }, true],
+ [{ bbox: [179.8, -0.1, -179.8, 0.1] }, true],
+ [{ lat: 0, lon: 179.5, radius_km: 10 }, true],
+ [{ lat: 0, lon: -179.5, radius_km: 10 }, true],
+ [{ lat: 0, lon: 180, radius_km: 10 }, true],
+ [{ lat: 0, lon: -180, radius_km: 10 }, true],
+ [{ bbox: [-0.1, -0.1, 0.1, 0.1] }, false],
+ [{ lat: 0, lon: 0, radius_km: 10 }, false],
+ ];
+ for (const vertices of [
+ ring,
+ [...ring, [...ring[0]]],
+ [...ring].reverse(),
+ [...ring.slice(2), ...ring.slice(0, 2)],
+ ]) {
+ for (const [input, expected] of areas) {
+ assert.equal(
+ polygonsTouchArea([[vertices]], await resolveArea(input)),
+ expected,
+ JSON.stringify({ vertices, input }),
+ );
+ }
+ }
+});
+
+test('antimeridian polygons keep holes empty and include their boundaries', async () => {
+ const outer = [
+ [178, -3],
+ [-178, -3],
+ [-178, 3],
+ [178, 3],
+ ];
+ const hole = [
+ [179, -1],
+ [-179, -1],
+ [-179, 1],
+ [179, 1],
+ ];
+ for (const input of [
+ { bbox: [179.4, -0.1, 179.6, 0.1] },
+ { bbox: [-179.6, -0.1, -179.4, 0.1] },
+ { lat: 0, lon: 180, radius_km: 10 },
+ ]) {
+ const area = await resolveArea(input);
+ assert.ok(polygonsTouchArea([[outer]], area));
+ assert.ok(!polygonsTouchArea([[outer, hole]], area));
+ assert.ok(!polygonsTouchArea([[outer, [...hole].reverse()]], area));
+ }
+ const solid = await resolveArea({ bbox: [178.4, -0.1, 178.6, 0.1] });
+ assert.ok(polygonsTouchArea([[outer, hole]], solid));
+ const boundary = await resolveArea({ bbox: [178.9, -0.1, 179.1, 0.1] });
+ assert.ok(polygonsTouchArea([[outer, hole]], boundary));
+});
+
+test('polygon containment retains rings spanning more than half the globe', async () => {
+ const longitudes = [-170, -110, -50, 10, 70, 130];
+ const ring = [
+ ...longitudes.map((lon) => [lon, -5]),
+ ...[...longitudes].reverse().map((lon) => [lon, 5]),
+ ];
+ const inside = await resolveArea({ bbox: [99, -1, 101, 1] });
+ const outside = await resolveArea({ bbox: [169, -1, 171, 1] });
+ assert.ok(polygonsTouchArea([[ring]], inside));
+ assert.ok(!polygonsTouchArea([[ring]], outside));
+});
diff --git a/src/tools/queries/environment.js b/src/tools/queries/environment.js
index 4f653ff327..b1d0c6a86e 100644
--- a/src/tools/queries/environment.js
+++ b/src/tools/queries/environment.js
@@ -288,20 +288,25 @@ export const getFirePerimeters = defineTool({
},
});
-/** The average vertex of a perimeter's outer rings, enough to place it in an area. */
+/** Average outer-ring vertices, using a circular longitude mean at the dateline. */
function polygonCenter(polygons) {
let lat = 0;
- let lon = 0;
+ let sinLon = 0;
+ let cosLon = 0;
let count = 0;
+ const toRad = Math.PI / 180;
for (const polygon of polygons || []) {
for (const [x, y] of polygon?.[0] || []) {
if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
- lon += x;
+ sinLon += Math.sin(x * toRad);
+ cosLon += Math.cos(x * toRad);
lat += y;
count += 1;
}
}
- return count ? { lat: lat / count, lon: lon / count } : null;
+ return count
+ ? { lat: lat / count, lon: Math.atan2(sinLon, cosLon) / toRad }
+ : null;
}
export const getTerrainHeight = defineTool({
diff --git a/src/tools/queries/environment.test.mjs b/src/tools/queries/environment.test.mjs
index 9dd3d0f8cf..694b9718e2 100644
--- a/src/tools/queries/environment.test.mjs
+++ b/src/tools/queries/environment.test.mjs
@@ -227,6 +227,97 @@ test('fire perimeters are placed by their outline and sorted by size', async ()
});
});
+test('fire perimeter queries include dateline interiors and exclude the opposite meridian', async () => {
+ const perimeters = {
+ getSnapshot: async () => [
+ {
+ stableId: 'dateline',
+ name: 'Dateline Fire',
+ acres: 100,
+ polygons: [
+ [
+ [
+ [179, -2],
+ [-179, -2],
+ [-179, 2],
+ [179, 2],
+ [179, -2],
+ ],
+ ],
+ ],
+ },
+ ],
+ };
+ const catalog = catalogWith({ perimeters });
+ for (const area of [
+ { bbox: [179.4, -0.1, 179.6, 0.1] },
+ { bbox: [-179.6, -0.1, -179.4, 0.1] },
+ { lat: 0, lon: 180, radius_km: 10 },
+ ]) {
+ const result = await catalog.call('get_fire_perimeters', { area });
+ assert.deepEqual(
+ result.data.rows.map((row) => row.id),
+ ['dateline'],
+ );
+ }
+ const elsewhere = await catalog.call('get_fire_perimeters', {
+ area: { bbox: [-0.1, -0.1, 0.1, 0.1] },
+ });
+ assert.equal(elsewhere.data.total, 0);
+});
+
+test('fire perimeter coordinates stay at the dateline for closed and multipart outlines', async () => {
+ const perimeters = {
+ getSnapshot: async () => [
+ {
+ stableId: 'closed',
+ acres: 100,
+ polygons: [
+ [
+ [
+ [179, -2],
+ [-179, -2],
+ [-179, 2],
+ [179, 2],
+ [179, -2],
+ ],
+ ],
+ ],
+ },
+ {
+ stableId: 'multipart',
+ acres: 50,
+ polygons: [
+ [
+ [
+ [179, -1],
+ [179.5, -1],
+ [179.5, 1],
+ [179, 1],
+ ],
+ ],
+ [
+ [
+ [-179.5, -1],
+ [-179, -1],
+ [-179, 1],
+ [-179.5, 1],
+ ],
+ ],
+ ],
+ },
+ ],
+ };
+ const result = await catalogWith({ perimeters }).call('get_fire_perimeters', {
+ area: { bbox: [178, -3, -178, 3] },
+ });
+ assert.equal(result.data.total, 2);
+ for (const row of result.data.rows) {
+ assert.ok(Math.abs(row.lon) > 179, `${row.id}: ${row.lon}`);
+ assert.ok(Math.abs(row.lon) <= 180);
+ }
+});
+
test('terrain heights are returned in request order', async () => {
const terrain = {
async getHeights(points) {
diff --git a/src/ui/recentImagery.js b/src/ui/recentImagery.js
index 300e2536b4..857271c8bd 100644
--- a/src/ui/recentImagery.js
+++ b/src/ui/recentImagery.js
@@ -344,7 +344,6 @@ export function createRecentImageryPanel({
const detailsHost = el('div', 'ri-details', root);
detailsHost.id = 'ri-details';
let detailsOpen = false;
- let detailsShownOpen = false;
const details = createRailCards({
container: detailsHost,
document,
@@ -352,6 +351,8 @@ export function createRecentImageryPanel({
onOpen: () => {
detailsOpen = !detailsOpen;
render();
+ // After the render: preserveScroll() puts the old position back.
+ if (detailsOpen) revealCard(container, detailsHost.children[0]);
},
});
@@ -875,9 +876,6 @@ export function createRecentImageryPanel({
],
},
]);
- if (detailsOpen && !detailsShownOpen)
- revealCard(container, detailsHost.children[0]);
- detailsShownOpen = detailsOpen;
}
// ---- divider ----------------------------------------------------------
diff --git a/src/ui/recentImagery.test.mjs b/src/ui/recentImagery.test.mjs
index af1758166e..a77556797c 100644
--- a/src/ui/recentImagery.test.mjs
+++ b/src/ui/recentImagery.test.mjs
@@ -1147,6 +1147,29 @@ test('the body scroll position survives renders even when DOM mutations reset it
assert.equal(f.body.scrollTop, 120);
});
+test('opening DETAILS scrolls its card into view, and closing it does not scroll', async () => {
+ const f = fixture();
+ await f.ready();
+ // The body is 100 px high and scrolled 40 px; the card opens 150 px down.
+ f.body.scrollTop = 40;
+ f.body.clientHeight = 100;
+ f.body.getBoundingClientRect = () => ({ top: 0 });
+ const header = f
+ .byId('ri-details')
+ .find((node) => node.classList.contains('rail-card-header'));
+ const card = header.parentNode;
+ card.getBoundingClientRect = () => ({
+ top: 150,
+ height: card.dataset.open === 'true' ? 60 : 0,
+ });
+ header.click();
+ assert.equal(card.dataset.open, 'true');
+ assert.equal(f.body.scrollTop, 150);
+ header.click();
+ assert.equal(card.dataset.open, 'false');
+ assert.equal(f.body.scrollTop, 150);
+});
+
test('destroy returns every listener, the divider and the panel state', async () => {
const f = fixture();
await f.ready();