Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Overlay.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-03 12:18:17
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-02-04 14:29:34
  6. */
  7. import OverlayEvent from '../event/OverlayEvent'
  8. class Overlay {
  9. constructor() {
  10. this._id = DC.Util.uuid()
  11. this._layer = undefined
  12. this._state = undefined
  13. this._delegate = undefined
  14. this._show = true
  15. this._style = {}
  16. this._attr = {}
  17. this._overlayEvent = new OverlayEvent()
  18. this._overlayEvent.on(DC.OverlayEventType.ADD, this._addCallback, this)
  19. this._overlayEvent.on(
  20. DC.OverlayEventType.REMOVE,
  21. this._removeCallback,
  22. this
  23. )
  24. this.type = undefined
  25. }
  26. get id() {
  27. return this._id
  28. }
  29. set show(show) {
  30. this._show = show
  31. this._delegate && (this._delegate.show = this._show)
  32. }
  33. get show() {
  34. return this._show
  35. }
  36. set attr(attr) {
  37. this._attr = attr
  38. }
  39. get attr() {
  40. return this._attr
  41. }
  42. get overlayEvent() {
  43. return this._overlayEvent
  44. }
  45. get delegate() {
  46. return this._delegate
  47. }
  48. get state() {
  49. return this._state
  50. }
  51. /***
  52. *
  53. */
  54. _prepareDelegate() {}
  55. /**
  56. *
  57. * @param {*} layer
  58. */
  59. _addCallback(layer) {
  60. this._layer = layer
  61. this._prepareDelegate()
  62. if (this._layer && this._layer.delegate && this._layer.delegate.entities) {
  63. this._layer.delegate.entities.add(this._delegate)
  64. this._state = DC.OverlayState.ADDED
  65. }
  66. }
  67. /**
  68. *
  69. */
  70. _removeCallback() {
  71. if (this._layer && this._layer.delegate && this._layer.delegate.entities) {
  72. this._layer.delegate.entities.remove(this._delegate)
  73. this._state = DC.OverlayState.REMOVED
  74. }
  75. }
  76. /**
  77. *
  78. * @param {*} style
  79. * set overlay style
  80. */
  81. setStyle(style) {}
  82. /**
  83. * 覆盖物删除
  84. */
  85. remove() {
  86. if (this._layer) {
  87. this._layer.layerEvent.fire(DC.LayerEventType.REMOVE_OVERLAY, this)
  88. }
  89. }
  90. /**
  91. *
  92. * @param {*} type
  93. * @param {*} callback
  94. * @param {*} context
  95. */
  96. on(type, callback, context) {
  97. this._overlayEvent.on(type, callback, context || this)
  98. return this
  99. }
  100. /**
  101. *
  102. * @param {*} type
  103. * @param {*} callback
  104. * @param {*} context
  105. */
  106. off(type, callback, context) {
  107. this._overlayEvent.off(type, callback, context || this)
  108. return this
  109. }
  110. /**
  111. *
  112. * @param {*} type
  113. * @param {*} param
  114. */
  115. fire(type, params) {
  116. this._overlayEvent.fire(type, params)
  117. return this
  118. }
  119. }
  120. export default Overlay