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.

ScanCirclePrimitive.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-12-31 11:05:32
  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 ScanCirclePrimitive extends Overlay {
  11. constructor(position, radius) {
  12. super()
  13. this._position = Parse.parsePosition(position)
  14. this._radius = radius
  15. this._delegate = new Cesium.GroundPrimitive({
  16. geometryInstances: new Cesium.GeometryInstance({
  17. geometry: {}
  18. })
  19. })
  20. this.type = Overlay.getOverlayType('scan_circle_primitive')
  21. this._state = State.INITIALIZED
  22. }
  23. set position(position) {
  24. this._position = Parse.parsePosition(position)
  25. this._delegate.geometryInstances.geometry = new Cesium.EllipseGeometry({
  26. center: Transform.transformWGS84ToCartesian(this._position),
  27. semiMajorAxis: this._radius,
  28. semiMinorAxis: this._radius
  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.semiMajorAxis = this._radius
  38. this._delegate.geometryInstances.geometry.semiMinorAxis = this._radius
  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('CircleScan', {
  54. color: this._style?.color || Cesium.Color.WHITE,
  55. speed: this._style?.speed || 10
  56. })
  57. })
  58. }
  59. _mountedHook() {
  60. /**
  61. * set the position
  62. */
  63. this.position = this._position
  64. /**
  65. * set the appearance
  66. */
  67. !this._delegate.appearance && this._setAppearance()
  68. }
  69. /**
  70. * Sets Style
  71. * @param style
  72. * @returns {ScanCirclePrimitive}
  73. */
  74. setStyle(style = {}) {
  75. if (Object.keys(style).length === 0) {
  76. return this
  77. }
  78. this._style = style
  79. style.classificationType &&
  80. (this._delegate.classificationType = this._style.classificationType)
  81. this._setAppearance()
  82. return this
  83. }
  84. }
  85. Overlay.registerType('scan_circle_primitive')
  86. export default ScanCirclePrimitive