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