随笔 - 833  文章 - 1  评论 - 106  阅读 - 200万

cesium 自定义时间轴 通过改变时间设置光照效果[转]

cesium 自带timeline animation空间有时候满足不了项目的需求,需求要通过自己设置时间来改变光照

this.viewer = new Cesium.Viewer('cesiumContainer', {
  animation: false, //是否显示动画控件
  homeButton: false, //是否显示home键
  geocoder: false, //是否显示地名查找控件
  baseLayerPicker: false, //是否显示图层选择控件
  timeline: false, //是否显示时间线控件
  fullscreenButton: false, //是否全屏显示
  scene3DOnly: true, //如果设置为true,则所有几何图形以3D模式绘制以节约GPU资源
  infoBox: true, //是否显示点击要素之后显示的信息
  sceneModePicker: false, //是否显示投影方式控件 三维/二维
  navigationInstructionsInitiallyVisible: false,
  navigationHelpButton: false, //是否显示帮助信息控件
  selectionIndicator:false,
  // 影像图
  imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
  url: server + ':6080/arcgis/rest/services/dls/CesiumImagery/MapServer'
       }),
  // terrainProvider: Cesium.createWorldTerrain()
  // 地形图
  terrainProvider: new Cesium.CesiumTerrainProvider({
  url: server + ':8080/terrain',
  requestVertexNormals: true // 地形图上添加此属性 效果更好
    })
})
this.viewer._cesiumWidget._creditContainer.style.display = 'none' // 去除版权信息
this.viewer.scene.globe.depthTestAgainstTerrain = true

this.scene = this.viewer.scene
this.camera = this.viewer.camera
this.scene.globe.enableLighting = true
上边是初始化cesium的一些配置属性

重点:关键

1.开始一直想的是通过设置this.viewer.clock.currentTime来改变viewer的时间进而改变光照,但是发现始终设置不成功

原来是因为它只能获取不能设置

 

 

 

2.需要使用clockViewModel,具体为什么,没研究,但是这个是可以设置成功的,参考案例:https://sandcastle.cesium.com/index.html?src=Clock.html

  

3.具体使用

var utc=Cesium.JulianDate.fromDate(new Date("2019/10/04 09:00:00"));//UTC

this.viewer.clockViewModel.currentTime = Cesium.JulianDate.addHours(utc,8,new Cesium.JulianDate());//北京时间=UTC+8=GMT+8
这里涉及到一个知识点:julianDate与Date之间的转换关系(参考文档:https://blog.csdn.net/xiaotian602574436/article/details/78293637)

js创建的Date对象是北京时间,但是与JulianDate的日期是不同的,cesium中显示的时间与Date日期的时间是差8个小时。北京时间=JulianDate+8

var date=new Date(“2019/10/04 12:30:00”);//时间为:2019/10/04 12:00:00

var julianTime=Cesium.JulianDate.fromDate(date); //转为JulianDate

//设置时钟的当前日期

this.viewer.clock.currentTime=julianTime.clone();//时钟上显示的时间为:2019/10/04 20:00:00

想让时钟显示 2019/10/04 12:00:00

var utc=Cesium.JulianDate.fromDate(new Date("2019/10/04 12:00:00"));//UTC

this.viewer.clock.currentTime=Cesium.JulianDate.addHours(utc,8,new Cesium.JulianDate());//北京时间=UTC+8=GMT+8
————————————————
版权声明:本文为CSDN博主「匆匆忙忙慌慌张张」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42213796/article/details/107367962

posted on   3D入魔  阅读(2150)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2012-06-10 利用ATL技术创建ActiveX控件CircleCtl 。简单介绍 VC2003 使用 ATL 开发 ActiveX 控件(转)
2012-06-10 Web发布cab文件打包的ActiveX控件总结 (转)
2012-06-10 使用ATL开发ActiveX控件
2012-06-10 用ATL开发和部署ActiveX网页控件(转)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示