Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Billboard.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-19 10:18:23
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-06-25 08:54:07
  6. */
  7. import { Util } from '../../utils'
  8. import Transform from '../../transform/Transform'
  9. import Parse from '../../parse/Parse'
  10. import State from '../../state/State'
  11. import Overlay from '../Overlay'
  12. const { Cesium } = DC.Namespace
  13. class Billboard extends Overlay {
  14. constructor(position, icon) {
  15. super()
  16. this._delegate = new Cesium.Entity({ billboard: {} })
  17. this._position = Parse.parsePosition(position)
  18. this._icon = icon
  19. this._size = [32, 32]
  20. this.type = Overlay.getOverlayType('billboard')
  21. this._state = State.INITIALIZED
  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. */
  68. setStyle(style) {
  69. if (!style || Object.keys(style).length === 0) {
  70. return this
  71. }
  72. delete style['image'] && delete style['width'] && delete style['height']
  73. this._style = style
  74. Util.merge(this._delegate.billboard, this._style)
  75. return this
  76. }
  77. /**
  78. *
  79. * @param {*} entity
  80. */
  81. static fromEntity(entity) {
  82. let billboard = undefined
  83. let now = Cesium.JulianDate.now()
  84. let position = Transform.transformCartesianToWGS84(
  85. entity.position.getValue(now)
  86. )
  87. if (entity.billboard) {
  88. billboard = new Billboard(position, entity.billboard.image.getValue(now))
  89. billboard.attr = {
  90. ...entity.properties.getValue(now)
  91. }
  92. }
  93. return billboard
  94. }
  95. }
  96. Overlay.registerType('billboard')
  97. export default Billboard