一些技术路线测试,增加git,方便代码还原
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
/**
 * @Author : Caven Chen
 */
 
import { Cesium } from '../../../libs'
import State from '../../state/State'
import { Util } from '../../utils'
import IMG from '../../images/cloud.jpg'
 
class Cloud {
  constructor(viewer) {
    this._id = Util.uuid()
    this._viewer = viewer
    this._delegate = undefined
    this._rotateAmount = 0
    this._enable = false
    this._heading = 0
    this._state = State.INITIALIZED
  }
 
  get type() {
    return 'cloud'
  }
 
  set enable(enable) {
    if (!this._viewer.scene.mode === Cesium.SceneMode.SCENE3D) {
      return
    }
    if (!this._delegate) {
      this._createPrimitive()
    }
    this._enable = this._delegate.show = enable
    if (this._enable) {
      this._viewer.scene.postUpdate.addEventListener(this._onRotate, this)
    } else {
      this._viewer.scene.postUpdate.removeEventListener(this._onRotate, this)
    }
  }
 
  get enable() {
    return this._enable
  }
 
  set rotateAmount(rotateAmount) {
    this._rotateAmount = rotateAmount
  }
 
  get rotateAmount() {
    return this._rotateAmount
  }
 
  /**
   *
   * @param scene
   * @param time
   * @private
   */
  _onRotate(scene, time) {
    if (this._rotateAmount === 0) {
      return
    }
    this._heading += this._rotateAmount
    if (this._heading >= 360 || this._heading <= -360) {
      this._heading = 0
    }
    this._delegate.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
      new Cesium.Cartesian3(),
      new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(this._heading), 0, 0)
    )
  }
 
  /**
   *
   * @private
   */
  _createPrimitive() {
    this._delegate = new Cesium.Primitive({
      appearance: new Cesium.EllipsoidSurfaceAppearance({
        material: new Cesium.Material({
          fabric: {
            type: 'Image',
            uniforms: {
              color: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
              image: IMG,
            },
            components: {
              alpha:
                'texture(image, fract(repeat * materialInput.st)).r * color.a',
              diffuse: 'vec3(1.0)',
            },
          },
        }),
        translucent: true,
        aboveGround: true,
      }),
    })
    this._delegate.geometryInstances = new Cesium.GeometryInstance({
      geometry: new Cesium.EllipsoidGeometry({
        vertexFormat: Cesium.VertexFormat.POSITION_AND_ST,
        radii: this._viewer.scene.globe.ellipsoid.radii,
      }),
      id: this._id,
    })
    this._delegate.show = this._enable
    this._viewer.scene.primitives.add(this._delegate)
  }
}
 
export default Cloud