Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-31 18:57:02
  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 Circle extends Overlay {
  12. constructor(center, radius) {
  13. super()
  14. this._delegate = new Cesium.Entity({ ellipse: {} })
  15. this._center = Parse.parsePosition(center)
  16. this._radius = +radius || 0
  17. this._rotateAmount = 0
  18. this._stRotation = 0
  19. this._state = State.INITIALIZED
  20. }
  21. get type() {
  22. return Overlay.getOverlayType('circle')
  23. }
  24. set center(center) {
  25. this._center = Parse.parsePosition(center)
  26. this._delegate.position = Transform.transformWGS84ToCartesian(this._center)
  27. return this
  28. }
  29. get center() {
  30. return this._center
  31. }
  32. set radius(radius) {
  33. this._radius = +radius
  34. this._delegate.ellipse.semiMajorAxis = this._radius
  35. this._delegate.ellipse.semiMinorAxis = this._radius
  36. return this
  37. }
  38. get radius() {
  39. return this._radius
  40. }
  41. set rotateAmount(amount) {
  42. this._rotateAmount = +amount
  43. this._delegate.ellipse.stRotation = new Cesium.CallbackProperty(() => {
  44. this._stRotation += this._rotateAmount
  45. if (this._stRotation >= 360 || this._stRotation <= -360) {
  46. this._stRotation = 0
  47. }
  48. return Cesium.Math.toRadians(this._stRotation)
  49. }, false)
  50. return this
  51. }
  52. get rotateAmount() {
  53. return this._rotateAmount
  54. }
  55. _mountedHook() {
  56. /**
  57. * set the location
  58. */
  59. this.center = this._center
  60. this.radius = this._radius
  61. }
  62. /**
  63. * Sets Text with Style
  64. * @param text
  65. * @param textStyle
  66. * @returns {Circle}
  67. */
  68. setLabel(text, textStyle) {
  69. this._delegate.label = {
  70. ...textStyle,
  71. text: text
  72. }
  73. return this
  74. }
  75. /**
  76. *
  77. * @param style
  78. * @returns {Circle}
  79. */
  80. setStyle(style) {
  81. if (!style || Object.keys(style).length === 0) {
  82. return this
  83. }
  84. delete style['position'] &&
  85. delete style['semiMajorAxis'] &&
  86. delete style['semiMinorAxis']
  87. Util.merge(this._style, style)
  88. Util.merge(this._delegate.ellipse, style)
  89. return this
  90. }
  91. }
  92. Overlay.registerType('circle')
  93. export default Circle