選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ElecEllipsoidPrimitive.js 2.4KB

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