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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<script>
import commonMixin from '../base/mixins/common.js'
import bindEvents from '../base/bindEvent.js'
import {createBounds} from '../base/factory.js'
 
export default {
  name: 'bm-ground',
  render () {},
  mixins: [commonMixin('overlay')],
  props: {
    bounds: {
      type: Object
    },
    opacity: {
      type: Number
    },
    imageURL: {
      type: String
    },
    displayOnMinLevel: {
      type: Number
    },
    displayOnMaxLevel: {
      type: Number
    }
  },
  watch: {
    bounds: {
      handler (val) {
        const {BMap} = this
        this.originInstance.setBounds(createBounds(BMap, val))
      },
      deep: true
    },
    opacity (val) {
      this.originInstance.setOpacity(val)
    },
    imageURL (val) {
      this.originInstance.setImageURL(val)
    },
    displayOnMinLevel (val) {
      this.originInstance.setDisplayOnMinLevel(val)
    },
    displayOnMaxLevel (val) {
      this.originInstance.setDisplayOnMaxLevel(val)
    }
  },
  methods: {
    load () {
      const {BMap, map, bounds, opacity, imageURL, displayOnMinLevel, displayOnMaxLevel} = this
      const overlay = new BMap.GroundOverlay(bounds && createBounds(BMap, bounds), {
        opacity,
        imageURL,
        displayOnMaxLevel,
        displayOnMinLevel
      })
      // option 中配置 https 协议地址无法加载
      overlay.setImageURL(imageURL)
      this.originInstance = overlay
      bindEvents.call(this, overlay)
      map.addOverlay(overlay)
    }
  }
}
</script>