2023-07-18 09:04:15 +08:00
|
|
|
|
(function (window, mars3d) {
|
2023-07-08 15:37:34 +08:00
|
|
|
|
//创建widget类,需要继承BaseWidget
|
|
|
|
|
|
class MyWidget extends mars3d.widget.BaseWidget {
|
|
|
|
|
|
//弹窗配置
|
|
|
|
|
|
get view() {
|
|
|
|
|
|
return {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
type: "window",
|
|
|
|
|
|
url: "view.html",
|
2023-07-08 15:37:34 +08:00
|
|
|
|
windowOptions: {
|
|
|
|
|
|
width: 270,
|
|
|
|
|
|
height: 500,
|
|
|
|
|
|
position: {
|
|
|
|
|
|
top: 70,
|
|
|
|
|
|
bottom: 40,
|
|
|
|
|
|
left: 15,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2023-07-18 09:04:15 +08:00
|
|
|
|
};
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//初始化[仅执行1次]
|
|
|
|
|
|
create() {}
|
|
|
|
|
|
//每个窗口创建完成后调用
|
|
|
|
|
|
winCreateOK(opt, result) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.viewWindow = result;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//打开激活
|
|
|
|
|
|
activate() {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.layerWork = this.map.getLayer(this.config.layerCfg);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
if (this.layerWork) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.layerWork.on(mars3d.EventType.removeLayer, this._onRemoveLayerHandler, this);
|
|
|
|
|
|
this.layerWork.on(mars3d.EventType.hide, this._onRemoveLayerHandler, this);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_onRemoveLayerHandler(e) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.disableBase();
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//关闭释放
|
|
|
|
|
|
disable() {
|
|
|
|
|
|
if (this.layerWork) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.layerWork.off(mars3d.EventType.removeLayer, this._onRemoveLayerHandler, this);
|
|
|
|
|
|
this.layerWork.on(mars3d.EventType.removeLayer, this._onRemoveLayerHandler, this);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.resetStyle();
|
|
|
|
|
|
this.viewWindow = null;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
getTreeUrl() {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
var url = this.config.layerCfg.url;
|
|
|
|
|
|
url = url.substring(0, url.lastIndexOf("/") + 1) + this.config.layerCfg.scenetree;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
var that = this;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
$.ajax({
|
|
|
|
|
|
url: url,
|
2023-07-18 09:04:15 +08:00
|
|
|
|
dataType: "json",
|
2023-07-08 15:37:34 +08:00
|
|
|
|
success(scene) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
that.viewWindow.initSceneTree(scene);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
},
|
2023-07-18 09:04:15 +08:00
|
|
|
|
});
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
resetStyle() {
|
|
|
|
|
|
if (!this.layerWork?.tileset) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
return;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.layerWork.tileset.style = undefined;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//定位
|
|
|
|
|
|
locateNode(nodeid, nodesphere) {
|
|
|
|
|
|
if (nodesphere[3] <= 0) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
return;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.layerWork) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
return;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.layerWork.closePopup();
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
//构件节点位置
|
2023-07-18 09:04:15 +08:00
|
|
|
|
var center = new Cesium.Cartesian3(nodesphere[0], nodesphere[1], nodesphere[2]);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
//获取构件节点位置,现对于原始矩阵变化后的新位置
|
2023-07-18 09:04:15 +08:00
|
|
|
|
center = this.layerWork.getPositionByOrginMatrix(center);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
//飞行过去
|
2023-07-18 09:04:15 +08:00
|
|
|
|
var sphere = new Cesium.BoundingSphere(center, nodesphere[3]);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
this.map.camera.flyToBoundingSphere(sphere, {
|
|
|
|
|
|
offset: new Cesium.HeadingPitchRange(this.map.camera.heading, this.map.camera.pitch, nodesphere[3] * 4),
|
|
|
|
|
|
duration: 0.5,
|
2023-07-18 09:04:15 +08:00
|
|
|
|
});
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
//设置tileset的样式
|
|
|
|
|
|
this.layerWork.style = new Cesium.Cesium3DTileStyle({
|
|
|
|
|
|
color: {
|
|
|
|
|
|
conditions: [
|
2023-07-18 09:04:15 +08:00
|
|
|
|
["${id} ==='" + nodeid + "'", "rgb(255, 255, 255)"],
|
|
|
|
|
|
["true", "rgba(255, 200, 200,0.2)"],
|
2023-07-08 15:37:34 +08:00
|
|
|
|
],
|
|
|
|
|
|
},
|
2023-07-18 09:04:15 +08:00
|
|
|
|
});
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//注册到widget管理器中。
|
2023-07-18 09:04:15 +08:00
|
|
|
|
mars3d.widget.bindClass(MyWidget);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
//每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
|
2023-07-18 09:04:15 +08:00
|
|
|
|
})(window, mars3d);
|