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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
| <template>
| <div v-show="panel">
| <slot></slot>
| </div>
| </template>
|
| <script>
| import {createPoint, createBounds} from '../base/factory.js'
| import {isPoint} from '../base/util.js'
| import commonMixin from '../base/mixins/common.js'
|
| export default {
| name: 'bm-local-search',
| mixins: [commonMixin('search')],
| props: {
| location: {
| type: [Object, String]
| },
| keyword: {
| type: [Array, String]
| },
| panel: {
| type: Boolean,
| default: true
| },
| forceLocal: {
| type: Boolean
| },
| customData: {
| type: Object
| },
| bounds: {
| type: Object
| },
| nearby: {
| type: Object
| },
| // page: {
| // type: Number
| // },
| pageCapacity: {
| type: Number
| },
| autoViewport: {
| type: Boolean
| },
| selectFirstResult: {
| type: Boolean
| }
| },
| watch: {
| location: {
| handler (val) {
| const {originInstance, search} = this
| originInstance.setLocation(val || this.map)
| search()
| },
| deep: true
| },
| keyword () {
| this.search()
| },
| bounds: {
| handler (val) {
| const {searchInBounds} = this
| searchInBounds(val)
| },
| deep: true
| },
| nearby: {
| handler (val) {
| const {searchNearby} = this
| searchNearby(val)
| },
| deep: true
| },
| forceLocal () {
| this.reload()
| },
| customData: {
| deep: true,
| handler () {
| this.reload()
| }
| },
| // panel () {
| // this.reload()
| // },
| pageCapacity (val) {
| this.originInstance && this.originInstance.setPageCapacity(val)
| },
| autoViewport (val) {
| this.originInstance && (val ? this.originInstance.enableAutoViewport() : this.originInstance.disableAutoViewport())
| },
| selectFirstResult (val) {
| this.originInstance && (val ? this.originInstance.enableFirstResultSelection() : this.originInstance.disableFirstResultSelection())
| },
| highlightMode () {
| this.reload()
| }
| },
| methods: {
| searchNearby (nearby) {
| const {originInstance, keyword, customData, BMap} = this
| originInstance.searchNearby(keyword, createPoint(BMap, nearby.center), nearby.radius, customData)
| },
| searchInBounds (bounds) {
| const {originInstance, keyword, customData, BMap} = this
| originInstance.searchInBounds(keyword, createBounds(BMap, bounds), customData)
| },
| search () {
| const {originInstance, keyword, forceLocal, customData, nearby, bounds, searchNearby, searchInBounds} = this
| nearby ? searchNearby(nearby) : bounds ? searchInBounds(bounds) : originInstance.search(keyword, {
| forceLocal,
| customData
| })
| },
| load () {
| const instance = this
| const {map, BMap, search, pageCapacity, autoViewport, selectFirstResult, highlightMode, location, originInstance} = this
| const _location = location ? isPoint(location) ? createPoint(BMap, location) : location : map
| const route = this.originInstance = new BMap.LocalSearch(_location, {
| onMarkersSet (e) {
| instance.$emit('markersset', e)
| },
| onInfoHtmlSet (e) {
| instance.$emit('infohtmlset', e)
| },
| onResultsHtmlSet (e) {
| instance.$emit('resultshtmlset', e)
| },
| onSearchComplete (e) {
| if (originInstance && originInstance !== route) {
| originInstance.clearResults()
| }
| instance.$emit('searchcomplete', e)
| },
| pageCapacity: pageCapacity,
| renderOptions: {
| map,
| // panel: panel && this.$el,
| panel: this.$el,
| selectFirstResult,
| autoViewport,
| highlightMode
| }
| })
| search()
| }
| }
| }
| </script>
|
|