zhaoxing
2023-12-07 e1c6c2df3601bc54bc1445cf9bf9e0da268d5ad8
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
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //初始化[仅执行1次]
    create() {}
    //打开激活
    activate() {
      //创建Graphic图层
      var graphicLayer = new mars3d.layer.GraphicLayer({
        name: this.config.name,
        pid: 99, //图层管理 中使用,父节点id
      });
      this.map.addLayer(graphicLayer);
 
      graphicLayer.bindPopup(function (event) {
        let item = event.graphic?.attr;
        var inhtml = "管线长度:" + item.changdu + "米<br/>管径:" + item.guanjin + "mm";
        return inhtml;
      });
 
      this.graphicLayer = graphicLayer;
 
      //添加管道示例数据
      $.getJSON("//data.mars3d.cn/file/geojson/pipeline.json", (geojson) => {
        //循环每个面
 
        let arr = mars3d.Util.geoJsonToGraphics(geojson);
 
        for (let i = 0; i < arr.length; i++) {
          let graphicOptions = arr[i];
 
          var radius = graphicOptions.attr.guanjin / 80;
          if (radius < 2) {
            radius = 2;
          }
 
          var primitive = new mars3d.graphic.PolylineVolumePrimitive({
            positions: graphicOptions.positions,
            style: {
              shape: "pipeline",
              radius: radius,
              material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.Color, {
                color: Cesium.Color.BLUE,
              }),
            },
            attr: graphicOptions.attr,
          });
          this.graphicLayer.addGraphic(primitive);
        }
 
        console.log("管线加载完成,共" + arr.length + "条");
 
        this.graphicLayer.flyTo();
      });
    }
    //关闭释放
    disable() {
      this.map.removeLayer(this.graphicLayer, true);
      this.graphicLayer = null;
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);