mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
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.
112 lines
3.3 KiB
JavaScript
112 lines
3.3 KiB
JavaScript
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).
|
|
const msg = (text) => text;
|
|
|
|
const DIRECTIONS = [
|
|
msg('N'),
|
|
msg('NNE'),
|
|
msg('NE'),
|
|
msg('ENE'),
|
|
msg('E'),
|
|
msg('ESE'),
|
|
msg('SE'),
|
|
msg('SSE'),
|
|
msg('S'),
|
|
msg('SSW'),
|
|
msg('SW'),
|
|
msg('WSW'),
|
|
msg('W'),
|
|
msg('WNW'),
|
|
msg('NW'),
|
|
msg('NNW'),
|
|
];
|
|
export const WIND_UNITS = Object.freeze({
|
|
'km/h': 3.6,
|
|
'm/s': 1,
|
|
mph: 2.2369362921,
|
|
});
|
|
|
|
/** Meteorological bearing is where the wind comes FROM, not where it travels. */
|
|
export function windFrom(u, v) {
|
|
if (Math.hypot(u, v) < 0.2) return 'Calm';
|
|
const bearing = ((Math.atan2(-u, -v) * 180) / Math.PI + 360) % 360;
|
|
return DIRECTIONS[Math.round(bearing / 22.5) % 16];
|
|
}
|
|
|
|
export function formatWindSpeed(speed, units = 'km/h') {
|
|
const unit = Object.hasOwn(WIND_UNITS, units) ? units : 'km/h';
|
|
return `${(speed * WIND_UNITS[unit]).toFixed(1)} ${unit}`;
|
|
}
|
|
|
|
/**
|
|
* 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,
|
|
{ query, canvas } = {},
|
|
{ units, overlay, model, validTime, status, position } = {},
|
|
) {
|
|
const point =
|
|
position ||
|
|
(canvas &&
|
|
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'),
|
|
model,
|
|
validTime,
|
|
status,
|
|
explanation: msg(
|
|
'A location reading needs a loaded forecast and the Earth at the center of the view.',
|
|
),
|
|
};
|
|
const { lon, lat } = location;
|
|
const vector = sampleWind(
|
|
{ ...snapshot.grid, u: snapshot.u, v: snapshot.v },
|
|
lon,
|
|
lat,
|
|
);
|
|
const speed = windSpeed(vector.u, vector.v);
|
|
const from = windFrom(vector.u, vector.v);
|
|
const scalar = ['temperature', 'pressure'].includes(overlay)
|
|
? sampleScalar(snapshot, lon, lat, overlay)
|
|
: null;
|
|
return {
|
|
position: point,
|
|
speed,
|
|
from,
|
|
units,
|
|
coordinates: `${Math.abs(lat).toFixed(2)}°${lat < 0 ? 'S' : 'N'} · ${Math.abs(lon).toFixed(2)}°${lon < 0 ? 'W' : 'E'}`,
|
|
wind: `${formatWindSpeed(speed, units)}${from === 'Calm' ? ' · calm' : ` from ${from}`}`,
|
|
scalarKind: overlay,
|
|
scalarLabel:
|
|
overlay === 'speed'
|
|
? msg('Wind speed')
|
|
: overlay === 'temperature'
|
|
? msg('Air temperature · 2 m')
|
|
: overlay === 'pressure'
|
|
? msg('Sea-level pressure')
|
|
: null,
|
|
scalarValue:
|
|
overlay === 'speed'
|
|
? formatWindSpeed(speed, units)
|
|
: scalar == null
|
|
? null
|
|
: `${scalar.toFixed(1)} ${overlay === 'temperature' ? '°C' : 'hPa'}`,
|
|
model,
|
|
validTime,
|
|
status,
|
|
explanation: msg(
|
|
'Interpolated model forecast on an approximately 1° grid. Broad weather patterns, not a street-level measurement.',
|
|
),
|
|
};
|
|
}
|