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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"use script"; //开发环境建议开启严格模式
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //初始化[仅执行1次]
    create() {}
    //打开激活
    activate() {
      this._last_basemap = this.map.basemap?.uuid;
      this.map.basemap = 2017; //切换底图到深色底图
 
      this.map.setCameraView({ lat: 31.314644, lng: 121.515959, alt: 7866, heading: 200, pitch: -43 });
 
      //显示上海建筑物
      this.layerJzw = this.map.getLayer(204012, "id");
      if (this.layerJzw && !this.layerJzw.isAdded) {
        this.layerJzw.marsJzwStyle = true;
        this.layerJzw.style = {
          color: {
            conditions: [["true", "rgb(3, 104, 255)"]],
          },
        };
 
        this.map.addLayer(this.layerJzw, true);
        this._hasRemoveLayer = true;
      }
 
      //创建Graphic图层
      var graphicLayer = new mars3d.layer.GraphicLayer({
        name: this.config.name,
        pid: 99, //图层管理 中使用,父节点id
      });
      this.map.addLayer(graphicLayer);
 
      this.graphicLayer = graphicLayer;
 
      //加一些演示数据
      addGraphic_a1(graphicLayer);
      addGraphic_a2(graphicLayer);
      addGraphic_a3(graphicLayer);
      addGraphic_a4(graphicLayer);
      addGraphic_a5(graphicLayer);
    }
    //关闭释放
    disable() {
      if (this._last_basemap) {
        this.map.basemap = this._last_basemap; //还原底图
        this._last_basemap = null;
      }
 
      if (this.graphicLayer) {
        this.map.removeLayer(this.graphicLayer, true);
        this.graphicLayer = null;
      }
      if (this._hasRemoveLayer && this.layerJzw) {
        this.map.removeLayer(this.layerJzw);
        this._hasRemoveLayer = false;
      }
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  function addGraphic_a1(graphicLayer) {
    //立体围墙扩散效果,面状
    var diffuseWallGlow = new mars3d.graphic.DiffuseWall({
      positions: [
        [121.475616, 31.255374, 5.87],
        [121.482578, 31.248681, 10.85],
        [121.479447, 31.240235, 14.25],
        [121.470002, 31.240496, 12.92],
        [121.46538, 31.249206, 9.53],
        [121.475616, 31.255374, 5.87],
      ],
      style: {
        diffHeight: 2000, //高度
        speed: 10, //速度
      },
    });
    graphicLayer.addGraphic(diffuseWallGlow);
  }
 
  function addGraphic_a2(graphicLayer) {
    //立体围墙扩散效果,圆状
    var circleDiffuseWallGlow = new mars3d.graphic.DiffuseWall({
      position: new mars3d.LatLngPoint(121.481165, 31.278668, 44.3), //圆中心点
      style: {
        radius: 600, //半径
        color: "#ff0000",
        diffHeight: 2000, //高度
        speed: 10, //速度
      },
    });
    graphicLayer.addGraphic(circleDiffuseWallGlow);
  }
 
  function addGraphic_a3(graphicLayer) {
    var primitive = new mars3d.graphic.CirclePrimitive({
      position: [121.522454, 31.267553, 61.9],
      style: {
        radius: 2000,
        material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ScanLine, {
          color: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
          speed: 10,
        }),
        clampToGround: true, //是否贴地
      },
    });
    graphicLayer.addGraphic(primitive);
  }
  function addGraphic_a4(graphicLayer) {
    var _rotation = Math.random();
 
    var graphic = new mars3d.graphic.CircleEntity({
      position: Cesium.Cartesian3.fromDegrees(121.504242, 31.23805, 27.88),
      style: {
        radius: 1500.0,
        //扫描材质
        material: new mars3d.material.CircleScanMaterialProperty({
          url: "img/textures/circleScan.png",
          color: Cesium.Color.fromCssColorString("#00ff00"),
        }),
        stRotation: new Cesium.CallbackProperty(function (e) {
          _rotation -= 0.1;
          return _rotation;
        }, false),
        classificationType: Cesium.ClassificationType.BOTH,
        clampToGround: true, //是否贴地
      },
    });
    graphicLayer.addGraphic(graphic);
  }
 
  function addGraphic_a5(graphicLayer) {
    var _rotation = Math.random();
    var graphic = new mars3d.graphic.CircleEntity({
      position: new mars3d.LatLngPoint(121.526215, 31.245237, 123.5),
      style: {
        radius: 700.0,
        material: new mars3d.material.CircleScanMaterialProperty({
          //扫描材质
          url: "img/textures/circle_bg.png",
          color: Cesium.Color.fromCssColorString("#5fc4ee"),
        }),
        stRotation: new Cesium.CallbackProperty(function (e) {
          _rotation -= 0.1;
          return _rotation;
        }, false),
        classificationType: Cesium.ClassificationType.BOTH,
        clampToGround: true, //是否贴地
      },
    });
    graphicLayer.addGraphic(graphic);
  }
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);