geoServer + leaflet 实现实时数据展示 以及数据回放

本文介绍如何在GeoServer中发布带有时间属性的图层,并在Leaflet中调用WMS图层实现时间维度的数据展示和回放。通过设置图层的timestamp字段,启用时间维度,结合定时器和图层刷新方法,实现动态数据更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.geoserver发布带有时间属性的图层

图层属性添加timestamp 类型字段

发布图层时 添加启用时间维度

 

 

2.leaflet 调用wms图层

this.ownLayer = this.nsnMap.newLayer({
   url: geoServerLayerUrl,
   layers: ownCarLayer,
   crs: L.CRS.EPSG4326,
   name: '自驾',
   type: 'wms_time',
   show: false,
   time: this.test,

});

其中 注意传递的time值 

由于我本人刚开始使用leaflet 找不到leaflet重新请求图层的方法

添加定时器

createTimer(value) {
   if (this.timer) {
      clearInterval(this.timer); // 在Vue实例销毁前,清除我们的定时器
   }
   let time = value * 3000;
   let app = this;
   this.timer = setInterval(() => {
      //更新时间 
       app.test = this.dataTest[a];
      //刷新图层  这里找不到leaflet的图层刷新方法 所以从新加载图层
      app.getAirPortRoadLayer();
      
   }, time);
},
getAirPortRoadLayer() {
   this.roadLayer.clearLayers();
   this.ownLayer = this.nsnMap.newLayer({
      url: geoServerLayerUrl,
      layers: ownCarLayer,
      crs: L.CRS.EPSG4326,
      name: '自驾',
      type: 'wms_time',
      show: false,
      time: this.test,

   });
   this.roadLayer.addLayer(this.ownLayer);
},

 这里需要保证geoserver的图层实行更新完成 。当然 可以使用socket 

注意:测试是geoserver会将时间转为CST 注意更改geoserver的时区

当然两个时区相差八小时 可以传递时间参数的时候 减去8小时传递  

3.数据回放

思路  1 获取要显示的时间段时间数组

2 循环数组刷新wms图层 实现数据回放

 

 

 

可参考 :https://docs.geoserver.org/stable/en/user/services/wms/index.html

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值