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.1KB

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