Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ScanCirclePrimitive.js 2.3KB

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