(function (window, mars3d) {
|
//创建widget类,需要继承BaseWidget
|
class MyWidget extends mars3d.widget.BaseWidget {
|
//外部资源配置
|
get resources() {
|
return ["view.css"];
|
}
|
|
//弹窗配置
|
get view() {
|
return {
|
type: "append",
|
url: "view.html",
|
};
|
}
|
|
//初始化[仅执行1次]
|
create() {
|
this.isAnimate = this.map.clock.shouldAnimate;
|
}
|
//每个窗口创建完成后调用
|
winCreateOK(opt, result) {
|
var that = this;
|
//此处可以绑定页面dom事件
|
|
this.$start = $("#btn-animation-start");
|
this.$time = $("#btn-animation-time");
|
this.$speed = $("#txt-animation-speed");
|
|
$("#btn-animation-now").click(function (e) {
|
that.map.clock.currentTime = Cesium.JulianDate.fromDate(new Date());
|
});
|
|
this.$start.click(function (e) {
|
that.map.clock.shouldAnimate = !that.map.clock.shouldAnimate;
|
that.updateStatus();
|
});
|
|
this.$speed.val(this.map.clock.multiplier);
|
this.$speed.change(function (e) {
|
var val = Number(that.$speed.val());
|
if (!isNaN(val)) {
|
that.map.clock.multiplier = val;
|
} //飞行速度
|
});
|
|
//this.map.clock.onTick.addEventListener(this.clock_onTickHandler, this);
|
setInterval(function () {
|
that.clock_onTickHandler();
|
}, 1000);
|
that.clock_onTickHandler();
|
}
|
//激活插件
|
activate() {
|
$(".distance-legend").css({
|
bottom: "25px",
|
});
|
$(".cesium-viewer-timelineContainer").css({ left: "290px" });
|
}
|
//释放插件
|
disable() {}
|
|
updateStatus() {
|
if (!this.$start || this.isAnimate === this.map.clock.shouldAnimate) {
|
return;
|
}
|
this.isAnimate = this.map.clock.shouldAnimate;
|
|
if (this.isAnimate) {
|
this.$start.attr("title", "暂停").html('<i class="fa fa-pause"></i>');
|
} else {
|
this.$start.attr("title", "继续").html('<i class="fa fa-play"></i>');
|
}
|
}
|
clock_onTickHandler() {
|
this.updateStatus();
|
|
if (this.$time) {
|
var str = Cesium.JulianDate.toDate(this.map.clock.currentTime).format("yyyy-MM-dd HH:mm:ss");
|
this.$time.html(str);
|
}
|
}
|
}
|
|
//注册到widget管理器中。
|
mars3d.widget.bindClass(MyWidget);
|
|
//每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
|
})(window, mars3d);
|