a maptalks | mapbox-gl | openlayers | leaflet | bmap | amap extension to show wind field。
wind-layer 是一个专注于气象格点数据可视的插件,设计之处是参考了 earth cambecc 的一个气象数据的展示,他使用了流体场的方式去展示了全球的风速和风向,富有很强的 表现力, 这个插件的早期的很多核心代码也是来源于此。当然现在它不仅仅是做风场的展示,常规的气象数据都可以依赖此插件进行可视化。
gl-core
扩展目前只针对 mapbox
、maplibre
和 maptalks
做了相关适配,其他引擎适配欢迎 PR。
目前计划支持的图层如下:
configDeps
, exif
默认支持,因为在 safari
浏览器下 configDeps
有兼容性问题,所以默认打包了 exif 的解析库。
mapboxWind.configDeps(['https://unpkg.com/geotiff/dist-browser/geotiff.js']);
TIP: 注意 2.0 之后不再支持 jsonArray
数据和 EPSG:4326
的图片数据,如果有需求请使用 1.x 版本
https://github.com/sakitam-fdd/wind-layer/assets/19517451/b36b7eea-c647-42ed-91a4-e1f182d0343c
https://github.com/sakitam-fdd/wind-layer/assets/19517451/bf27d98e-68ed-4f9c-b1e4-812764665bff
https://github.com/sakitam-fdd/wind-layer/assets/19517451/90542837-b80c-450e-857d-4df6f52b6a49
https://github.com/sakitam-fdd/wind-layer/assets/19517451/064f0ea4-f72f-4e9a-80e7-7a0097f60013
Project | Version | Npm | CDN | Description |
---|---|---|---|---|
wind-core | 风场核心渲染,可扩展不可以直接使用 | |||
wind-gl-core | 色斑图核心渲染,可扩展不可以直接使用 | |||
ol-wind | openlayers 6+ 风场扩展插件 |
|||
ol5-wind | openlayers 5 风场扩展插件 |
|||
openlayers-wind | openlayers 3/4 风场扩展插件 |
|||
@sakitam-gis/maptalks-wind | maptalks 风场扩展插件 |
|||
amap-wind | 高德地图风场扩展插件 | |||
bmap-wind | 百度地图风场扩展插件 | |||
mapbox-wind | mapbox-gl 风场扩展插件 | |||
maplibre-wind | maplibre-gl 风场扩展插件 | |||
leaflet-wind | Leaflet风场扩展插件 |
cesium 相关集成请查看 cesium-wind
我们推荐使用 pnpm 或 yarn 的方式进行开发, 不仅可在开发环境轻松调试,也可放心地在生产环境打包部署使用, 享受整个生态圈和工具链带来的诸多好处。
相关插件:
# pnpm
pnpm install wind-core
pnpm install wind-gl-core
pnpm install src-wind
pnpm install ol5-wind
pnpm install openlayers-wind
pnpm install @sakitam-gis/maptalks-wind
pnpm install amap-wind
pnpm install bmap-wind
pnpm install leaflet-wind
pnpm install @sakitam-gis/mapbox-wind
pnpm install @sakitam-gis/maplibre-wind
# yarn
yarn add wind-core
yarn add wind-gl-core
yarn add src-wind
yarn add ol5-wind
yarn add openlayers-wind
yarn add @sakitam-gis/maptalks-wind
yarn add amap-wind
yarn add bmap-wind
yarn add leaflet-wind
yarn add @sakitam-gis/mapbox-wind
yarn add @sakitam-gis/maplibre-wind
在浏览器中使用 script
标签直接引入文件,并使用全局变量。
我们在仓库发布包内的 dist
目录下提供了 xxx.js
以及 xxx.min.js
;
基础使用可以分为三步:
WebGIS
地图类库,引入对应的可视化图层扩展插件。WindLayer
,设置风场格点的 U V
数据和图层参数 并添加到地图上。以下以 maptalks 为例:
<template>
<div class="demo-content">
<div class="demo-content-datgui"></div>
<div class="map-warp" ref="map"></div>
</div>
</template>
<script>
import 'maptalks/dist/maptalks.css';
import {
Map,
TileLayer,
} from 'maptalks';
import { WindLayer } from 'maptalks-wind';
export default {
name: 'maptalks-wind-base',
data() {
return {};
},
watch: {},
methods: {
initMap() {
const map = new Map(this.$refs.map, {
center: [113.53450137499999, 34.44104525],
zoom: 3,
baseLayer: new TileLayer('base', {
urlTemplate: '//{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
// urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c', 'd'],
})
});
fetch('/data/wind.json')
.then(res => res.json())
.then(res => {
const windLayer = new WindLayer('wind', res, {
windOptions: {
// colorScale: scale,
velocityScale: 1 / 20,
paths: 5000,
// eslint-disable-next-line no-unused-vars
colorScale: [
"rgb(36,104, 180)",
"rgb(60,157, 194)",
"rgb(128,205,193 )",
"rgb(151,218,168 )",
"rgb(198,231,181)",
"rgb(238,247,217)",
"rgb(255,238,159)",
"rgb(252,217,125)",
"rgb(255,182,100)",
"rgb(252,150,75)",
"rgb(250,112,52)",
"rgb(245,64,32)",
"rgb(237,45,28)",
"rgb(220,24,32)",
"rgb(180,0,35)"
],
// colorScale: scale,
},
// map: map,
// projection: 'EPSG:4326'
});
console.log(map, windLayer);
map.addLayer(windLayer);
});
}
},
mounted() {
this.initMap();
},
};
</script>
<style lang="less">
.demo-content {
width: 100%;
height: 100%;
position: relative;
background-color: #cbe0ff;
&-datgui {
position: absolute;
top: 10px;
left: 10px;
z-index: 1;
pointer-events: auto;
}
.map-warp {
width: 100%;
height: 100%;
}
}
</style>
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Map - Display a map</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.css">
<style type="text/css">
html, body {
margin: 0;
height: 100%;
width: 100%
}
.container {
width: 100%;
height: 100%
}
</style>
<body>
<div id="map" class="container"></div>
<script src="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@sakitam-gis/maptalks-wind/dist/maptalks-wind.js"></script>
<script>
const map = new maptalks.Map('map', {
center: [113.53450137499999, 34.44104525],
zoom: 5,
baseLayer: new maptalks.TileLayer('base', {
// urlTemplate: 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c', 'd'],
})
});
fetch('data.json')
.then(res => res.json())
.then(res => {
const windLayer = new MaptalksWind.WindLayer('wind', res, {
windOptions: {
// colorScale: (m) => {
// // console.log(m);
// return '#fff';
// },
colorScale: [
"rgb(36,104, 180)",
"rgb(60,157, 194)",
"rgb(128,205,193 )",
"rgb(151,218,168 )",
"rgb(198,231,181)",
"rgb(238,247,217)",
"rgb(255,238,159)",
"rgb(252,217,125)",
"rgb(255,182,100)",
"rgb(252,150,75)",
"rgb(250,112,52)",
"rgb(245,64,32)",
"rgb(237,45,28)",
"rgb(220,24,32)",
"rgb(180,0,35)"
],
// velocityScale: 1 / 20,
// paths: 5000,
frameRate: 16,
maxAge: 60,
globalAlpha: 0.9,
velocityScale: 1 / 30,
// paths: 10000,
paths: () => { // can be number or function
const zoom = map.getZoom();
return zoom * 1000;
},
},
});
console.log(map, windLayer);
map.addLayer(windLayer);
});
</script>
</body>
</html>
天气数据由全球预报系统(GFS)生成, 由美国国家气象局管理。 预测每天产生四次,并可用于 从NOMADS下载。 这些文件位于GRIB2 格式并包含超过300条记录。 我们只需要这些记录中的一小部分就可以在特定的等压线上可视化风资料。 下面的命令下载 1000 hPa风向量,并使用grib2json将它们转换为JSON格式。
YYYYMMDD=<a date, for example: 20140101>
curl "http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs.pl?file=gfs.t00z.pgrb2.1p00.f000&lev_10_m_above_ground=on&var_UGRD=on&var_VGRD=on&dir=%2Fgfs.${YYYYMMDD}00" -o gfs.t00z.pgrb2.1p00.f000
grib2json -d -n -o current-wind-surface-level-gfs-1.0.json gfs.t00z.pgrb2.1p00.f000
cp current-wind-surface-level-gfs-1.0.json <earth-git-repository>/public/data/weather/current
对于 2.x 版本的数据格式我们可以使用 https://github.com/sakitam-gis/raster-process 来生成所需要的瓦片和单张图片。