Blame view

node_modules/vue-baidu-map/components/controls/Copyright.vue 1.43 KB
290144e9   易尊强   第一次
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
  <script>
  import commonMixin from '../base/mixins/common.js'
  import {createSize} from '../base/factory.js'
  
  export default {
    name: 'bm-copyright',
    render () {},
    mixins: [commonMixin('control')],
    props: ['anchor', 'offset', 'copyright'],
    watch: {
      anchor () {
        this.reload()
      },
      offset () {
        this.reload()
      },
      copyright () {
        this.reload()
      }
    },
    methods: {
      load () {
        const {BMap, map, offset, anchor, updateCopyrightList} = this
        this.originInstance = new BMap.CopyrightControl({
          anchor: global[anchor],
          offset: offset && createSize(BMap, offset)
        })
        updateCopyrightList()
        map.addControl(this.originInstance)
      },
      updateCopyrightList () {
        const {BMap, map} = this
        const {removeCopyright, getCopyrightCollection} = this.originInstance
        const copyrightList = getCopyrightCollection()
        copyrightList && copyrightList.forEach(item => {
          removeCopyright(item.id)
        })
        this.copyright && this.copyright.forEach(item => {
          const bounds = item.bounds
            ? new BMap.Bounds(new BMap.Point(item.bounds.sw.lng, item.bounds.sw.lat), new BMap.Point(item.bounds.ne.lng, item.bounds.ne.lat))
            : map.getBounds()
          this.originInstance.addCopyright({
            id: item.id,
            content: item.content,
            bounds
          })
          this.originInstance.getCopyrightCollection()
        })
      }
    }
  }
  </script>