前言

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

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

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

实现思路

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

更多的详情见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. 微服务与SOA的区别

    微服务架构强调的第一个重点就是业务系统需要彻底的组件化和服务化,原有的单个业务系统会拆分为多个可以独立开发,设计,运行和运维的小应用.这些小应用之间通过服务完成交互和集成.每个小应用从前端web ui ...

  2. php-msf 源码解读【转】

    php-msf: https://github.com/pinguo/php-msf 百度脑图 - php-msf 源码解读: http://naotu.baidu.com/file/cc7b5a49 ...

  3. Java 精简Jre jar打包成exe

    #开始 最近几天都在忙一个事情,那就是尝试精简jre,我想不明白为什么甲骨文官方不出exe打包工具... 网络上精简jre的文章很多,但是原创的似乎没几个,绝大多数都是转发同一个博客, 这里借鉴了不少 ...

  4. JS中的常量

    javascript中没有常量,可以通过创建只能取值不能赋值的私有变量来模仿常量. 创建取值器: var Class = function(){ var NUM = 5;   //  在运行时NUM值 ...

  5. 11. 将博客部署到tomcat上

    springboot项目既可以以jar运行,也可以做成war包放到服务器上,因为我的博客项目涉及到文件上传,所以按照jar的方式就不可行,需要部署到tomcat上,具体做法如下:1. 修改pom.xm ...

  6. [Python]range与xrange用法对比

    [整理内容]具体如下: 先来看如下示例:>>>x=xrange(0,8)>>> print xxrange(8)>>>print x[0]0> ...

  7. if_else_while_for

    import getpass #标准库里要加密密码需要导包getpass.但是getpass在pycharm中不好用,需要在命令窗口中输入才管用. _username = "abc" ...

  8. DOM常见操作

    一.查找 1.直接查找 document.getElementById           根据ID获取一个标签 document.getElementsByName         根据name属性 ...

  9. 如何把word中的图片怎么导出来呢?

    在办公使用word的过程中你可能经常会遇到这个问题:插入到word中的图片找不到导出来的方法,是不是很郁闷呢,别急,今天咱们研究一下把word中的图片导出来的方法(把"我的"变成你 ...

  10. logrus_hook.go

    package) //表示自身栈中跳过6个,:]     entry.Data["file"] = fileName     entry.Data["func" ...