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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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._state = State.INITIALIZED
  21. }
  22. get type() {
  23. return Overlay.getOverlayType('scan_circle_primitive')
  24. }
  25. set position(position) {
  26. this._position = Parse.parsePosition(position)
  27. this._delegate.geometryInstances.geometry = new Cesium.EllipseGeometry({
  28. center: Transform.transformWGS84ToCartesian(this._position),
  29. semiMajorAxis: this._radius,
  30. semiMinorAxis: this._radius
  31. })
  32. return this
  33. }
  34. get position() {
  35. return this._position
  36. }
  37. set radius(radius) {
  38. this._radius = radius
  39. this._delegate.geometryInstances.geometry.semiMajorAxis = this._radius
  40. this._delegate.geometryInstances.geometry.semiMinorAxis = this._radius
  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('CircleScan', {
  56. color: this._style?.color || Cesium.Color.WHITE,
  57. speed: this._style?.speed || 10
  58. })
  59. })
  60. }
  61. _mountedHook() {
  62. /**
  63. * set the position
  64. */
  65. this.position = this._position
  66. /**
  67. * set the appearance
  68. */
  69. !this._delegate.appearance && this._setAppearance()
  70. }
  71. /**
  72. * Sets Style
  73. * @param style
  74. * @returns {ScanCirclePrimitive}
  75. */
  76. setStyle(style = {}) {
  77. if (Object.keys(style).length === 0) {
  78. return this
  79. }
  80. this._style = style
  81. style.classificationType &&
  82. (this._delegate.classificationType = this._style.classificationType)
  83. this._setAppearance()
  84. return this
  85. }
  86. }
  87. Overlay.registerType('scan_circle_primitive')
  88. export default ScanCirclePrimitive