修改时间线Timeline格式

2021-08-18  本文已影响0人  变异宝宝
// 时间格式化
Cesium.Timeline.prototype.makeLabel = (e) => {
    var t = this.julianToDate(e),
        i = t.millisecond,
        r = ' UTC';
    if (0 < i && this._timeBarSecondsSpan < 3600) {
        for (r = Math.floor(i).toString(); r.length < 3; )
            r = '0' + r;
        r = '.' + r;
    }
    //这里就是设置格式的地方
    return (
        t.year +
        '-' +
        this.twoDigits(t.month) +
        '-' +
        this.twoDigits(t.day) +
        ' ' +
        this.twoDigits(t.hour) +
        ':' +
        this.twoDigits(t.minute) +
        ':' +
        this.twoDigits(t.second)
    );
};
/**
 * 朱利安时间转日期对象
 */
julianToDate(e) {
    var date = new Date();
    var h = 0 - date.getTimezoneOffset();
    //由于Cesium都是以JulianDate作为默认日期,所以参数e肯定为JulianDate类型
    var dataZone = Cesium.JulianDate.addMinutes(
        e,
        h,
        new Cesium.JulianDate()
    );
    return Cesium.JulianDate.toGregorianDate(dataZone);
};
// 设置当前时间
viewer.clock.currentTime = Cesium.JulianDate.now();
// js日期转朱利安日期
Cesium.JulianDate.fromDate (date);
// 公历日期转朱利安日期
Cesium.JulianDate.fromGregorianDate (date);
上一篇 下一篇

猜你喜欢

热点阅读