Cesium的小部件animation和timeline显示UTC系统时间,需要将其改为本地系统时间。修改方法如下:
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
| this.viewer.animation.viewModel.dateFormatter = localeDateTimeFormatter this.viewer.animation.viewModel.timeFormatter = localeTimeFormatter this.viewer.timeline.makeLabel = function (time) { return localeDateTimeFormatter(time) }
// Date formatting to a global form function localeDateTimeFormatter(datetime, viewModel, ignoredate) { var julianDT = new Cesium.JulianDate(); Cesium.JulianDate.addHours(datetime,8,julianDT) var gregorianDT= Cesium.JulianDate.toGregorianDate(julianDT) var objDT; if (ignoredate) objDT = ''; else { objDT = new Date(gregorianDT.year, gregorianDT.month - 1, gregorianDT.day); objDT = gregorianDT.year + '年' +objDT.toLocaleString("zh-cn", { month: "short" })+ gregorianDT.day + '日' ; if (viewModel || gregorianDT.hour + gregorianDT.minute === 0) return objDT; objDT += ' '; } return objDT + Cesium.sprintf("%02d:%02d:%02d", gregorianDT.hour, gregorianDT.minute, gregorianDT.second); }
function localeTimeFormatter(time, viewModel) { return localeDateTimeFormatter(time, viewModel, true); }
|
上述代码还存在一个问题,当timeline小部件不活动时,其仍然显示UTC标准系统时间。
Cesium的credit十分碍眼,采用如下方法去掉:
1 2
| //去除版权信息 viewer._cesiumWidget._creditContainer.style.display = "none";
|
参考链接
- EST,CST,PST,GMT,UTC,EDT等等时间缩写, by chienchia.
- Change UTC timezone to SGT timezone in Cesiumjs, by stackoverflow.
- Cesium去掉logo,by 跃然实验室.