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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-01-09 21:40:36
  4. */
  5. import State from '@dc-modules/state/State'
  6. import Parse from '@dc-modules/parse/Parse'
  7. import { Transform } from '@dc-modules/transform'
  8. import Overlay from '../Overlay'
  9. const { Cesium } = DC.Namespace
  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. * Sets Style
  75. * @param style
  76. * @returns {ElecEllipsoidPrimitive}
  77. */
  78. setStyle(style = {}) {
  79. if (Object.keys(style).length === 0) {
  80. return this
  81. }
  82. this._style = style
  83. this._setAppearance()
  84. return this
  85. }
  86. }
  87. export default ElecEllipsoidPrimitive