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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-31 18:57:02
  4. */
  5. import State from '@dc-modules/state/State'
  6. import Parse from '@dc-modules/parse/Parse'
  7. import { Util } from '@dc-modules/utils'
  8. import { Transform } from '@dc-modules/transform'
  9. import Overlay from '../Overlay'
  10. const { Cesium } = DC.Namespace
  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.type = Overlay.getOverlayType('circle')
  20. this._state = State.INITIALIZED
  21. }
  22. set center(center) {
  23. this._center = Parse.parsePosition(center)
  24. this._delegate.polygon.hierarchy = this._computeHierarchy()
  25. return this
  26. }
  27. get center() {
  28. return this._center
  29. }
  30. set radius(radius) {
  31. this._radius = +radius
  32. this._delegate.polygon.hierarchy = this._computeHierarchy()
  33. return this
  34. }
  35. get radius() {
  36. return this._radius
  37. }
  38. set rotateAmount(amount) {
  39. this._rotateAmount = +amount
  40. this._delegate.polygon.stRotation = new Cesium.CallbackProperty(time => {
  41. this._stRotation += this._rotateAmount
  42. if (this._stRotation >= 360 || this._stRotation <= -360) {
  43. this._stRotation = 0
  44. }
  45. return Cesium.Math.toRadians(this._stRotation)
  46. })
  47. return this
  48. }
  49. get rotateAmount() {
  50. return this._rotateAmount
  51. }
  52. /**
  53. *
  54. * @private
  55. */
  56. _computeHierarchy() {
  57. let result = new Cesium.PolygonHierarchy()
  58. let cep = Cesium.EllipseGeometryLibrary.computeEllipsePositions(
  59. {
  60. center: Transform.transformWGS84ToCartesian(this._center),
  61. semiMajorAxis: this._radius,
  62. semiMinorAxis: this._radius,
  63. rotation: 0,
  64. granularity: 0.005
  65. },
  66. false,
  67. true
  68. )
  69. let pnts = Cesium.Cartesian3.unpackArray(cep.outerPositions)
  70. pnts.push(pnts[0])
  71. result.positions = pnts
  72. return result
  73. }
  74. _mountedHook() {
  75. /**
  76. * set the location
  77. */
  78. this.center = this._center
  79. }
  80. /**
  81. *
  82. * @param style
  83. * @returns {Circle}
  84. */
  85. setStyle(style) {
  86. if (!style || Object.keys(style).length === 0) {
  87. return this
  88. }
  89. delete style['positions']
  90. this._style = style
  91. Util.merge(this._delegate.polygon, this._style)
  92. return this
  93. }
  94. }
  95. Overlay.registerType('circle')
  96. export default Circle