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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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({ polygon: {} })
  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.polygon.hierarchy = this._computeHierarchy()
  27. return this
  28. }
  29. get center() {
  30. return this._center
  31. }
  32. set radius(radius) {
  33. this._radius = +radius
  34. this._delegate.polygon.hierarchy = this._computeHierarchy()
  35. return this
  36. }
  37. get radius() {
  38. return this._radius
  39. }
  40. set rotateAmount(amount) {
  41. this._rotateAmount = +amount
  42. this._delegate.polygon.stRotation = new Cesium.CallbackProperty(() => {
  43. this._stRotation += this._rotateAmount
  44. if (this._stRotation >= 360 || this._stRotation <= -360) {
  45. this._stRotation = 0
  46. }
  47. return Cesium.Math.toRadians(this._stRotation)
  48. }, false)
  49. return this
  50. }
  51. get rotateAmount() {
  52. return this._rotateAmount
  53. }
  54. /**
  55. *
  56. * @private
  57. */
  58. _computeHierarchy() {
  59. let result = new Cesium.PolygonHierarchy()
  60. let cep = Cesium.EllipseGeometryLibrary.computeEllipsePositions(
  61. {
  62. center: Transform.transformWGS84ToCartesian(this._center),
  63. semiMajorAxis: this._radius,
  64. semiMinorAxis: this._radius,
  65. rotation: 0,
  66. granularity: 0.005
  67. },
  68. false,
  69. true
  70. )
  71. let pnts = Cesium.Cartesian3.unpackArray(cep.outerPositions)
  72. pnts.push(pnts[0])
  73. result.positions = pnts
  74. return result
  75. }
  76. _mountedHook() {
  77. /**
  78. * set the location
  79. */
  80. this.center = this._center
  81. }
  82. /**
  83. * Sets Text with Style
  84. * @param text
  85. * @param textStyle
  86. * @returns {Circle}
  87. */
  88. setLabel(text, textStyle) {
  89. this._delegate.position = Transform.transformWGS84ToCartesian(this._center)
  90. this._delegate.label = {
  91. ...textStyle,
  92. text: text
  93. }
  94. return this
  95. }
  96. /**
  97. *
  98. * @param style
  99. * @returns {Circle}
  100. */
  101. setStyle(style) {
  102. if (!style || Object.keys(style).length === 0) {
  103. return this
  104. }
  105. delete style['positions']
  106. Util.merge(this._style, style)
  107. Util.merge(this._delegate.polygon, style)
  108. return this
  109. }
  110. }
  111. Overlay.registerType('circle')
  112. export default Circle