Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-02-12 21:44:24
  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 CustomBillboard extends Overlay {
  12. constructor(position, icon) {
  13. super()
  14. this._delegate = new Cesium.Entity({ billboard: {} })
  15. this._position = Parse.parsePosition(position)
  16. this._icon = icon
  17. this._size = [32, 32]
  18. this.type = Overlay.getOverlayType('custom_billboard')
  19. this._state = State.INITIALIZED
  20. }
  21. get type() {
  22. return Overlay.getOverlayType('custom_billboard')
  23. }
  24. set position(position) {
  25. this._position = Parse.parsePosition(position)
  26. this._delegate.position = Transform.transformWGS84ToCartesian(
  27. this._position
  28. )
  29. return this
  30. }
  31. get position() {
  32. return this._position
  33. }
  34. set icon(icon) {
  35. this._icon = icon
  36. this._delegate.billboard.image = this._icon
  37. return this
  38. }
  39. get icon() {
  40. return this._icon
  41. }
  42. set size(size) {
  43. if (!Array.isArray(size)) {
  44. throw new Error('CustomBillboard: the size invalid')
  45. }
  46. this._size = size
  47. this._delegate.billboard.width = this._size[0] || 32
  48. this._delegate.billboard.height = this._size[1] || 32
  49. return this
  50. }
  51. get size() {
  52. return this._size
  53. }
  54. _mountedHook() {
  55. /**
  56. * set the location
  57. */
  58. this.position = this._position
  59. /**
  60. * initialize the Overlay parameter
  61. */
  62. this.icon = this._icon
  63. this.size = this._size
  64. }
  65. /**
  66. * Sets label
  67. * @param text
  68. * @param textStyle
  69. * @returns {CustomBillboard}
  70. */
  71. setLabel(text, textStyle) {
  72. this._delegate.label = {
  73. ...textStyle,
  74. text: text
  75. }
  76. return this
  77. }
  78. /**
  79. * Sets Style
  80. * @param style
  81. * @returns {CustomBillboard}
  82. */
  83. setStyle(style) {
  84. if (!style || Object.keys(style).length === 0) {
  85. return this
  86. }
  87. delete style['image'] && delete style['width'] && delete style['height']
  88. this._style = style
  89. Util.merge(this._delegate.billboard, this._style)
  90. return this
  91. }
  92. /**
  93. * Sets VLine style
  94. * @param style
  95. * @returns {CustomBillboard}
  96. */
  97. setVLine(style = {}) {
  98. if (this._position.alt > 0 && !this._delegate.polyline) {
  99. let position = this._position.copy()
  100. position.alt = style.height || 0
  101. this._delegate.polyline = {
  102. ...style,
  103. positions: Transform.transformWGS84ArrayToCartesianArray([
  104. position,
  105. this._position
  106. ])
  107. }
  108. }
  109. return this
  110. }
  111. /**
  112. * @param {*} radius
  113. * @param {*} style
  114. * @param {*} rotateAmount
  115. */
  116. setBottomCircle(radius, style = {}, rotateAmount = 0) {
  117. let stRotation = 0
  118. let amount = rotateAmount
  119. this._delegate.ellipse = {
  120. ...style,
  121. semiMajorAxis: radius,
  122. semiMinorAxis: radius,
  123. stRotation: new Cesium.CallbackProperty(() => {
  124. stRotation += amount
  125. if (stRotation >= 360 || stRotation <= -360) {
  126. stRotation = 0
  127. }
  128. return stRotation
  129. })
  130. }
  131. return this
  132. }
  133. }
  134. Overlay.registerType('custom_billboard')
  135. export default CustomBillboard