您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ElecEllipsoidPrimitive.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-01-09 21:40:36
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import State from '@dc-modules/state/State'
  7. import Parse from '@dc-modules/parse/Parse'
  8. import { Transform } from '@dc-modules/transform'
  9. import Overlay from '../Overlay'
  10. class ElecEllipsoidPrimitive extends Overlay {
  11. constructor(position, radius) {
  12. super()
  13. this._position = Parse.parsePosition(position)
  14. this._radius = radius || { x: 10, y: 10, z: 10 }
  15. this._delegate = new Cesium.Primitive({
  16. geometryInstances: new Cesium.GeometryInstance({
  17. geometry: {}
  18. })
  19. })
  20. this._state = State.INITIALIZED
  21. }
  22. get type() {
  23. return Overlay.getOverlayType('elec_ellipsoid_primitive')
  24. }
  25. set position(position) {
  26. this._position = Parse.parsePosition(position)
  27. this._delegate.geometryInstances.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
  28. Transform.transformWGS84ToCartesian(this._position)
  29. )
  30. return this
  31. }
  32. get position() {
  33. return this._position
  34. }
  35. set radius(radius) {
  36. this._radius = radius
  37. this._delegate.geometryInstances.geometry = new Cesium.EllipsoidGeometry({
  38. radii: this._radius,
  39. maximumCone: Cesium.Math.PI_OVER_TWO
  40. })
  41. return this
  42. }
  43. get radius() {
  44. return this._radius
  45. }
  46. /**
  47. *
  48. * @private
  49. */
  50. _setAppearance() {
  51. if (!this._style) {
  52. return
  53. }
  54. this._delegate.appearance = new Cesium.MaterialAppearance({
  55. material: Cesium.Material.fromType('EllipsoidElectric', {
  56. color: this._style?.color || Cesium.Color.GREEN,
  57. speed: this._style?.speed || 5
  58. })
  59. })
  60. }
  61. _mountedHook() {
  62. /**
  63. * set the radius
  64. */
  65. this.radius = this._radius
  66. /**
  67. * set the position
  68. */
  69. this.position = this._position
  70. /**
  71. * set the appearance
  72. */
  73. !this._delegate.appearance && this._setAppearance()
  74. }
  75. /**
  76. *
  77. * @param text
  78. * @param textStyle
  79. * @returns {ElecEllipsoidPrimitive}
  80. */
  81. setLabel(text, textStyle) {
  82. return this
  83. }
  84. /**
  85. * Sets Style
  86. * @param style
  87. * @returns {ElecEllipsoidPrimitive}
  88. */
  89. setStyle(style = {}) {
  90. if (Object.keys(style).length === 0) {
  91. return this
  92. }
  93. this._style = style
  94. this._setAppearance()
  95. return this
  96. }
  97. }
  98. Overlay.registerType('elec_ellipsoid_primitive')
  99. export default ElecEllipsoidPrimitive