Read the wind layer's map-centre reading and its marker through the query and frame ports

The wind reading at the map centre now asks the renderer's query port where
the ellipsoid lies under the middle of the canvas and converts it with the app's
WGS84 helpers, instead of Cesium's camera pick and Cartographic. The
inspection marker projects its point with the query port, hides it beyond
the ellipsoid's horizon with isOccluded, and follows rendered frames through
the frame port's postRender phase instead of the scene's event. The layer
entry no longer carries a Cesium namespace: the rendering part, which stays
Cesium-bound, defaults it, owns the fallback globe imagery host, and loads
the adapter factories a viewer with no renderer bound gets its ports from.

The wind entry, its inspection reading and its marker leave the allow-list.
They still read the viewer's canvas size and container element.
This commit is contained in:
Sameh Khamis committed 2026-11-07 01:50:42 -08:00
1 parent f0e5540561
commit 03ff8f291f
9 files changed
+121 -121

No files matched your search

+11 -14
View File
@@ -1,5 +1,6 @@
import { sampleWind, windSpeed } from './model.js';
import { sampleScalar } from './fields.js';
import { toLonLatH } from '../../geo/ellipsoid.js';
// The reading stays English: AI tools read it too. Text is marked for i18n
// extraction and translated where the WEATHER card shows it (presentation.js).
@@ -41,24 +42,22 @@ export function formatWindSpeed(speed, units = 'km/h') {
return `${(speed * WIND_UNITS[unit]).toFixed(1)} ${unit}`;
}
/** A deliberate snapshot at the map center; does not own pointer input. */
/**
* A deliberate snapshot at the map center; does not own pointer input. The
* center is where `view.query` (a renderer query port) meets the ellipsoid
* under the middle of `view.canvas`, unless `position` (ECEF) is given.
*/
export function inspectWindAtCenter(
snapshot,
viewer,
cesium,
{ query, canvas } = {},
{ units, overlay, model, validTime, status, position } = {},
) {
const scene = viewer?.scene;
const canvas = scene?.canvas;
const ellipsoid = scene?.globe?.ellipsoid || cesium.Ellipsoid?.WGS84;
const point =
position ||
(canvas &&
viewer.camera?.pickEllipsoid?.(
new cesium.Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2),
ellipsoid,
));
if (!point || !snapshot?.u || !snapshot?.v)
query?.pickEllipsoid(canvas.clientWidth / 2, canvas.clientHeight / 2));
const location = point && snapshot?.u && snapshot?.v && toLonLatH(point);
if (!location)
return {
coordinates: msg('No surface reading'),
wind: msg('Aim the map center at Earth'),
@@ -69,9 +68,7 @@ export function inspectWindAtCenter(
'A location reading needs a loaded forecast and the Earth at the center of the view.',
),
};
const location = cesium.Cartographic.fromCartesian(point, ellipsoid);
const lon = cesium.Math.toDegrees(location.longitude);
const lat = cesium.Math.toDegrees(location.latitude);
const { lon, lat } = location;
const vector = sampleWind(
{ ...snapshot.grid, u: snapshot.u, v: snapshot.v },
lon,