Move satellites, launches and the sky with the world time

Layers whose data has a time of its own follow the page's world clock from
the start; live feeds such as flights, military, vessels and transit stay
live. Launches register the span of the launches loaded, so turning them on
brings up the timeline. Each timed layer registers its coverage once and
reports none while off, telling the clock after each step has settled. The
launch feed keeps its own window, and an orbit ring is drawn again once the
world time has moved far from when it was drawn.
This commit is contained in:
Sameh Khamis committed 2026-11-01 22:53:51 -08:00
1 parent 690a6637e2
commit 3534398771
14 files changed
+123 -45

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ export function createControls({ state: layerState, services, parts, source }) {
*/
getAnalystRecords(maxCount = Infinity) {
if (!layerState._enabled) return [];
const now = Date.now();
const now = layerState.now();
const text = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
const result = [];
for (const launch of layerState._launches || []) {
+1
View File
@@ -222,6 +222,7 @@ export function createIngestion({
layerState._lastUpdate = Date.now();
layerState._lastError = null;
layerState._stale = stale === true;
layerState.coverageChanged();
} catch (error) {
if (layerState._enabled && token === layerState._lifecycleToken) {
layerState._lastError = error.message;
+18
View File
@@ -1,5 +1,6 @@
import * as Cesium from 'cesium';
import { isPointerFree } from '../../data/inputOwnership.js';
import { worldClock } from '../../time/worldClock.js';
const HOVER_PICK_INTERVAL_MS = 120;
@@ -119,6 +120,21 @@ export function createLifecycle({
}) {
const { holdContinuousRender, releaseContinuousRender } = services.render;
let hover = null;
// While on, the launches loaded span the time from the first to the last,
// each one a mark. Registered once; off, the layer has no time to show, and
// each step tells the clock once it has settled.
worldClock.register({
id: 'rocket-launches',
coverage: () => {
if (!layerState._enabled) return null;
const marks = layerState._launches
.map((launch) => Date.parse(launch.launchTime))
.filter(Number.isFinite)
.sort((a, b) => a - b);
if (!marks.length) return null;
return { start: marks[0], end: marks.at(-1), marks };
},
});
const methods = {
init(viewer) {
@@ -194,6 +210,7 @@ export function createLifecycle({
}
throw error;
}
layerState.coverageChanged();
},
async _enableBody() {
@@ -231,6 +248,7 @@ export function createLifecycle({
parts.overlays.clearMissionOverlaySources();
await parts.ingestion.restoreSatelliteDependency();
parts.panel.renderMissionPanel();
layerState.coverageChanged();
},
async destroy(viewer) {
+1 -1
View File
@@ -175,7 +175,7 @@ export function createModel({ state: layerState, services, parts, source }) {
* @returns {Array<object>}
*/
function normalizeRocketLaunches(payload, now = new Date(layerState.now())) {
function normalizeRocketLaunches(payload, now = new Date()) {
const launches = Array.isArray(payload) ? payload : payload?.results;
if (!Array.isArray(launches)) return [];
const cutoff = now.getTime() - WINDOW_DAYS * 86400000;
+5 -1
View File
@@ -1,5 +1,5 @@
import * as Cesium from 'cesium';
import { worldTimeFor } from '../../time/worldClock.js';
import { worldClock, worldTimeFor } from '../../time/worldClock.js';
export function createState({ services }) {
const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource } =
@@ -156,6 +156,10 @@ export function createState({ services }) {
state.orbitNow = worldTimeFor('satellites');
/** The launches loaded changed, and with them the time they cover. */
state.coverageChanged = () => worldClock.coverageChanged();
state._missionOrbitPatternRegistered = false;
state._pathDistanceCache = new WeakMap();
+1 -1
View File
@@ -170,7 +170,6 @@ export function createIngestion({
layerState._coreStale = coreStale;
layerState._count = layerState._points.size;
layerState._catalogRevision++;
layerState.coverageChanged();
layerState._lastUpdate = Date.now();
layerState._lastPropagation = Date.now();
layerState._lastTrackingRefreshOutcome = {
@@ -194,6 +193,7 @@ export function createIngestion({
// the rebuild must not block on that.
void parts.tracking._reconcileTrackedSubjectContext();
parts.tracking._applyPendingTrackingRestore();
layerState.coverageChanged();
} catch (e) {
if (updateSignal.aborted || e?.name === 'AbortError') {
throw new DOMException('Satellite update aborted', 'AbortError');
+16 -28
View File
@@ -10,30 +10,19 @@ export function createLifecycle({
}) {
const { clearFocusTarget } = services.focus;
// While on with a catalog, satellites can be shown at any time in reach of
// their element sets.
let releaseCoverage = null;
const coverWorldTime = () => {
if (releaseCoverage) return;
const release = worldClock.register({
id: 'satellites',
coverage: () => {
if (!layerState._catalog.size) return null;
const now = worldClock.wallNow();
return {
start: now - SATELLITE_COVERAGE_MS,
end: now + SATELLITE_COVERAGE_MS,
};
},
});
// Registering tells the world's listeners, which may turn the layer off
// (or off and on, registering again) before this returns.
if (layerState._enabled && !releaseCoverage) releaseCoverage = release;
else release();
};
const uncoverWorldTime = () => {
releaseCoverage?.();
releaseCoverage = null;
};
// their element sets. Registered once; off, the layer has no time to show,
// and each step tells the clock once it has settled.
worldClock.register({
id: 'satellites',
coverage: () => {
if (!layerState._enabled || !layerState._catalog.size) return null;
const now = worldClock.wallNow();
return {
start: now - SATELLITE_COVERAGE_MS,
end: now + SATELLITE_COVERAGE_MS,
};
},
});
const { holdContinuousRender, releaseContinuousRender } = services.render;
const { registerPickOwner, unregisterPickOwner } = services.picking;
@@ -91,7 +80,6 @@ export function createLifecycle({
enable(viewer) {
layerState._enabled = true;
coverWorldTime();
holdContinuousRender('satellites'); // per-frame animator (perf wave 2)
if (layerState._pointCollection)
layerState._pointCollection.show =
@@ -120,13 +108,13 @@ export function createLifecycle({
);
}
parts.tracking._applyPendingTrackingRestore();
layerState.coverageChanged();
},
disable(viewer) {
parts.catalog._abortActiveUpdates();
parts.tracking._cancelPendingTrackingRestore();
layerState._enabled = false;
uncoverWorldTime();
releaseContinuousRender('satellites');
if (layerState._pointCollection) layerState._pointCollection.show = false;
for (const path of layerState._orbitPaths.values())
@@ -148,13 +136,13 @@ export function createLifecycle({
layerState._preRenderListener();
layerState._preRenderListener = null;
}
layerState.coverageChanged();
},
destroy(viewer) {
parts.catalog._abortActiveUpdates();
releaseContinuousRender('satellites'); // direct-destroy path (perf wave 2 fix)
layerState._enabled = false;
uncoverWorldTime();
parts.tracking._clearTracking();
parts.tracking._cancelPendingTrackingRestore();
if (layerState._clickHandler) {
@@ -191,7 +179,6 @@ export function createLifecycle({
layerState._denseStatus = 'idle';
layerState._denseError = null;
layerState._catalogRevision++;
layerState.coverageChanged();
layerState._rowControlsListener = null;
layerState._count = 0;
layerState._lastUpdate = null;
@@ -207,6 +194,7 @@ export function createLifecycle({
failedGroups: [],
};
layerState._viewer = null;
layerState.coverageChanged();
},
};
+7
View File
@@ -30,6 +30,13 @@ export const ORBIT_PATH_STEPS = 180;
export const POSITION_UPDATE_MS = 1000;
/** How far either side of now SGP4 on current element sets stays meaningful. */
export const SATELLITE_COVERAGE_MS = 14 * 24 * 3_600_000;
/**
* How far the world time may move from when an orbit ring was drawn before it
* is drawn again: the Earth's turn is followed exactly, but the orbit's plane
* drifts a few degrees a day.
*/
export const ORBIT_REBAKE_MS = 30 * 60_000;
// re-propagate every 1s (SGP4 is smooth at this rate)
export const RING_ROTATION_MS = 1000;
+16 -2
View File
@@ -1,6 +1,11 @@
import * as Cesium from 'cesium';
import { gstime } from 'satellite.js';
import { ISS_NORAD, POSITION_UPDATE_MS, RING_ROTATION_MS } from './policy.js';
import {
ISS_NORAD,
ORBIT_REBAKE_MS,
POSITION_UPDATE_MS,
RING_ROTATION_MS,
} from './policy.js';
export function createRendering({
state: layerState,
@@ -75,6 +80,8 @@ export function createRendering({
layerState._orbitPaths.set(noradId, {
primitive,
color: pathColor,
bakeMs: bakeDate.getTime(),
// Same Date object as computeOrbitPath's internal fixedGmst → identical
// GMST value (gstime is pure), so delta starts at exactly 0 and the
// initial identity modelMatrix is correct until the first ring tick.
@@ -113,8 +120,15 @@ export function createRendering({
function _updateOrbitPathRotations(nowDate) {
if (layerState._orbitPaths.size === 0) return;
for (const path of layerState._orbitPaths.values()) {
for (const [noradId, path] of [...layerState._orbitPaths]) {
if (!path.primitive) continue;
// The rotation keeps the ring under the dot for minutes; the plane
// itself precesses, so a world time moved far from the bake re-bakes.
if (Math.abs(nowDate.getTime() - path.bakeMs) > ORBIT_REBAKE_MS) {
_hideOrbitPath(noradId);
_showOrbitPath(noradId, path.color);
continue;
}
parts.orbits.orbitFrameModelMatrix(
path.gmstAtBake,
nowDate,