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.

DynamicBillboard.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-05-05 09:16:35
  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. import DynamicOverlay from './DynamicOverlay'
  12. class DynamicBillboard extends DynamicOverlay {
  13. constructor(position, icon) {
  14. super()
  15. this._posistion = Parse.parsePosition(position)
  16. this._icon = icon
  17. this._delegate = new Cesium.Entity({ billboard: {} })
  18. this.type = Overlay.getOverlayType('dynamic_billboard')
  19. this._state = State.INITIALIZED
  20. }
  21. set icon(icon) {
  22. this._icon = icon
  23. this._delegate.billboard.image = this._icon
  24. return this
  25. }
  26. get icon() {
  27. return this._icon
  28. }
  29. set size(size) {
  30. if (!Array.isArray(size)) {
  31. throw new Error('DynamicBillboard: the size invalid')
  32. }
  33. this._size = size
  34. this._delegate.billboard.width = this._size[0] || 32
  35. this._delegate.billboard.height = this._size[1] || 32
  36. return this
  37. }
  38. get size() {
  39. return this._size
  40. }
  41. _mountedHook() {
  42. /**
  43. * set the location
  44. */
  45. this._samplePosition.forwardExtrapolationType =
  46. Cesium.ExtrapolationType.HOLD
  47. this._startTime = Cesium.JulianDate.now()
  48. this._samplePosition.addSample(
  49. this._startTime,
  50. Transform.transformWGS84ToCartesian(this._posistion)
  51. )
  52. this._delegate.position = this._samplePosition
  53. this._cache.push(this._startTime)
  54. /**
  55. * initialize the Overlay parameter
  56. */
  57. this.icon = this._icon
  58. this.size = this._size
  59. }
  60. /**
  61. *
  62. * @param style
  63. * @returns {DynamicBillboard}
  64. */
  65. setStyle(style) {
  66. if (!style || Object.keys(style).length === 0) {
  67. return this
  68. }
  69. delete style['image'] && delete style['width'] && delete style['height']
  70. this._style = style
  71. Util.merge(this._delegate.billboard, this._style)
  72. return this
  73. }
  74. }
  75. Overlay.registerType('dynamic_billboard')
  76. export default DynamicBillboard