Overlay.vue 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. mixins: [commonMixin('overlay')],
  11. props: {
  12. pane: {
  13. type: String
  14. }
  15. },
  16. watch: {
  17. pane () {
  18. this.reload()
  19. }
  20. },
  21. methods: {
  22. load () {
  23. const {BMap, map, $el, pane} = this
  24. const $emit = this.$emit.bind(this)
  25. class CustomOverlay extends BMap.Overlay {
  26. initialize () {
  27. $emit('initialize', {
  28. BMap,
  29. map,
  30. el: $el,
  31. overlay: this
  32. })
  33. try {
  34. map.getPanes()[pane].appendChild($el)
  35. } catch (e) {}
  36. return $el
  37. }
  38. draw () {
  39. $emit('draw', {
  40. BMap,
  41. map,
  42. el: $el,
  43. overlay: this
  44. })
  45. }
  46. }
  47. const overlay = new CustomOverlay()
  48. this.originInstance = overlay
  49. map.addOverlay(overlay)
  50. }
  51. }
  52. }
  53. </script>