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

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