@aeroswarm/weather-layer

中文文档
0.12.0发布于 2026/11/04TypeScriptES Module零依赖近 30 天下载 3395

Animated weather overlay (wind, clouds, rain, fog, lightning) for LuciadRIA maps, driven by @aeroswarm/weather.

原始使用文档
文档目录9 节
  1. A. Flat overlay (2D and 3D)
  2. B. 3D clouds at real altitude
  3. C. Windy-style fields (flow particles + colour maps)
  4. D. Other maps (MapLibre, Leaflet, CesiumJS)
  5. E. Ready-made UI ( /react-ui )
  6. F. Sea layers and extra data (flow layers, providers)
  7. G. Clip a layer to polygons (mask)
  8. Documentation
  9. Limits

@aeroswarm/weather-layer

Animated weather on a map: wind particles, clouds, rain/snow, fog and lightning, plus sea layers (waves, ocean currents, sea level). It takes the AnimationState produced by @aeroswarm/weather (decoded METAR/SPECI/TAF) and fields from @aeroswarm/marine, and draws them. No network access. Works with LuciadRIA, MapLibre/Mapbox GL, Leaflet and CesiumJS (section D).

A. Flat overlay (2D and 3D)

import { animationSnapshot } from "@aeroswarm/weather";
import { createWeatherOverlay } from "@aeroswarm/weather-layer";

const overlay = createWeatherOverlay(map);          // transparent canvases on map.domNode
const snapshot = animationSnapshot({ observation: metar, forecast: taf });
if (snapshot) overlay.setState(snapshot.state);

overlay.setVisible(false);                           // toggle from your layer panel
overlay.setOpacity(0.8);
overlay.destroy();

React:

import { useWeatherOverlay } from "@aeroswarm/weather-layer/react";

useWeatherOverlay(map, snapshot?.state, { visible, opacity });

Wind direction follows the map rotation (mapScreenOffset; override with getScreenOffset). The overlay is a canvas above the map, so it is not part of map.layerTree: wire its visible and opacity to your own layer panel. Honours prefers-reduced-motion (draws a still frame).

B. 3D clouds at real altitude

import { FeatureLayer } from "@mid/ria/view/feature/FeatureLayer";
import { createCloudLayer3D } from "@aeroswarm/weather-layer";

const clouds = createCloudLayer3D(
  { reference, Feature, FeatureModel, MemoryStore, FeatureLayer, FeaturePainter, createPoint },
  { center: { lat: -7.3798, lon: 112.7869 }, elevationM: 3 },
);
map.layerTree.addChild(clouds.layer);
clouds.setState(snapshot.state);

Cloud height = aerodrome elevation + cloud base above ground level (METAR reports AGL). Sprites are sized in metres, so they scale with zoom and perspective. Drawn only when the map is 3D (EPSG:4978) unless only3D: false. The RIA classes are passed in so this package never bundles its own copy of RIA.

C. Windy-style fields (flow particles + colour maps)

Wind particles that follow a gridded wind field, coloured by speed, plus colour maps for cloud cover, rain or temperature. The grid can come from anywhere (see @aeroswarm/weather: windGridFromStations for several METARs, parseGrib2Json, parseGridJson, stationWindsFromModelPoints).

import { createFieldOverlay, createRiaUnproject, PRECIPITATION_RAMP } from "@aeroswarm/weather-layer";

const unproject = createRiaUnproject(map, { wgs84, createPoint, createTransformation });
const overlay = createFieldOverlay(map, { unproject });

overlay.setWind(windGrid);                                  // particles
overlay.setScalar(cloudGrid);                                // cloud cover (default ramp)
overlay.setScalar(rainGrid, PRECIPITATION_RAMP);             // or rain, temperature, ...

The field is mapped onto a screen grid whenever the map moves (throttled), so the particles read a small array instead of projecting every particle on every frame. Points that are not on the map (3D: off the globe) have no wind.

D. Other maps (MapLibre, Leaflet, CesiumJS)

The package core never imports a map library. A map is described by a small MapAdapter (container, unproject(x, y), screenOffset(), onChange(cb)), and each map has an adapter on its own subpath. Adapters only call methods on the map object you pass in, so there is nothing extra to install and importing /maplibre never pulls Cesium or RIA.

import { createFieldOverlay } from "@aeroswarm/weather-layer";
import { maplibreAdapter } from "@aeroswarm/weather-layer/maplibre";   // also works with Mapbox GL
const overlay = createFieldOverlay(maplibreAdapter(map));

import { leafletAdapter } from "@aeroswarm/weather-layer/leaflet";
const overlay = createFieldOverlay(leafletAdapter(map));                // no rotation unless you pass { bearing }

import { cesiumAdapter } from "@aeroswarm/weather-layer/cesium";
import * as Cesium from "cesium";
const overlay = createFieldOverlay(
  cesiumAdapter(viewer, { Cartesian2: Cesium.Cartesian2, Cartographic: Cesium.Cartographic, toDegrees: Cesium.Math.toDegrees }),
);

import { riaAdapter } from "@aeroswarm/weather-layer/ria";
const overlay = createFieldOverlay(riaAdapter(map, { wgs84, createPoint, createTransformation }));

createWeatherOverlay accepts an adapter the same way. The old createFieldOverlay(map, { unproject }) call for RIA keeps working. Notes: on Cesium, screen points that miss the globe have no wind; with a tilted camera (MapLibre pitch, Cesium, RIA 3D) the wind direction on screen is an approximation. 3D clouds (section B) are still RIA only.

E. Ready-made UI (/react-ui)

React components so you do not assemble the controller, overlay and time UI yourself. One <WeatherLayer> per map; the components inside read its state, so two maps on one page do not interfere.

import { maplibreAdapter } from "@aeroswarm/weather-layer/maplibre";
import { WeatherLayer, WeatherLayerSwitch, WeatherLegend, WeatherTimeline } from "@aeroswarm/weather-layer/react-ui";
import "@aeroswarm/weather-layer/react-ui/weather-ui.css";   // optional default look

const adapter = useMemo(() => (map ? maplibreAdapter(map) : null), [map]);

<WeatherLayer adapter={adapter} store={store} grid={grid} series={series} locale="id" timeZone="Asia/Jakarta">
  <WeatherLayerSwitch />
  <WeatherTimeline />
  <WeatherLegend />
</WeatherLayer>
ExportWhat it does
WeatherLayermounts the overlay and the controller, provides context. Props: adapter (or RIA MapLike + unproject), store, grid, series, blend, locale, timeZone, messages
WeatherLayerSwitchWind, Cloud, Rain, Temperature. All off until turned on; colour layers are exclusive
WeatherTimelineslider with TAF period blocks, play/pause, "Now", window (today / next 3 days)
WeatherLegendcolour bar and unit of the active layer
WeatherPreviewTablehourly values at a point (model, reports, or model blended with reports)
useWeatherController(), useWeatherSnapshot(station)controller + state, and the station weather at the displayed time
windowFor(range, now, timeZone), previewRows(...)the pure functions behind them
  • Language: locale="id" gives Indonesian, anything else English; replace single texts with messages={{ wind: "Wind speed" }}.
  • Time zone: IANA name, default UTC. "Today" is the 24 hours of that zone's day.
  • Styling: no forced position, size or layout; put the components wherever your layout wants them. Classes are prefixed aw- (documented at the top of weather-ui.css) and colours come from --aw-* CSS variables, light and dark. The stylesheet is optional and does not depend on Tailwind or any UI kit.
  • Accessibility: native buttons and range input, radiogroup with arrow keys, aria-valuetext on the slider, WeatherSummary for a screen-reader sentence (aria-live), WeatherMotionToggle; both default themes meet WCAG AA contrast and the components pass an axe-core audit (jsdom, which cannot check layout-dependent rules; not tested with a real screen reader).
  • Motion: the particle overlay follows prefers-reduced-motion (still image) and the user can turn motion back on; particle count drops automatically on slow devices.
  • React 18+ is a peer dependency, optional for the rest of the package.

F. Sea layers and extra data (flow layers, providers)

Besides wind, the controller can draw several flow layers (particles that follow a vector field) and colour layers at once.

KindIdsSource
Flowwind, current, waveweather grid, ocean current, wave propagation
Colourcloud, rain, temperature, waveHeight, seaLevelweather grids, marine grids
controller.toggleFlowLayer("current");            // also setFlowLayers([...]); state.flows lists the ones on
controller.toggleColorLayer("waveHeight");        // several colour layers can be on together
controller.setLayerOpacity("seaLevel", 0.6);

Ramps: LAYER_RAMPS and FLOW_RAMPS (WAVE_HEIGHT_RAMP, SEA_LEVEL_RAMP, CURRENT_RAMP, WAVE_FLOW_RAMP); replace any of them with <WeatherLayer ramps={{ waveHeight: [...] }}> (stops are [value, r, g, b, alpha?]). Each flow layer has its own canvas, ramp and motion scale. Ocean currents are drawn much faster than their real speed, otherwise nothing would be seen to move. WeatherLayerSwitch accepts the new layers and its onChange also reports flows.

Providers bring fields from outside weather. A FieldProvider is { id, range(), fieldsAt(time) }; its time range extends the timeline, so the existing slider and play button animate it. @aeroswarm/marine ships ready-made ones:

import { marineFieldProvider, zoneTimeProvider } from "@aeroswarm/marine";

controller.setProviders([zoneTimeProvider(zones), marineFieldProvider(series)]);   // or pass `providers` in the options

G. Clip a layer to polygons (mask)

Sea layers must not paint over land, and their edge should follow the coast, not the grid squares. setMask limits chosen layers to a set of GeoJSON-style polygons (for example the sea zones from @aeroswarm/marine):

controller.setMask(polygons);                       // default layers: waveHeight, seaLevel, current, wave
controller.setMask(polygons, ["waveHeight"]);       // only these
controller.setMask(null);                           // remove
  • It uses CSS clip-path on the layer canvas, so the renderers pay nothing per frame. It needs MapAdapter.project, which the MapLibre, Leaflet and RIA adapters provide; without it setMask does nothing.
  • Ring winding is normalised, so touching or overlapping polygons merge and holes stay holes (normalizeMask, maskClipPath are exported).
  • Thousands of polygon points make the clip-path string long. If a map gets slow, simplify the polygons first.
  • The overlay is rebuilt when the map switches between 2D and 3D; call setMask again after the new controller exists.
  • Pair it with fillMarineGaps from @aeroswarm/marine so the strip between the sea values and the polygon edge is not blank.

Documentation

Stability and versioning policy (STABILITY.md), limits of use (LIMITS.md) and measured performance and size (PERFORMANCE.md) are shipped with @aeroswarm/weather; changes are in CHANGELOG.md.

Limits

METAR and TAF describe one point (the aerodrome). The animation is a representation around the airport, not the real position of clouds or rain. There is no terrain; the only land cut-out is the polygon mask of section G, which you supply. Sea layers are indicative (model resolution about 5-10 km), not for navigation.

版本与发布记录

@aeroswarm/weather-layer 共发布 21 个版本,首次发布于 2026/11/02;过去 12 个月发布了 21 个版本。

版本发布日期距今
0.12.0latest2026/11/042 天前
0.11.02026/11/042 天前
0.10.02026/11/042 天前
0.9.02026/11/033 天前
0.8.02026/11/033 天前
0.7.02026/11/033 天前

关于 @aeroswarm/weather-layer 的常见问题

@aeroswarm/weather-layer 是什么?

Animated weather overlay (wind, clouds, rain, fog, lightning) for LuciadRIA maps, driven by @aeroswarm/weather.

如何安装 @aeroswarm/weather-layer?

在项目目录运行 npm install @aeroswarm/weather-layer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@aeroswarm/weather(>=0.4.0 <1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aeroswarm/weather-layer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aeroswarm/weather-layer 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aeroswarm/weather-layer 可以商用吗?

@aeroswarm/weather-layer 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@aeroswarm/weather-layer 的下载量有多少?

根据 npm 官方下载统计,@aeroswarm/weather-layer 在 2026/10/06 – 2026/11/04 这 30 天内被下载 3,395 次,日均约 113 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aeroswarm/weather-layer 还在维护吗?

最新版本 0.12.0 发布于 2026/11/04(2 天前);至今共发布 21 个版本,其中过去 12 个月发布了 21 个;首次发布于 2026/11/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。