您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Billboard.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-19 10:18:23
  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 Billboard 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._state = State.INITIALIZED
  19. }
  20. get type() {
  21. return Overlay.getOverlayType('billboard')
  22. }
  23. set position(position) {
  24. this._position = Parse.parsePosition(position)
  25. this._delegate.position = Transform.transformWGS84ToCartesian(
  26. this._position
  27. )
  28. return this
  29. }
  30. get position() {
  31. return this._position
  32. }
  33. set icon(icon) {
  34. this._icon = icon
  35. this._delegate.billboard.image = this._icon
  36. return this
  37. }
  38. get icon() {
  39. return this._icon
  40. }
  41. set size(size) {
  42. if (!Array.isArray(size)) {
  43. throw new Error('Billboard: the size invalid')
  44. }
  45. this._size = size
  46. this._delegate.billboard.width = this._size[0] || 32
  47. this._delegate.billboard.height = this._size[1] || 32
  48. return this
  49. }
  50. get size() {
  51. return this._size
  52. }
  53. _mountedHook() {
  54. /**
  55. * set the location
  56. */
  57. this.position = this._position
  58. /**
  59. * initialize the Overlay parameter
  60. */
  61. this.icon = this._icon
  62. this.size = this._size
  63. }
  64. /**
  65. *
  66. * @param style
  67. * @returns {Billboard}
  68. */
  69. setStyle(style) {
  70. if (!style || Object.keys(style).length === 0) {
  71. return this
  72. }
  73. delete style['image'] && delete style['width'] && delete style['height']
  74. Util.merge(this._style, style)
  75. Util.merge(this._delegate.billboard, style)
  76. return this
  77. }
  78. /**
  79. * Parse from entity
  80. * @param entity
  81. * @returns {any}
  82. */
  83. static fromEntity(entity) {
  84. let billboard = undefined
  85. let now = Cesium.JulianDate.now()
  86. let position = Transform.transformCartesianToWGS84(
  87. entity.position.getValue(now)
  88. )
  89. if (entity.billboard) {
  90. billboard = new Billboard(position, entity.billboard.image.getValue(now))
  91. billboard.attr = {
  92. ...entity?.properties?.getValue(now)
  93. }
  94. }
  95. return billboard
  96. }
  97. }
  98. Overlay.registerType('billboard')
  99. export default Billboard