Blame view

node_modules/vue-baidu-map/components/extra/Heatmap.vue 1.42 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  <script>
  import commonMixin from '../base/mixins/common.js'
  import Heatmap from 'bmaplib.heatmap'
  
  export default {
    name: 'bml-heatmap',
    render () {},
    mixins: [commonMixin('overlay')],
    props: {
      data: {
        type: Array,
        default: Array
      },
      max: {
        type: Number
      },
      radius: {
        type: Number
      },
      gradient: {
        type: Object
      },
      opacity: {
        type: Number
      }
    },
    watch: {
      data: {
        handler () {
          this.reload()
        },
        deep: true
      },
      max () {
        this.reload()
      },
      radius (val) {
        const {originInstance, opacity, gradient} = this
        originInstance.setOptions({
          radius: val,
          opacity,
          gradient
        })
      },
      gradient: {
        handler (val) {
          const {originInstance, radius, opacity} = this
          originInstance.setOptions({
            radius,
            opacity,
            gradient: val
          })
        },
        deep: true
      },
      opacity (val) {
        const {originInstance, radius, gradient} = this
        originInstance.setOptions({
          radius,
          opacity: val,
          gradient
        })
      }
    },
    methods: {
      load () {
        const {map, data, max, radius, opacity, gradient} = this
        const overlay = this.originInstance = new Heatmap({
          radius,
          opacity,
          gradient
        })
        map.addOverlay(overlay)
        overlay.setDataSet({data, max})
      }
    }
  }
  </script>