You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ElecEllipsoidPrimitive.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.type = Overlay.getOverlayType('elec_ellipsoid_primitive')
  21. this._state = State.INITIALIZED
  22. }
  23. set position(position) {
  24. this._position = Parse.parsePosition(position)
  25. this._delegate.geometryInstances.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
  26. Transform.transformWGS84ToCartesian(this._position)
  27. )
  28. return this
  29. }
  30. get position() {
  31. return this._position
  32. }
  33. set radius(radius) {
  34. this._radius = radius
  35. this._delegate.geometryInstances.geometry = new Cesium.EllipsoidGeometry({
  36. radii: this._radius,
  37. maximumCone: Cesium.Math.PI_OVER_TWO
  38. })
  39. return this
  40. }
  41. get radius() {
  42. return this._radius
  43. }
  44. /**
  45. *
  46. * @private
  47. */
  48. _setAppearance() {
  49. if (!this._style) {
  50. return
  51. }
  52. this._delegate.appearance = new Cesium.MaterialAppearance({
  53. material: Cesium.Material.fromType('EllipsoidElectric', {
  54. color: this._style?.color || Cesium.Color.GREEN,
  55. speed: this._style?.speed || 5
  56. })
  57. })
  58. }
  59. _mountedHook() {
  60. /**
  61. * set the radius
  62. */
  63. this.radius = this._radius
  64. /**
  65. * set the position
  66. */
  67. this.position = this._position
  68. /**
  69. * set the appearance
  70. */
  71. !this._delegate.appearance && this._setAppearance()
  72. }
  73. /**
  74. *
  75. * @param text
  76. * @param textStyle
  77. * @returns {ElecEllipsoidPrimitive}
  78. */
  79. setLabel(text, textStyle) {
  80. return this
  81. }
  82. /**
  83. * Sets Style
  84. * @param style
  85. * @returns {ElecEllipsoidPrimitive}
  86. */
  87. setStyle(style = {}) {
  88. if (Object.keys(style).length === 0) {
  89. return this
  90. }
  91. this._style = style
  92. this._setAppearance()
  93. return this
  94. }
  95. }
  96. Overlay.registerType('elec_ellipsoid_primitive')
  97. export default ElecEllipsoidPrimitive