kongdeqiang
2023-07-02 fa99d6f0de7d6e7d601542eefa5b040f38c69f98
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
<div v-show="panel">
</div>
</template>
 
<script>
import {createPoint} from '../base/factory.js'
import {isPoint} from '../base/util.js'
import commonMixin from '../base/mixins/common.js'
 
export default {
  name: 'bm-bus',
  mixins: [commonMixin('search')],
  props: {
    location: {
      type: [Object, String]
    },
    keyword: {
      type: String
    },
    panel: {
      type: Boolean,
      default: true
    },
    pageCapacity: {
      type: Number
    },
    autoViewport: {
      type: Boolean
    },
    selectFirstResult: {
      type: Boolean
    }
  },
  watch: {
    location: {
      handler (val) {
        const {originInstance, map} = this
        originInstance.setLocation(val || map)
      },
      deep: true
    },
    keyword (val) {
      this.search(val)
    },
    panel () {
      this.reload()
    },
    autoViewport (val) {
      this.reload()
    },
    selectFirstResult (val) {
      this.reload()
    }
  },
  methods: {
    search (keyword) {
      const {originInstance} = this
      originInstance.getBusList(keyword)
    },
    load () {
      const instance = this
      const {location, selectFirstResult, autoViewport, highlightMode, keyword, search, BMap, map, originInstance} = this
      const _location = location ? isPoint(location) ? createPoint(BMap, location) : location : map
      const route = this.originInstance = new BMap.BusLineSearch(_location, {
        renderOptions: {
          map,
          panel: this.$el,
          selectFirstResult,
          autoViewport,
          highlightMode
        },
        onGetBusListComplete (e) {
          if (originInstance && originInstance !== route) {
            originInstance.clearResults()
          }
          instance.$emit('getbuslistcomplete', e)
        },
        onGetBusLineComplete (e) {
          if (originInstance && originInstance !== route) {
            originInstance.clearResults()
          }
          instance.$emit('getbuslinecomplete', e)
        },
        onBusListHtmlSet (e) {
          instance.$emit('buslisthtmlset', e)
        },
        onBusLineHtmlSet (e) {
          instance.$emit('buslinehtmlset', e)
        },
        onMarkersSet (e) {
          instance.$emit('markersset', e)
        },
        onPolylinesSet (e) {
          instance.$emit('polylinesset', e)
        }
      })
      search(keyword)
    }
  }
}
</script>