VUE+OpenLayer动态显示船舶位置信息

VUE+OpenLayer动态显示船舶位置信息

 

目前项目中需要使用海图来展示船舶位置信息。

特此来总结一下开发心得。使用的是openlayer组件库来实现海图的展示,底图为离线瓦片地图。

目标:实现前端定时发请求给后端,依据后端返回数据,在地图中展示物体实时坐标信息。

 <div id="map" class="map">
    mounted(){
      //在此处定义地图初始化方法
      this.initMap();
      this.getDataInfo();
    },
    created() {
     //定义定时获取数据方法
      this.refreshTab();
    },

refreshTab(){
setInterval(()=>{
this.getDataInfo(),6000;
)}


initMap(){
        this.map=new Map({
          layers:[
            new TileLayer({
            source: new XYZ({
              url: 'http://IP:PORT/{z}/{x}/{y}.png',
              tileSize:256
            })
            })
          ],
          target: "map",
          controls:defaults({zoom:true}),
          view: new View({
            center: [119,35],
            projection: 'EPSG:4326',
            zoom: 6,
            minZoom:1,
            maxZoom:16
          })
        })

//addControl增加地图控件展示
        let fullScreenControl = new FullScreen();
        this.map.addControl(fullScreenControl)
        let scaleLineControl = new ScaleLine();
        this.map.addControl(scaleLineControl)
        this.map.addControl(new ZoomSlider())

获取后端数据,判断坐标物是否已存在,存在则更新位置信息、无需新增图层(首次为新增图层。)

getDataInfo(){
getBackInterface().then(
response=>{
for(let i=0;i<response.length;i++)
var shipLocationLayer = _that.AisLayerArray[response[i].name];
if(shipLocationLayer ){
let ft = shipLocationLayer .getSource().getFeatureById(response[i].name]);
ft.setGeometry(new Point(x,y);
ft.setStyle();
//利用此方法更新位置信息
ft.changed();
}else{
//新建图层 VectorLayer
 shipLocationLayer  = new VectorLayer({
source: new VectorSoure()})
let feature = new Feature({
geometry: new Point();
})
//新增Feature、设置Feature样式、主键
feature .setStyle();
feature .setId();
//Layer.getSource().addFeature
shipLocationLayer.getSource.addFeature(feature );
//地图map新增图层
map.addLayer(shipLocationLayer)
_that.AisLayerArray[response[i].name]=shipLocationLayer
})
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三顾科技

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值