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.

BillboardPrimitive.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-06-03 21:06:17
  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. class BillboardPrimitive extends Overlay {
  11. constructor(position, icon) {
  12. super()
  13. this._position = Parse.parsePosition(position)
  14. this._icon = icon
  15. this._size = [32, 32]
  16. this._delegate = {
  17. position: undefined,
  18. image: undefined,
  19. width: 0,
  20. height: 0
  21. }
  22. this._state = State.INITIALIZED
  23. }
  24. get type() {
  25. return Overlay.getOverlayType('billboard_primitive')
  26. }
  27. set position(position) {
  28. this._position = Parse.parsePosition(position)
  29. this._delegate.position = Transform.transformWGS84ToCartesian(
  30. this._position
  31. )
  32. return this
  33. }
  34. get position() {
  35. return this._position
  36. }
  37. set icon(icon) {
  38. this._icon = icon
  39. this._delegate.image = this._icon
  40. return this
  41. }
  42. get icon() {
  43. return this._icon
  44. }
  45. set size(size) {
  46. if (!Array.isArray(size)) {
  47. throw new Error('Billboard Primitive: the size invalid')
  48. }
  49. this._size = size
  50. this._delegate.width = this._size[0] || 32
  51. this._delegate.height = this._size[1] || 32
  52. return this
  53. }
  54. get size() {
  55. return this._size
  56. }
  57. _mountedHook() {
  58. /**
  59. * set the location
  60. */
  61. this.position = this._position
  62. /**
  63. * initialize the Overlay parameter
  64. */
  65. this.icon = this._icon
  66. this.size = this._size
  67. }
  68. /**
  69. *
  70. * @param style
  71. * @returns {BillboardPrimitive}
  72. */
  73. setStyle(style) {
  74. if (!style || Object.keys(style).length === 0) {
  75. return this
  76. }
  77. delete style['position'] &&
  78. delete style['image'] &&
  79. delete style['width'] &&
  80. delete style['height']
  81. Util.merge(this._style, style)
  82. Util.merge(this._delegate, style)
  83. return this
  84. }
  85. }
  86. Overlay.registerType('billboard_primitive')
  87. export default BillboardPrimitive