Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

CustomBillboard.js 3.1KB

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