Blame view

node_modules/vue-baidu-map/components/search/Transit.vue 3.09 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  <template>
  <div v-show="panel">
    <slot></slot>
  </div>
  </template>
  
  <script>
  import {createPoint} from '../base/factory.js'
  import {isPoint, getPosition} from '../base/util.js'
  import commonMixin from '../base/mixins/common.js'
  
  export default {
    name: 'bm-transit',
    mixins: [commonMixin('search')],
    props: {
      location: {
        type: [Object, String]
      },
      start: {
        type: [Object, String]
      },
      end: {
        type: [Object, String]
      },
      panel: {
        type: Boolean,
        default: true
      },
      policy: {
        type: String
      },
      pageCapacity: {
        type: Number
      },
      autoViewport: {
        type: Boolean
      },
      selectFirstResult: {
        type: Boolean
      }
    },
    watch: {
      location: {
        handler (val) {
          const {originInstance, map} = this
          originInstance.setLocation(val || map)
        },
        deep: true
      },
      start: {
        handler (val) {
          const {originInstance, end, BMap} = this
          originInstance.search(getPosition(BMap, val), getPosition(BMap, end))
        },
        deep: true
      },
      end: {
        handler (val) {
          const {originInstance, start, BMap} = this
          originInstance.search(getPosition(BMap, start), getPosition(BMap, val))
        },
        deep: true
      },
      panel () {
        this.reload()
      },
      policy (val) {
        this.originInstance.setPolicy(global[val])
      },
      pageCapacity (val) {
        this.originInstance && this.originInstance.setPageCapacity(val)
      },
      autoViewport (val) {
        this.originInstance && (val ? this.originInstance.enableAutoViewport() : this.originInstance.disableAutoViewport())
      },
      selectFirstResult () {
        this.reload()
      },
      highlightMode () {
        this.reload()
      }
    },
    methods: {
      search (start, end) {
        const {originInstance} = this
        originInstance.search(start, end)
      },
      load () {
        const instance = this
        const {map, BMap, location, policy, pageCapacity, selectFirstResult, autoViewport, highlightMode, search, start, end, originInstance} = this
        const _location = location ? isPoint(location) ? createPoint(BMap, location) : location : map
        const route = this.originInstance = new BMap.TransitRoute(_location, {
          renderOptions: {
            map,
            // panel: panel && this.$el,
            panel: this.$el,
            selectFirstResult,
            autoViewport,
            highlightMode
          },
          policy: global[policy],
          pageCapacity,
          onSearchComplete (e) {
            if (originInstance && originInstance !== route) {
              originInstance.clearResults()
            }
            instance.$emit('searchcomplete', e)
          },
          onMarkersSet (e) {
            instance.$emit('markersset', e)
          },
          onInfoHtmlSet (e) {
            instance.$emit('infohtmlset', e)
          },
          onPolylinesSet (e) {
            instance.$emit('polylinesset', e)
          },
          onResultsHtmlSet (e) {
            instance.$emit('resultshtmlset', e)
          }
        })
        search(isPoint(start) ? createPoint(BMap, start) : start, isPoint(end) ? createPoint(BMap, end) : end)
      }
    }
  }
  </script>