前言

openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子,这个也是学习 openlayers4 的好素材。

openlayers4 入门开发系列的地图服务基于 Geoserver 发布的,关于 Geoserver 方面操作的博客,可以参考以下几篇文章:

本篇的重点内容是利用 openlayers4 实现风场图功能,效果图如下:

实现思路

  • 界面设计
//风场图
"<div style='height:25px;background:#30A4D5;margin-top:10px;width: 98%;margin-left: 3px;float: left;'>" +
"<span style='margin-left:5px;font-size: 13px;color:white;'>风场图</span>" +
"</div>" +
'<div id="windLayer" style="padding:5px;float: left;">' +
'<input type="checkbox" name="windlayer" style="width: 15px;height: 15px;vertical-align: middle;margin: auto;"/>' +
'<label style="font-weight: normal;vertical-align: middle;margin: auto;">风场图</label>' +
'</div>'
  • 点击事件
//风场图
$("#windLayer input").bind("click", function () {
if (this.checked) {
var layer = bmap.getMapConfig().getShareLayer("GISSERVER_Wind");
bxmap.olWindLayer.Init(bmap);
if(layer){
layer.setVisible(true);
}
//图例面板显示
$("#map_tl").css("display","block");
$("#map_tl>img").attr('src', getRootPath() +"js/main/olWindLayer/windLegend.jpg");
$("#map_tl>img").css("width","auto");
$("#map_tl>img").css("height","300px");
}
else {
var layer = bmap.getMapConfig().getShareLayer("GISSERVER_Wind");
bxmap.olWindLayer.clearWind();
if(layer){
layer.setVisible(false);
}
//图例面板隐藏
$("#map_tl").hide();
}
})
  • 初始化代码
var bxmap = bxmap || {};
bxmap.olWindLayer = {
map:null,
wind:null,
Init:function(bmap){
this.map = bmap.getMap();
this.map.getView().setCenter([13501836.676, 2751733.018]);
this.map.getView().setZoom(3);
//加载风场数据
var wind, data;
axios.get(getRootPath() +"js/main/olWindLayer/gfs.json").then(function (res) {
if (res.data) {
data = res.data
wind = bxmap.olWindLayer.wind = new WindLayer(data, {
projection: 'EPSG:3857',
ratio: 1
})
wind.appendTo(bxmap.olWindLayer.map)
}
});
},
clearWind:function(){
if(bxmap.olWindLayer.wind)
bxmap.olWindLayer.wind.clearWind();
} }
  • 核心代码
/*!
* author: FDD <smileFDD@gmail.com>
* wind-layer v0.0.4
* build-time: 2018-2-6 17:34
* LICENSE: MIT
* (c) 2017-2018 https://sakitam-fdd.github.io/wind-layer
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('openlayers')) :
typeof define === 'function' && define.amd ? define(['openlayers'], factory) :
(global.WindLayer = factory(global.ol));
}(this, (function (ol) { 'use strict'; ol = ol && ol.hasOwnProperty('default') ? ol['default'] : ol; var Windy = function Windy(params) {
var VELOCITY_SCALE = 0.005 * (Math.pow(window.devicePixelRatio, 1 / 3) || 1);
var MIN_TEMPERATURE_K = 261.15;
var MAX_TEMPERATURE_K = 317.15;
var MAX_PARTICLE_AGE = 90;
var PARTICLE_LINE_WIDTH = 1;
var PARTICLE_MULTIPLIER = 1 / 200;
var PARTICLE_REDUCTION = Math.pow(window.devicePixelRatio, 1 / 3) || 1.6;
var FRAME_RATE = 15,
FRAME_TIME = 1000 / FRAME_RATE; var NULL_WIND_VECTOR = [NaN, NaN, null]; var builder;
var grid;
var date;
var λ0, φ0, Δλ, Δφ, ni, nj; var bilinearInterpolateVector = function bilinearInterpolateVector(x, y, g00, g10, g01, g11) {
var rx = 1 - x;
var ry = 1 - y;
var a = rx * ry,
b = x * ry,
c = rx * y,
d = x * y;
var u = g00[0] * a + g10[0] * b + g01[0] * c + g11[0] * d;
var v = g00[1] * a + g10[1] * b + g01[1] * c + g11[1] * d;
var tmp = g00[2] * a + g10[2] * b + g01[2] * c + g11[2] * d;
return [u, v, tmp];
};
……

更多的详情见GIS之家小专栏

对本专栏感兴趣的话,可以关注一波

openlayers4 入门开发系列之风场图篇的更多相关文章

  1. openlayers4 入门开发系列之热力图篇(附源码下载)

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  2. openlayers4 入门开发系列之小区信号扇形图篇

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  3. openlayers4 入门开发系列之台风轨迹篇

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  4. openlayers4 入门开发系列之船讯篇

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  5. openlayers4 入门开发系列之聚合图篇(附源码下载)

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  6. openlayers4 入门开发系列之批量叠加 zip 压缩 SHP 图层篇(附源码下载)

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  7. openlayers4 入门开发系列之地图模态层篇(附源码下载)

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  8. openlayers4 入门开发系列之迁徙图篇(附源码下载)

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  9. openlayers4 入门开发系列之地图标绘篇(附源码下载)

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

随机推荐

  1. IntelliJ IDEA maven 构建简单springmvc项目

    环境: apache-tomcat-8.5.15 jdk1.8.0_172 IDEA 建立一个maven-webapp项目:Create New Project 后点击next 然后next 可以选择 ...

  2. 并发库应用之七 & 信号灯Semaphore应用

    Semaphore可以维护当前访问自身的线程个数,并且提供了同步机制. Semaphore实现的功能类似于厕所里有5个坑,有10个人要上厕所,同时就只能有5个人占用,当5个人中 的任何一个让开后,其中 ...

  3. MySQL类型float double decimal的区别

    语法 MySQL 浮点型和定点型可以用类型名称后加(M,D)来表示,M表示该值的总共长度,D表示小数点后面的长度,M和D又称为精度和标度,如float(7,4)的 可显示为-999.9999,MySQ ...

  4. linux C中调用shell命令和运行shell脚本

    1.system(执行shell 命令) 相关函数 fork,execve,waitpid,popen表头文件 #include<stdlib.h>定义函数 int system(cons ...

  5. java通过反射获取字段的类型

    import java.lang.reflect.Field;  //这是需要引入的包 Field[] f = 类名.class.getDeclaredFields(); //获取该类的字段for(F ...

  6. 在Windows下同时安装Python2.x和Python3.x

    前言: Python现在是两个版本共存,Python2.x和Python3.x都同时在更新.但是Python2.x和Python3.x的区别还是很多的(以后我可能会写一篇文章列举一下Python2.x ...

  7. Git协作流程

    Git 作为一个源码管理系统,不可避免涉及到多人协作. 协作必须有一个规范的流程,让大家有效地合作,使得项目井井有条地发展下去."协作流程"在英语里,叫做"workflo ...

  8. 写完批处理脚本,再写个Gradle脚本,解放双手

    前言 上一篇写个批处理来帮忙干活---遍历&字符串处理中,我们已经学习如何写批处理脚本来帮我们做一些简单的重复性工作,本篇继续来学习如何用 Gradle 写脚本,让它也来帮我们干活 Gradl ...

  9. 从零开始学习 Docker

      这篇文章是我学习 Docker 的记录,大部分内容摘抄自 <<Docker - 从入门到实践>> 一书,并非本人原创.学习过程中整理成适合我自己的笔记,其中也包含了我自己的 ...

  10. Nginx从听说到学会

    第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一 ...