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
66
67
68
69
70
71
72
73
74
75
76
<script>
import commonMixin from '../base/mixins/common.js'
import bindEvents from '../base/bindEvent.js'
import {createPoint} from '../base/factory.js'
 
export default {
  render () {},
  name: 'bm-point-collection',
  mixins: [commonMixin('overlay')],
  props: {
    points: {
      type: Array,
      default () {
        return []
      }
    },
    shape: {
      type: String,
      default: 'BMAP_POINT_SHAPE_CIRCLE'
    },
    color: {
      type: String
    },
    size: {
      type: String,
      default: 'BMAP_POINT_SIZE_NORMAL'
    }
  },
  watch: {
    shape (val) {
      const {originInstance, color, size} = this
      originInstance.setStyles({
        shape: global[val],
        color,
        size: global[size]
      })
    },
    size (val) {
      const {originInstance, color, shape} = this
      originInstance.setStyles({
        shape: global[shape],
        color,
        size: global[val]
      })
    },
    color (val) {
      const {originInstance, shape, size} = this
      originInstance.setStyles({
        shape: global[shape],
        color: val,
        size: global[size]
      })
    },
    points: {
      deep: true,
      handler (val) {
        const {originInstance} = this
        originInstance.clear()
        originInstance.setPoints(val)
      }
    }
  },
  methods: {
    load () {
      const {BMap, map, points, shape, color, size} = this
      const overlay = this.originInstance = new BMap.PointCollection(points.map(p => createPoint(BMap, p)), {
        shape: global[shape],
        color,
        size: global[size]
      })
      bindEvents.call(this, overlay)
      map.addOverlay(overlay)
    }
  }
}
</script>