From b774bd84c8c8fa2896f7bbad0aaf4e4bb0b44f31 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 7 Nov 2026 01:47:55 -0800 Subject: [PATCH] Read the weather layers' camera and map centre through the renderer's ports The weather layers listen for the camera's moveEnd through the camera port, find the map centre through the query port's ellipsoid pick and the app's WGS84 helpers, and fly through the port's cameraOf. The shell rendering part, which stays Cesium-bound, now defaults the Cesium namespace, provides the fallback globe imagery host, and loads the adapter factories for a viewer with no renderer bound. The weather entry leaves the allow-list. It still reads the viewer's canvas size for the centre pick. --- src/layers/weather/display.test.mjs | 28 +++++++++++-------- src/layers/weather/index.js | 41 +++++++++++----------------- src/layers/weather/shellRendering.js | 18 +++++++++++- src/layers/weather/weather.test.mjs | 3 ++ src/render/cesiumAllowList.json | 1 - 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/src/layers/weather/display.test.mjs b/src/layers/weather/display.test.mjs index 603493226..72f0753c9 100644 --- a/src/layers/weather/display.test.mjs +++ b/src/layers/weather/display.test.mjs @@ -8,6 +8,7 @@ import { createShellScene } from './shellFixture.mjs'; import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs'; import { formatScaleLabel } from '../../ui/unitLabels.js'; import { bindFakeCesiumCamera } from '../../testSupport/fakeCameraPort.mjs'; +import { fromDegrees } from '../../geo/ellipsoid.js'; import { fakeSceneFrame } from '../../testSupport/fakeCesiumScene.mjs'; const times = ['2026-09-15T20:00:00.000Z', '2026-09-15T20:05:00.000Z']; @@ -61,20 +62,23 @@ async function shownLayer(id, manifest, params, view = {}) { }), }); layer.init( - bindFakeCesiumCamera({ - camera: { - moveEnd: { addEventListener: () => () => {} }, - flyTo: ({ destination }) => flights.push(destination), - pickEllipsoid: () => - view.center - ? Cesium.Cartesian3.fromDegrees(...view.center) - : undefined, + bindFakeCesiumCamera( + { + camera: { + moveEnd: { addEventListener: () => () => {} }, + flyTo: ({ destination }) => flights.push(destination), + }, + scene: { canvas: { clientWidth: 800, clientHeight: 600 } }, }, - scene: { - canvas: { clientWidth: 800, clientHeight: 600 }, - globe: { ellipsoid: Cesium.Ellipsoid.WGS84 }, + { + query: { + pickEllipsoid: (x, y) => + x === 400 && y === 300 && view.center + ? fromDegrees(...view.center) + : null, + }, }, - }), + ), ); if (params) layer.setParams(params); layer.enable(); diff --git a/src/layers/weather/index.js b/src/layers/weather/index.js index a662ca1ee..1c046141d 100644 --- a/src/layers/weather/index.js +++ b/src/layers/weather/index.js @@ -1,6 +1,5 @@ -import * as Cesium from 'cesium'; import { createWeatherRendering } from './rendering.js'; -import { createWeatherShell } from './shellRendering.js'; +import { createWeatherShell, globeImageryHost } from './shellRendering.js'; import { imageryHostStatus } from './imageryHost.js'; import { weatherDisplay, insideExtent } from './display.js'; import { @@ -11,10 +10,8 @@ import { } from './clock.js'; import { formatUtcDayMonth, t, msg } from '../../i18n/index.js'; import { formatScaleLabel } from '../../ui/unitLabels.js'; -import { cameraOf } from '../../render/cesium/camera.js'; -// The renderer drapes through `findGlobe`; a viewer with no renderer bound -// gets its globe port from the factory this module provides. -import '../../render/cesium/globe.js'; +import { toLonLatH } from '../../geo/ellipsoid.js'; +import { cameraOf, findCamera, findQuery } from '../../render/rendererOf.js'; /** * A stored (English) failure in the language. HTTP failures from source.js @@ -62,7 +59,6 @@ export function createWeatherLayer({ feed, clock, id = 'weather-radar', - cesium = Cesium, createRendering = createWeatherRendering, documentRef = globalThis.document, eventTarget = globalThis.window, @@ -108,8 +104,7 @@ export function createWeatherLayer({ : REGIONAL_INFRARED_MAX_GAP_MS; const isLatest = () => clock ? clock.getState().mode === 'latest' : followLatest; - const getHost = () => - imageryHost?.() ?? { collection: viewer?.imageryLayers, kind: 'globe' }; + const getHost = () => imageryHost?.() ?? globeImageryHost(viewer); const notify = () => listener?.(); const shownTime = () => (noFrame ? null : rendering?.getDiagnostics().time); const unsubscribeClock = clock?.subscribe(() => { @@ -288,7 +283,7 @@ export function createWeatherLayer({ viewer = nextViewer; rendering = createRendering({ viewer, - createShell: (options) => createWeatherShell({ ...options, cesium }), + createShell: createWeatherShell, getHost, onChange: notify, }); @@ -318,10 +313,11 @@ export function createWeatherLayer({ enable() { enabled = true; if (!removeCamera) { - removeCamera = viewer.camera.moveEnd?.addEventListener(() => { - checkHost(); - notify(); - }); + removeCamera = + findCamera(viewer)?.on('moveEnd', () => { + checkHost(); + notify(); + }) ?? null; } registerClock(); }, @@ -587,18 +583,13 @@ export function createWeatherLayer({ const canvas = viewer?.scene?.canvas; const point = canvas && - viewer.camera.pickEllipsoid?.( - new cesium.Cartesian2( - canvas.clientWidth / 2, - canvas.clientHeight / 2, - ), - viewer.scene.globe.ellipsoid, + findQuery(viewer)?.pickEllipsoid( + canvas.clientWidth / 2, + canvas.clientHeight / 2, ); - const camera = point - ? cesium.Cartographic.fromCartesian(point, viewer.scene.globe.ellipsoid) - : null; - const lon = camera ? cesium.Math.toDegrees(camera.longitude) : 0; - const lat = camera ? cesium.Math.toDegrees(camera.latitude) : 0; + const camera = point ? toLonLatH(point) : null; + const lon = camera ? camera.lon : 0; + const lat = camera ? camera.lat : 0; const outside = b && camera && diff --git a/src/layers/weather/shellRendering.js b/src/layers/weather/shellRendering.js index 9def82c43..71ad2fca7 100644 --- a/src/layers/weather/shellRendering.js +++ b/src/layers/weather/shellRendering.js @@ -1,8 +1,24 @@ +import * as Cesium from 'cesium'; +// The weather layers fly through `cameraOf`, drape through `findGlobe` and +// read `findCamera` and `findQuery`; this module is their Cesium side, so it +// brings the factories a viewer with no renderer bound gets those ports from. +import '../../render/cesium/camera.js'; +import '../../render/cesium/globe.js'; import { acquireWeatherImage } from './infraredImage.js'; import { imageryHostStatus } from './imageryHost.js'; import { WEATHER_DETAIL_SIZE, WEATHER_IMAGE_SIZES } from './source.js'; import { msg } from '../../i18n/index.js'; +/** + * The viewer's own globe imagery, as a weather imagery host: where a layer + * drapes when the application shell names no host of its own. + * @param {object|null|undefined} viewer A Cesium viewer. + * @returns {{collection: object|undefined, kind: 'globe'}} + */ +export function globeImageryHost(viewer) { + return { collection: viewer?.imageryLayers, kind: 'globe' }; +} + /** Metres above the ellipsoid. Lower shells draw first, so lightning draws last. */ export const WEATHER_SHELL_HEIGHTS = Object.freeze({ wind: 5_000, @@ -394,7 +410,7 @@ export function detailWindow(footprint, bounds, previous = null) { * that area, so the two images share one mesh and never blend. */ export function createWeatherShell({ viewer, - cesium, + cesium = Cesium, product, height = WEATHER_SHELL_HEIGHTS[product], getHost = () => ({ collection: null, kind: 'tileset' }), diff --git a/src/layers/weather/weather.test.mjs b/src/layers/weather/weather.test.mjs index f2c5da209..d4a2a726d 100644 --- a/src/layers/weather/weather.test.mjs +++ b/src/layers/weather/weather.test.mjs @@ -11,6 +11,7 @@ import { WEATHER_IMAGERY_Z } from './imageryOrder.js'; import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs'; import { fakeSceneFrame } from '../../testSupport/fakeCesiumScene.mjs'; import { createCesiumGlobe } from '../../render/cesium/globe.js'; +import { bindRenderer } from '../../render/rendererOf.js'; import { createShellCesium, createShellScene, @@ -598,6 +599,7 @@ function layerHarness({ }), }; const viewer = { camera: { moveEnd } }; + bindRenderer(viewer, { camera: cameraOver(viewer) }); const layer = createWeatherLayer({ clock, id, @@ -1411,6 +1413,7 @@ for (const [id, product] of [ positionCartographic: { height: 1200 }, }; h.viewer.camera = camera; + bindRenderer(h.viewer, { camera: cameraOver(h.viewer) }); const events = target(); const layer = createWeatherLayer({ id, diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index ee8520b4a..94d45f3c7 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -94,7 +94,6 @@ "src/layers/transit/lifecycle.js", "src/layers/transit/rendering.js", "src/layers/transit/testing.js", - "src/layers/weather/index.js", "src/layers/weather/shellRendering.js", "src/layers/wind/gpuRendering.js", "src/layers/wind/relief.js",