kongdeqiang
2023-07-31 ae0de0617298a3d276622421c77c72435f4ec068
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
<template>
<div>
  <slot></slot>
</div>
</template>
 
<script>
import commonMixin from '../base/mixins/common.js'
import {createSize} from '../base/factory.js'
 
export default {
  name: 'bm-control',
  mixins: [commonMixin('control')],
  props: ['anchor', 'offset'],
  watch: {
    anchor (val) {
      this.originInstance.setAnchor(val)
    },
    offset (val) {
      this.originInstance.setOffset(val)
    }
  },
  methods: {
    load () {
      const {BMap, map, anchor, offset, $el} = this
      const Control = function () {
        this.defaultAnchor = global[anchor || 'BMAP_ANCHOR_TOP_LEFT']
        this.defaultOffset = createSize(BMap, offset)
      }
      Control.prototype = new BMap.Control()
      Control.prototype.initialize = map => map.getContainer().appendChild($el)
      this.originInstance = new Control(anchor, offset)
      map.addControl(this.originInstance)
    }
  }
}
</script>