前言

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="aisLayer" style="padding:5px;float: left;">' +
'<input type="checkbox" name="aislayer" style="width: 15px;height: 15px;vertical-align: middle;margin: auto;"/>' +
'<label style="font-weight: normal;vertical-align: middle;margin: auto;">船讯</label>' +
'</div>'
  • 点击事件
//船讯
$("#aisLayer input").bind("click", function () {
if (this.checked) {
ais = new bxmap.AIS({
bmap: bmap
});
ais.initSearchPanel($("#map-search-box-panel"));
ais.refresh();
var map = bmap.getMap();
map.getView().setCenter([12867513.634164134, 2589684.2523000734]);
map.getView().setZoom(10);
//图例面板显示
$("#map_tl").css("display","block");
$("#map_tl>img").attr('src', GLOBAL.domainResource+"/Content/img/AISLegend.png");
$("#map_tl>img").css("width","auto");
$("#map_tl>img").css("height","300px");
}
else {
ais.clear();
//图例面板隐藏
$("#map_tl").hide();
}
})
  • 地图范围显示船讯核心代码
/**
* @description 刷新船舶位置
*/
bxmap.AIS.prototype.refresh = function () {
var view = this.bmap.getMap().getView();
var resolution = view.getResolution();
//不满足显示渔船的条件
if(resolution > this.displayResolution) {
this.shipLayer && this.shipLayer.setVisible(false);
return;
} if(this.shipLayer){
//显示图层
this.shipLayer.setVisible(true); var center = view.getCenter();
//如果投影坐标系则转为EPSG:4326
if(this.isProjected) {
center = ol.proj.toLonLat(center);
} //获取船舶信息并添加到地图
var self = this;
bxmap.AIS.getShipsByResolution(center, resolution, function (data) {
if (data && data.length) {
//更新船舶
self._updateFeatureToMap(data);
//上次点击选中
if(self._shipInfoFeature){
//设置要素高亮样式
self.setHighlight(self._shipInfoFeature, true);
var info = self._shipInfoFeature["shipInfoData"];
if(this.showDefaultDialog){
this._showInfoDialog(info.shipid, info.source);
}
}
}
});
}
}

更多的详情见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 入门开发系列之地图展示篇(附源码下载)

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

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

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

  8. openlayers4 入门开发系列之风场图篇

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

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

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

随机推荐

  1. Python_生成大量随机信息

    #coding=utf-8 import random import string import codecs ''' 演示如何使用Python标准库random来生成随机数据,这在需要 ''' #常 ...

  2. C语言 > 构造素数表

    #include <stdio.h> #define NUMBER 1000 int main(){ int isPrime[NUMBER]; ; i < NUMBER; i++){ ...

  3. HTTP 前端需明白的相关知识点

    简介: http(Hyper Text Transfer Protocol)超文本传输协议是万维网应用层的协议,使用了面向连接的TCP作为运输层协议. 特征: 简单快速:通过url就可以访问资源,协议 ...

  4. JFrame图形界面 ----绝对布局和按钮

    开始 绝对布局应该是最简单的一种布局方式了,只需要确定好大小和位置就可以固定不变 代码 ` package window; import java.awt.Color; import java.awt ...

  5. c# Socket通信异步TCP

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  6. Ubuntu配置SecureCRT登录

    1. 命令行切换到root用户 备注:ubuntu默认root用户没有设置密码,切换需要首先设置密码 sudo passwd root 按照提示输入当前用户密码 按照提示输入要设置的root用户密码 ...

  7. MAC下Intellij IDEA常用快捷键

    alt+f7 : 查找在哪里使用 command+alt+f7 : 这个是查找选中的字符在工程中出现的地方,可以不是方法变量类等,这个和上面的有区别的 command+F7 : 可以查询当前元素在当前 ...

  8. .net core使用Apollo做统一配置管理

    做开发这么多年,经常因配置的问题引发生产环境的bug.有些年久的项目,几百个密密麻麻的配置项,经常容易搞混,有时好几个项目有好多同样的配置项,配置工作也不厌其烦.所幸,携程开源了新一代配置中心 - A ...

  9. 【建图+最短路】Bzoj1001 狼抓兔子

    Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个 ...

  10. BZOJ_3083_遥远的国度_树链剖分+线段树

    BZOJ_3083_遥远的国度_树链剖分 Description 描述 zcwwzdjn在追杀十分sb的zhx,而zhx逃入了一个遥远的国度.当zcwwzdjn准备进入遥远的国度继续追杀时,守护神Ra ...