mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 03:32:19 +00:00
Show JTWC cyclones: western Pacific, Indian Ocean and Southern Hemisphere (#1891)
* Show JTWC warnings in Cyclone advisories Cyclone advisories now also read the Joint Typhoon Warning Center (keyless, public domain) for the western North Pacific, North Indian Ocean and Southern Hemisphere, beside NHC and CPHC. - server/providers/jtwc.js reads JTWC's warnings feed, each storm's JMV 3.0 warning (.tcw) and its overlay (.kmz). /api/cyclones merges them with NHC's: one storm per id, NHC's advisory where NHC lists the storm. A failed JTWC read keeps its last storms, marked stale, and never hides NHC's. - Storms carry an agency. A JTWC warning has no cone; its 34-knot wind danger area is drawn as its own dashed area and named for the selected storm. - A JTWC storm's card notes that the regional centre's warning is official and that JTWC winds are 1-minute averages. Source and coverage wording names both agencies. - Each storm is served while its own advisory is usable (12 hours for NHC, 13 for JTWC). * Keep one JTWC failure from affecting other storms or NHC - A storm whose JTWC warning cannot be read or parsed is left out and the others are shown; the read fails only when every listed storm's does. - JTWC is read under its own 8-second deadline. A failed or slow JTWC read keeps JTWC's last good storms and never delays, fails or stales the NHC answer. - Danger-swath longitudes past ±180 (a ring crossing the antimeridian) are wrapped into -180..180 instead of dropping the ring. * Add the changelog entry for JTWC cyclones
This commit is contained in:
1 parent
ae212e5b63
commit
5608b12a25
33 files changed
+1699
-201
No files matched your search
@@ -3,6 +3,7 @@ import { sphereFromPoints } from '../../geo/sphere.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
import {
|
||||
CYCLONE_ACCENT,
|
||||
CYCLONE_DANGER_ACCENT,
|
||||
CYCLONE_MARKER_PX,
|
||||
CYCLONE_SELECTED_ACCENT,
|
||||
createCycloneLabels,
|
||||
@@ -24,6 +25,29 @@ export function coherentCycloneGeometry(storm) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a danger area's label sits: the vertex of its outer ring nearest the
|
||||
* forecast point halfway along the track (ECEF).
|
||||
*/
|
||||
function dangerAreaAnchor(ring, forecastPoints, ecef, lonLat) {
|
||||
const middle = forecastPoints[Math.floor(forecastPoints.length / 2)];
|
||||
if (!middle) return ring[0];
|
||||
const target = ecef(lonLat(middle.position));
|
||||
let best = ring[0],
|
||||
bestDistance = Infinity;
|
||||
for (const vertex of ring) {
|
||||
const d =
|
||||
(vertex.x - target.x) ** 2 +
|
||||
(vertex.y - target.y) ** 2 +
|
||||
(vertex.z - target.z) ** 2;
|
||||
if (d < bestDistance) {
|
||||
best = vertex;
|
||||
bestDistance = d;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/** A `#rrggbb` colour at `alpha`, as CSS. */
|
||||
function withAlpha(hex, alpha) {
|
||||
const n = Number.parseInt(hex.slice(1), 16);
|
||||
@@ -64,7 +88,14 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
forecasts = [],
|
||||
spheres = new Map(),
|
||||
itemStorms = new Map();
|
||||
let counts = { storms: 0, tracks: 0, cones: 0, forecastPoints: 0 };
|
||||
const emptyCounts = () => ({
|
||||
storms: 0,
|
||||
tracks: 0,
|
||||
cones: 0,
|
||||
dangerAreas: 0,
|
||||
forecastPoints: 0,
|
||||
});
|
||||
let counts = emptyCounts();
|
||||
let itemCount = 0;
|
||||
|
||||
function centerItem(storm) {
|
||||
@@ -104,7 +135,7 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
nextLines = [],
|
||||
nextCones = [],
|
||||
nextLabels = [];
|
||||
const nextCounts = { storms: 0, tracks: 0, cones: 0, forecastPoints: 0 };
|
||||
const nextCounts = emptyCounts();
|
||||
const lonLat = ({ longitude, latitude }) => ({
|
||||
lon: longitude,
|
||||
lat: latitude,
|
||||
@@ -130,6 +161,7 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
windKt: storm.windKt,
|
||||
position: center,
|
||||
forecasts: [],
|
||||
dangerArea: null,
|
||||
};
|
||||
nextLabels.push(label);
|
||||
nextCounts.storms++;
|
||||
@@ -151,38 +183,66 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
});
|
||||
nextCounts.tracks++;
|
||||
});
|
||||
const polygons =
|
||||
storm.cone?.type === 'Polygon'
|
||||
? [storm.cone.coordinates]
|
||||
: storm.cone?.coordinates || [];
|
||||
polygons.forEach((rings, index) => {
|
||||
// Each exterior retains its own interior holes. Native geographic
|
||||
// tessellation handles the antimeridian; never flatten rings.
|
||||
const all = rings.map((ring) => ring.map(pair));
|
||||
const ecefRings = all.map((ring) => ring.map(ecef));
|
||||
extent.push(...ecefRings[0]);
|
||||
nextCones.push({
|
||||
id: own(`cyclone:${storm.id}:cone:${index}`),
|
||||
geometry: { kind: 'polygon', rings: all },
|
||||
fill: withAlpha(CYCLONE_ACCENT, 0.16),
|
||||
height: 'clampGround',
|
||||
});
|
||||
ecefRings.forEach((ring, ringIndex) => {
|
||||
nextLines.push({
|
||||
id: own(
|
||||
`cyclone:${storm.id}:cone:${index}:outline:${ringIndex}`,
|
||||
),
|
||||
positions: ring,
|
||||
widthPx: 1,
|
||||
mode: 'draped',
|
||||
style: {
|
||||
kind: 'solid',
|
||||
color: withAlpha(CYCLONE_ACCENT, 0.55),
|
||||
},
|
||||
// NHC's cone of centre-track uncertainty, or JTWC's 34-knot wind
|
||||
// danger area: drawn apart, never one as the other.
|
||||
const areas = [
|
||||
{ kind: 'cone', shape: storm.cone, color: CYCLONE_ACCENT },
|
||||
{
|
||||
kind: 'danger',
|
||||
shape: storm.dangerArea,
|
||||
color: CYCLONE_DANGER_ACCENT,
|
||||
},
|
||||
];
|
||||
for (const { kind, shape, color } of areas) {
|
||||
const polygons =
|
||||
shape?.type === 'Polygon'
|
||||
? [shape.coordinates]
|
||||
: shape?.coordinates || [];
|
||||
polygons.forEach((rings, index) => {
|
||||
// Each exterior retains its own interior holes. Native
|
||||
// geographic tessellation handles the antimeridian; never
|
||||
// flatten rings.
|
||||
const all = rings.map((ring) => ring.map(pair));
|
||||
const ecefRings = all.map((ring) => ring.map(ecef));
|
||||
extent.push(...ecefRings[0]);
|
||||
nextCones.push({
|
||||
id: own(`cyclone:${storm.id}:${kind}:${index}`),
|
||||
geometry: { kind: 'polygon', rings: all },
|
||||
fill: withAlpha(color, kind === 'cone' ? 0.16 : 0.12),
|
||||
height: 'clampGround',
|
||||
});
|
||||
ecefRings.forEach((ring, ringIndex) => {
|
||||
nextLines.push({
|
||||
id: own(
|
||||
`cyclone:${storm.id}:${kind}:${index}:outline:${ringIndex}`,
|
||||
),
|
||||
positions: ring,
|
||||
widthPx: kind === 'cone' ? 1 : 1.5,
|
||||
mode: 'draped',
|
||||
style:
|
||||
kind === 'cone'
|
||||
? { kind: 'solid', color: withAlpha(color, 0.55) }
|
||||
: {
|
||||
kind: 'dash',
|
||||
color: withAlpha(color, 0.8),
|
||||
length: 16,
|
||||
},
|
||||
});
|
||||
});
|
||||
if (kind === 'cone') nextCounts.cones++;
|
||||
else {
|
||||
nextCounts.dangerAreas++;
|
||||
// The area's name sits on its edge nearest the middle of
|
||||
// the forecast track.
|
||||
label.dangerArea ??= dangerAreaAnchor(
|
||||
ecefRings[0],
|
||||
storm.forecastPoints,
|
||||
ecef,
|
||||
lonLat,
|
||||
);
|
||||
}
|
||||
});
|
||||
nextCounts.cones++;
|
||||
});
|
||||
}
|
||||
for (const [index, point] of storm.forecastPoints.entries()) {
|
||||
if (point.tauHours === 0) continue;
|
||||
const pos = lonLat(point.position);
|
||||
@@ -252,7 +312,7 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
itemStorms = new Map();
|
||||
itemCount = 0;
|
||||
selected = null;
|
||||
counts = { storms: 0, tracks: 0, cones: 0, forecastPoints: 0 };
|
||||
counts = emptyCounts();
|
||||
},
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
|
||||
Reference in new issue
Block a user