wangzhibo
2021-09-06 2efb5d2a02ce47a9fd6f1cec138496aba72f0815
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //弹窗配置
    get view() {
      return {
        type: "window",
        url: "view.html",
        windowOptions: {
          width: 270,
          height: 500,
          position: {
            top: 70,
            bottom: 40,
            left: 15,
          },
        },
      };
    }
 
    //初始化[仅执行1次]
    create() {}
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      this.viewWindow = result;
    }
    //打开激活
    activate() {
      this.layerWork = this.map.getLayer(this.config.layerCfg);
      if (this.layerWork) {
        this.layerWork.on(mars3d.EventType.removeLayer, this._onRemoveLayerHandler, this);
        this.layerWork.on(mars3d.EventType.hide, this._onRemoveLayerHandler, this);
      }
    }
 
    _onRemoveLayerHandler(e) {
      this.disableBase();
    }
    //关闭释放
    disable() {
      if (this.layerWork) {
        this.layerWork.off(mars3d.EventType.removeLayer, this._onRemoveLayerHandler, this);
        this.layerWork.on(mars3d.EventType.removeLayer, this._onRemoveLayerHandler, this);
      }
 
      this.resetStyle();
      this.viewWindow = null;
    }
    getTreeUrl() {
      var url = this.config.layerCfg.url;
      url = url.substring(0, url.lastIndexOf("/") + 1) + this.config.layerCfg.scenetree;
 
      var that = this;
      $.ajax({
        url: url,
        dataType: "json",
        success(scene) {
          that.viewWindow.initSceneTree(scene);
        },
      });
    }
    resetStyle() {
      if (!this.layerWork?.tileset) {
        return;
      }
      this.layerWork.tileset.style = undefined;
    }
    //定位
    locateNode(nodeid, nodesphere) {
      if (nodesphere[3] <= 0) {
        return;
      }
 
      if (!this.layerWork) {
        return;
      }
      this.layerWork.closePopup();
 
      //构件节点位置
      var center = new Cesium.Cartesian3(nodesphere[0], nodesphere[1], nodesphere[2]);
 
      //获取构件节点位置,现对于原始矩阵变化后的新位置
      center = this.layerWork.getPositionByOrginMatrix(center);
 
      //飞行过去
      var sphere = new Cesium.BoundingSphere(center, nodesphere[3]);
      this.map.camera.flyToBoundingSphere(sphere, {
        offset: new Cesium.HeadingPitchRange(this.map.camera.heading, this.map.camera.pitch, nodesphere[3] * 4),
        duration: 0.5,
      });
    }
    showTitleStyle(arrIds) {
      let titleStyle = "";
      //勾选
      arrIds.forEach((element, index) => {
        if (index === 0) {
          titleStyle += "${id} ==='" + element + "' ";
        } else {
          titleStyle += "|| ${id} ==='" + element + "'";
        }
      });
      //设置tileset的样式
      this.layerWork.style = new Cesium.Cesium3DTileStyle({
        color: {
          conditions: [
            [titleStyle, "rgb(255, 255, 255)"],
            ["true", "rgba(255, 200, 200,0.2)"],
          ],
        },
      });
    }
 
    //全部取消
    cancelAll() {
      this.layerWork.style = null;
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);