120 lines
3.1 KiB
JavaScript
120 lines
3.1 KiB
JavaScript
(function (window, mars3d) {
|
||
//创建widget类,需要继承BaseWidget
|
||
class MyWidget extends mars3d.widget.BaseWidget {
|
||
//弹窗配置
|
||
get view() {
|
||
return {
|
||
type: "window",
|
||
url: "view.html",
|
||
windowOptions: {
|
||
width: 230,
|
||
height: 520,
|
||
//maxmin: true,
|
||
},
|
||
};
|
||
}
|
||
//初始化[仅执行1次]
|
||
create() {}
|
||
//每个窗口创建完成后调用
|
||
winCreateOK(opt, result) {
|
||
//layer.min(opt._layerIdx); //最小化窗口
|
||
this.viewWindow = result;
|
||
}
|
||
//激活模块之前 的钩子方法
|
||
beforeActivate() {
|
||
var lonlats = this.config.data.positions;
|
||
if (!lonlats || lonlats.length < 2) {
|
||
toastr.error("路线无坐标数据,无法漫游!");
|
||
return;
|
||
}
|
||
let roamLine = new mars3d.graphic.RoamLine(this.config.data);
|
||
this.map.graphicLayer.addGraphic(roamLine);
|
||
this.roamLine = roamLine;
|
||
|
||
this.roamLine.on(mars3d.EventType.change, (event) => {
|
||
this.viewWindow.showRealTimeInfo(event);
|
||
this.updateCharsWidgeFlyOk(event.len); //更新剖面图
|
||
});
|
||
}
|
||
//打开激活
|
||
activate() {
|
||
if (this.config.data.clampToGround) {
|
||
this.roamLine.clampToGround(() => {
|
||
//异步计算完成贴地后再启动
|
||
this.startFly();
|
||
});
|
||
} else {
|
||
this.startFly();
|
||
}
|
||
}
|
||
startFly() {
|
||
this.roamLine.start();
|
||
|
||
//显示基本信息,名称、总长、总时间
|
||
this.viewWindow.showAllInfo({
|
||
name: this.roamLine.name,
|
||
alllen: this.roamLine.alllen,
|
||
alltime: this.roamLine.alltimes,
|
||
});
|
||
|
||
if (this.map.timeline) {
|
||
this.map.timeline.zoomTo(this.roamLine.startTime, this.roamLine.stopTime);
|
||
}
|
||
}
|
||
//关闭释放
|
||
disable() {
|
||
this.viewWindow = null;
|
||
|
||
this.roamLine.destroy();
|
||
delete this.roamLine;
|
||
}
|
||
//界面更新参数
|
||
getAttr() {
|
||
if (this.roamLine) {
|
||
return this.roamLine.options;
|
||
} else {
|
||
return this.config.data;
|
||
}
|
||
}
|
||
setCameraOptions(params) {
|
||
this.roamLine.setCameraOptions(params);
|
||
}
|
||
|
||
//返回列表widget
|
||
toRoamLine() {
|
||
this.roamLine.stop();
|
||
|
||
mars3d.widget.activate({
|
||
uri: "widgets/roamLine/widget.js",
|
||
});
|
||
}
|
||
|
||
//显示剖面
|
||
showHeightChars() {
|
||
this.roamLine.options.splitNum = 100;
|
||
this.roamLine.getTerrainHeight((data) => {
|
||
this.updateCharsWidge(data);
|
||
});
|
||
}
|
||
//首次激活roamChars
|
||
updateCharsWidge(data) {
|
||
mars3d.widget.activate({
|
||
uri: "widgets/roamChars/widget.js",
|
||
data: data,
|
||
});
|
||
}
|
||
//持续更新调用roamChars
|
||
updateCharsWidgeFlyOk(alllen) {
|
||
var roamingJK = mars3d.widget.getClass("widgets/roamChars/widget.js");
|
||
if (roamingJK && roamingJK.isActivate) {
|
||
roamingJK.changeFlyOk(alllen);
|
||
}
|
||
}
|
||
}
|
||
|
||
//注册到widget管理器中。
|
||
mars3d.widget.bindClass(MyWidget);
|
||
|
||
//每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
|
||
})(window, mars3d);
|