Overlay.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div>
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. import commonMixin from '../base/mixins/common.js'
  8. export default {
  9. name: 'bm-overlay',
  10. emits: ['initialize', 'draw'],
  11. mixins: [commonMixin('overlay')],
  12. props: {
  13. pane: {
  14. type: String
  15. }
  16. },
  17. watch: {
  18. pane() {
  19. this.reload()
  20. }
  21. },
  22. methods: {
  23. load() { },
  24. mountedLoad() {
  25. const { BMap, map, $el, pane } = this
  26. const $emit = this.$emit.bind(this)
  27. class CustomOverlay extends BMap.Overlay {
  28. initialize() {
  29. $emit('initialize', {
  30. BMap,
  31. map,
  32. el: $el,
  33. overlay: this
  34. })
  35. try {
  36. map.getPanes()[pane].appendChild($el)
  37. } catch (e) { }
  38. return $el
  39. }
  40. draw() {
  41. $emit('draw', {
  42. BMap,
  43. map,
  44. el: $el,
  45. overlay: this
  46. })
  47. }
  48. }
  49. const overlay = new CustomOverlay()
  50. this.originInstance = overlay
  51. map.addOverlay(overlay)
  52. }
  53. }
  54. }
  55. </script>