pass_b_map_vue2 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +22 -0
- package/.github/ISSUE_TEMPLATE.md +7 -0
- package/.travis.yml +26 -0
- package/CONTRIBUTING.md +27 -0
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/build/compiler.js +127 -0
- package/build/webpack.docs.config.js +86 -0
- package/build/webpack.prod.config.js +24 -0
- package/build/webpack.test.config.js +27 -0
- package/components/base/bindEvent.js +11 -0
- package/components/base/events.js +120 -0
- package/components/base/factory.js +39 -0
- package/components/base/mixins/abstract.js +13 -0
- package/components/base/mixins/common.js +81 -0
- package/components/base/util.js +6 -0
- package/components/context-menu/Item.vue +62 -0
- package/components/context-menu/Menu.vue +52 -0
- package/components/controls/CityList.vue +43 -0
- package/components/controls/Control.vue +37 -0
- package/components/controls/Copyright.vue +52 -0
- package/components/controls/Geolocation.vue +59 -0
- package/components/controls/MapType.vue +39 -0
- package/components/controls/Navigation.vue +55 -0
- package/components/controls/OverviewMap.vue +56 -0
- package/components/controls/Panorama.vue +29 -0
- package/components/controls/Scale.vue +36 -0
- package/components/extra/CurveLine.vue +101 -0
- package/components/extra/Heatmap.vue +78 -0
- package/components/extra/Lushu.vue +125 -0
- package/components/extra/MarkerClusterer.vue +93 -0
- package/components/index.js +98 -0
- package/components/layers/Tile.vue +53 -0
- package/components/layers/Traffic.vue +34 -0
- package/components/map/Map.vue +287 -0
- package/components/map/MapView.vue +9 -0
- package/components/others/AutoComplete.vue +70 -0
- package/components/others/Boundary.vue +60 -0
- package/components/overlays/Circle.vue +170 -0
- package/components/overlays/Ground.vue +65 -0
- package/components/overlays/Icon.vue +0 -0
- package/components/overlays/InfoWindow.vue +137 -0
- package/components/overlays/Label.vue +99 -0
- package/components/overlays/Marker.vue +163 -0
- package/components/overlays/Overlay.vue +55 -0
- package/components/overlays/PointCollection.vue +76 -0
- package/components/overlays/Polygon.vue +105 -0
- package/components/overlays/Polyline.vue +86 -0
- package/components/overlays/Symblo.vue +0 -0
- package/components/search/Bus.vue +102 -0
- package/components/search/Driving.vue +177 -0
- package/components/search/LocalSearch.vue +152 -0
- package/components/search/Transit.vue +126 -0
- package/components/search/Walking.vue +115 -0
- package/index.d.ts +3 -0
- package/index.js +1 -0
- package/karma.conf.js +44 -0
- package/package.json +69 -0
- package/test/map.js +37 -0
- package/test/util/BMap.mock/Map.js +82 -0
- package/test/util/BMap.mock/create-class.js +9 -0
- package/test/util/BMap.mock/index.js +5 -0
- package/test/util/BMap.mock/spy.js +2 -0
- package/test/util/util.js +12 -0
- package/types/auto-complete.d.ts +21 -0
- package/types/base/base-control.d.ts +12 -0
- package/types/base/common.d.ts +127 -0
- package/types/boundary.d.ts +40 -0
- package/types/bus.d.ts +27 -0
- package/types/circle.d.ts +46 -0
- package/types/city-list.d.ts +3 -0
- package/types/control.d.ts +3 -0
- package/types/copyright.d.ts +7 -0
- package/types/curve-line.d.ts +36 -0
- package/types/driving.d.ts +47 -0
- package/types/geolocation.d.ts +18 -0
- package/types/ground.d.ts +24 -0
- package/types/heatmap.d.ts +29 -0
- package/types/index.d.ts +93 -0
- package/types/info-window.d.ts +51 -0
- package/types/item.d.ts +25 -0
- package/types/label.d.ts +35 -0
- package/types/local-search.d.ts +62 -0
- package/types/lushu.d.ts +53 -0
- package/types/map-type.d.ts +13 -0
- package/types/map-view.d.ts +3 -0
- package/types/map.d.ts +87 -0
- package/types/marker-clusterer.d.ts +25 -0
- package/types/marker.d.ts +78 -0
- package/types/menu.d.ts +7 -0
- package/types/navigation.d.ts +18 -0
- package/types/overlay.d.ts +16 -0
- package/types/overview-map.d.ts +14 -0
- package/types/panorama.d.ts +3 -0
- package/types/point-collection.d.ts +26 -0
- package/types/polygon.d.ts +46 -0
- package/types/polyline.d.ts +37 -0
- package/types/scale.d.ts +3 -0
- package/types/tile.d.ts +21 -0
- package/types/traffic.d.ts +8 -0
- package/types/transit.d.ts +39 -0
- package/types/tsconfig.json +17 -0
- package/types/walking.d.ts +35 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<div v-if="!hasBmView" ref="view" style="width: 100%; height: 100%">
|
|
4
|
+
</div>
|
|
5
|
+
<slot></slot>
|
|
6
|
+
</div>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
import bindEvents from '../base/bindEvent.js'
|
|
11
|
+
import {checkType} from '../base/util.js'
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
name: 'bm-map',
|
|
15
|
+
props: {
|
|
16
|
+
ak: {
|
|
17
|
+
type: String
|
|
18
|
+
},
|
|
19
|
+
center: {
|
|
20
|
+
type: [Object, String]
|
|
21
|
+
},
|
|
22
|
+
zoom: {
|
|
23
|
+
type: Number
|
|
24
|
+
},
|
|
25
|
+
minZoom: {
|
|
26
|
+
type: Number
|
|
27
|
+
},
|
|
28
|
+
maxZoom: {
|
|
29
|
+
type: Number
|
|
30
|
+
},
|
|
31
|
+
highResolution: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: true
|
|
34
|
+
},
|
|
35
|
+
mapClick: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
default: true
|
|
38
|
+
},
|
|
39
|
+
mapType: {
|
|
40
|
+
type: String
|
|
41
|
+
},
|
|
42
|
+
dragging: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
default: true
|
|
45
|
+
},
|
|
46
|
+
scrollWheelZoom: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: false
|
|
49
|
+
},
|
|
50
|
+
doubleClickZoom: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
default: true
|
|
53
|
+
},
|
|
54
|
+
keyboard: {
|
|
55
|
+
type: Boolean,
|
|
56
|
+
default: true
|
|
57
|
+
},
|
|
58
|
+
inertialDragging: {
|
|
59
|
+
type: Boolean,
|
|
60
|
+
default: true
|
|
61
|
+
},
|
|
62
|
+
continuousZoom: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
default: true
|
|
65
|
+
},
|
|
66
|
+
pinchToZoom: {
|
|
67
|
+
type: Boolean,
|
|
68
|
+
default: true
|
|
69
|
+
},
|
|
70
|
+
autoResize: {
|
|
71
|
+
type: Boolean,
|
|
72
|
+
default: true
|
|
73
|
+
},
|
|
74
|
+
theme: {
|
|
75
|
+
type: Array
|
|
76
|
+
},
|
|
77
|
+
mapStyle: {
|
|
78
|
+
type: Object
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
watch: {
|
|
82
|
+
center (val, oldVal) {
|
|
83
|
+
const {map, zoom} = this
|
|
84
|
+
if (checkType(val) === 'String' && val !== oldVal) {
|
|
85
|
+
map.centerAndZoom(val, zoom)
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
'center.lng' (val, oldVal) {
|
|
89
|
+
const {BMap, map, zoom, center} = this
|
|
90
|
+
if (val !== oldVal && val >= -180 && val <= 180) {
|
|
91
|
+
map.centerAndZoom(new BMap.Point(val, center.lat), zoom)
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
'center.lat' (val, oldVal) {
|
|
95
|
+
const {BMap, map, zoom, center} = this
|
|
96
|
+
if (val !== oldVal && val >= -74 && val <= 74) {
|
|
97
|
+
map.centerAndZoom(new BMap.Point(center.lng, val), zoom)
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
zoom (val, oldVal) {
|
|
101
|
+
const {map} = this
|
|
102
|
+
if (val !== oldVal && val >= 3 && val <= 19) {
|
|
103
|
+
map.setZoom(val)
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
minZoom (val) {
|
|
107
|
+
const {map} = this
|
|
108
|
+
map.setMinZoom(val)
|
|
109
|
+
},
|
|
110
|
+
maxZoom (val) {
|
|
111
|
+
const {map} = this
|
|
112
|
+
map.setMaxZoom(val)
|
|
113
|
+
},
|
|
114
|
+
highResolution () {
|
|
115
|
+
this.reset()
|
|
116
|
+
},
|
|
117
|
+
mapClick () {
|
|
118
|
+
this.reset()
|
|
119
|
+
},
|
|
120
|
+
mapType (val) {
|
|
121
|
+
const {map} = this
|
|
122
|
+
map.setMapType(global[val])
|
|
123
|
+
},
|
|
124
|
+
dragging (val) {
|
|
125
|
+
const {map} = this
|
|
126
|
+
val ? map.enableDragging() : map.disableDragging()
|
|
127
|
+
},
|
|
128
|
+
scrollWheelZoom (val) {
|
|
129
|
+
const {map} = this
|
|
130
|
+
val ? map.enableScrollWheelZoom() : map.disableScrollWheelZoom()
|
|
131
|
+
},
|
|
132
|
+
doubleClickZoom (val) {
|
|
133
|
+
const {map} = this
|
|
134
|
+
val ? map.enableDoubleClickZoom() : map.disableDoubleClickZoom()
|
|
135
|
+
},
|
|
136
|
+
keyboard (val) {
|
|
137
|
+
const {map} = this
|
|
138
|
+
val ? map.enableKeyboard() : map.disableKeyboard()
|
|
139
|
+
},
|
|
140
|
+
inertialDragging (val) {
|
|
141
|
+
const {map} = this
|
|
142
|
+
val ? map.enableInertialDragging() : map.disableInertialDragging()
|
|
143
|
+
},
|
|
144
|
+
continuousZoom (val) {
|
|
145
|
+
const {map} = this
|
|
146
|
+
val ? map.enableContinuousZoom() : map.disableContinuousZoom()
|
|
147
|
+
},
|
|
148
|
+
pinchToZoom (val) {
|
|
149
|
+
const {map} = this
|
|
150
|
+
val ? map.enablePinchToZoom() : map.disablePinchToZoom()
|
|
151
|
+
},
|
|
152
|
+
autoResize (val) {
|
|
153
|
+
const {map} = this
|
|
154
|
+
val ? map.enableAutoResize() : map.disableAutoResize()
|
|
155
|
+
},
|
|
156
|
+
theme (val) {
|
|
157
|
+
const {map} = this
|
|
158
|
+
map.setMapStyle({styleJson: val})
|
|
159
|
+
},
|
|
160
|
+
'mapStyle.features': {
|
|
161
|
+
handler (val, oldVal) {
|
|
162
|
+
const {map, mapStyle} = this
|
|
163
|
+
const {style, styleJson} = mapStyle
|
|
164
|
+
map.setMapStyle({
|
|
165
|
+
styleJson,
|
|
166
|
+
features: val,
|
|
167
|
+
style
|
|
168
|
+
})
|
|
169
|
+
},
|
|
170
|
+
deep: true
|
|
171
|
+
},
|
|
172
|
+
'mapStyle.style' (val, oldVal) {
|
|
173
|
+
const {map, mapStyle} = this
|
|
174
|
+
const {features, styleJson} = mapStyle
|
|
175
|
+
map.setMapStyle({
|
|
176
|
+
styleJson,
|
|
177
|
+
features,
|
|
178
|
+
style: val
|
|
179
|
+
})
|
|
180
|
+
},
|
|
181
|
+
'mapStyle.styleJson': {
|
|
182
|
+
handler (val, oldVal) {
|
|
183
|
+
const {map, mapStyle} = this
|
|
184
|
+
const {features, style} = mapStyle
|
|
185
|
+
map.setMapStyle({
|
|
186
|
+
styleJson: val,
|
|
187
|
+
features,
|
|
188
|
+
style
|
|
189
|
+
})
|
|
190
|
+
},
|
|
191
|
+
deep: true
|
|
192
|
+
},
|
|
193
|
+
mapStyle (val) {
|
|
194
|
+
const {map, theme} = this
|
|
195
|
+
!theme && map.setMapStyle(val)
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
methods: {
|
|
199
|
+
setMapOptions () {
|
|
200
|
+
const {map, minZoom, maxZoom, mapType, dragging, scrollWheelZoom, doubleClickZoom, keyboard, inertialDragging, continuousZoom, pinchToZoom, autoResize} = this
|
|
201
|
+
minZoom && map.setMinZoom(minZoom)
|
|
202
|
+
maxZoom && map.setMaxZoom(maxZoom)
|
|
203
|
+
mapType && map.setMapType(global[mapType])
|
|
204
|
+
dragging ? map.enableDragging() : map.disableDragging()
|
|
205
|
+
scrollWheelZoom ? map.enableScrollWheelZoom() : map.disableScrollWheelZoom()
|
|
206
|
+
doubleClickZoom ? map.enableDoubleClickZoom() : map.disableDoubleClickZoom()
|
|
207
|
+
keyboard ? map.enableKeyboard() : map.disableKeyboard()
|
|
208
|
+
inertialDragging ? map.enableInertialDragging() : map.disableInertialDragging()
|
|
209
|
+
continuousZoom ? map.enableContinuousZoom() : map.disableContinuousZoom()
|
|
210
|
+
pinchToZoom ? map.enablePinchToZoom() : map.disablePinchToZoom()
|
|
211
|
+
autoResize ? map.enableAutoResize() : map.disableAutoResize()
|
|
212
|
+
},
|
|
213
|
+
init (BMap) {
|
|
214
|
+
if (this.map) {
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
let $el = this.$refs.view
|
|
218
|
+
for (let $node of this.$slots.default || []) {
|
|
219
|
+
if ($node.componentOptions && $node.componentOptions.tag === 'bm-view') {
|
|
220
|
+
this.hasBmView = true
|
|
221
|
+
$el = $node.elm
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const map = new BMap.Map($el, {enableHighResolution: this.highResolution, enableMapClick: this.mapClick})
|
|
225
|
+
this.map = map
|
|
226
|
+
const {setMapOptions, zoom, getCenterPoint, theme, mapStyle} = this
|
|
227
|
+
theme ? map.setMapStyle({styleJson: theme}) : map.setMapStyle(mapStyle)
|
|
228
|
+
setMapOptions()
|
|
229
|
+
bindEvents.call(this, map)
|
|
230
|
+
// 此处强行初始化一次地图 回避一个由于错误的 center 字符串导致初始化失败抛出的错误
|
|
231
|
+
map.reset()
|
|
232
|
+
map.centerAndZoom(getCenterPoint(), zoom)
|
|
233
|
+
this.$emit('ready', {BMap, map})
|
|
234
|
+
// Debug
|
|
235
|
+
// global.map = map
|
|
236
|
+
// global.mapComponent = this
|
|
237
|
+
},
|
|
238
|
+
getCenterPoint () {
|
|
239
|
+
const {center, BMap} = this
|
|
240
|
+
switch (checkType(center)) {
|
|
241
|
+
case 'String': return center
|
|
242
|
+
case 'Object': return new BMap.Point(center.lng, center.lat)
|
|
243
|
+
default: return new BMap.Point()
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
initMap (BMap) {
|
|
247
|
+
this.BMap = BMap
|
|
248
|
+
this.init(BMap)
|
|
249
|
+
},
|
|
250
|
+
getMapScript () {
|
|
251
|
+
if (!global.BMap) {
|
|
252
|
+
const ak = this.ak || this._BMap().ak
|
|
253
|
+
global.BMap = {}
|
|
254
|
+
global.BMap._preloader = new Promise((resolve, reject) => {
|
|
255
|
+
global._initBaiduMap = function () {
|
|
256
|
+
resolve(global.BMap)
|
|
257
|
+
global.document.body.removeChild($script)
|
|
258
|
+
global.BMap._preloader = null
|
|
259
|
+
global._initBaiduMap = null
|
|
260
|
+
}
|
|
261
|
+
const $script = document.createElement('script')
|
|
262
|
+
global.document.body.appendChild($script)
|
|
263
|
+
$script.src = `http://test-pass-api.ibtmap.com/b/_BMapJsApi30/api?v=2.0&ak=${ak}&callback=_initBaiduMap`
|
|
264
|
+
})
|
|
265
|
+
return global.BMap._preloader
|
|
266
|
+
} else if (!global.BMap._preloader) {
|
|
267
|
+
return Promise.resolve(global.BMap)
|
|
268
|
+
} else {
|
|
269
|
+
return global.BMap._preloader
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
reset () {
|
|
273
|
+
const {getMapScript, initMap} = this
|
|
274
|
+
getMapScript()
|
|
275
|
+
.then(initMap)
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
mounted () {
|
|
279
|
+
this.reset()
|
|
280
|
+
},
|
|
281
|
+
data () {
|
|
282
|
+
return {
|
|
283
|
+
hasBmView: false
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
</script>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span>
|
|
3
|
+
<slot>
|
|
4
|
+
<input>
|
|
5
|
+
</slot>
|
|
6
|
+
</span>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
import commonMixin from '../base/mixins/common.js'
|
|
11
|
+
import bindEvents from '../base/bindEvent.js'
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
name: 'bm-autocomplete',
|
|
15
|
+
mixins: [commonMixin()],
|
|
16
|
+
props: {
|
|
17
|
+
types: {
|
|
18
|
+
type: String
|
|
19
|
+
},
|
|
20
|
+
location: {
|
|
21
|
+
type: String
|
|
22
|
+
},
|
|
23
|
+
sugStyle: {
|
|
24
|
+
type: Object,
|
|
25
|
+
default () {
|
|
26
|
+
return {}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
watch: {
|
|
31
|
+
types () {
|
|
32
|
+
this.reload()
|
|
33
|
+
},
|
|
34
|
+
location () {
|
|
35
|
+
this.reload()
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
methods: {
|
|
39
|
+
load () {
|
|
40
|
+
const {BMap, map, $el, types, location, sugStyle} = this
|
|
41
|
+
const input = $el.querySelector('input')
|
|
42
|
+
if (!input) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
this.originInstance = new BMap.Autocomplete({
|
|
46
|
+
input,
|
|
47
|
+
types,
|
|
48
|
+
location: location || map,
|
|
49
|
+
onSearchComplete: e => {
|
|
50
|
+
const $sugs = document.querySelectorAll('.tangram-suggestion-main')
|
|
51
|
+
for (const $sug of $sugs) {
|
|
52
|
+
for (const name in sugStyle) {
|
|
53
|
+
$sug.style[name] = sugStyle[name].toString()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
this.$emit('searchcomplete', e)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// Support v-model
|
|
61
|
+
this.originInstance.addEventListener('onconfirm', e => {
|
|
62
|
+
const val = e.item.value
|
|
63
|
+
this.$emit('input', val.province + val.city + val.district + val.street + val.business)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
bindEvents.call(this, this.originInstance)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="paths.length">
|
|
3
|
+
<bm-polygon
|
|
4
|
+
v-for="(path, index) of paths"
|
|
5
|
+
:key="index"
|
|
6
|
+
:path="path"
|
|
7
|
+
:stroke-color="strokeColor"
|
|
8
|
+
:stroke-weight="strokeWeight"
|
|
9
|
+
:stroke-opacity="strokeOpacity"
|
|
10
|
+
:stroke-style="strokeStyle"
|
|
11
|
+
:fill-opacity="fillOpacity"
|
|
12
|
+
:fill-color="fillColor"
|
|
13
|
+
:mass-clear="massClear"
|
|
14
|
+
:clicking="clicking"
|
|
15
|
+
@click="$emit('click', $event)"
|
|
16
|
+
@dblclick="$emit('dblclick', $event)"
|
|
17
|
+
@mousedown="$emit('mousedown', $event)"
|
|
18
|
+
@mouseup="$emit('mouseup', $event)"
|
|
19
|
+
@mouseout="$emit('mouseout', $event)"
|
|
20
|
+
@mouseover="$emit('mouseover', $event)"
|
|
21
|
+
@remove="$emit('remove', $event)"
|
|
22
|
+
/>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script>
|
|
27
|
+
import BmPolygon from '../overlays/Polygon.vue'
|
|
28
|
+
import commonMixin from '../base/mixins/common.js'
|
|
29
|
+
// import abstractMixin from '../base/mixins/abstract.js'
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
mixins: [
|
|
33
|
+
commonMixin('abstract')
|
|
34
|
+
],
|
|
35
|
+
props: ['name', 'strokeColor', 'strokeWeight', 'strokeOpacity', 'strokeStyle', 'fillColor', 'fillOpacity', 'massClear', 'clicking'],
|
|
36
|
+
data () {
|
|
37
|
+
return {
|
|
38
|
+
paths: []
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
components: {
|
|
42
|
+
BmPolygon
|
|
43
|
+
},
|
|
44
|
+
watch: {
|
|
45
|
+
name () {
|
|
46
|
+
this.reload()
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
methods: {
|
|
50
|
+
load () {
|
|
51
|
+
const {BMap, name} = this
|
|
52
|
+
const bd = new BMap.Boundary()
|
|
53
|
+
bd.get(name, data => {
|
|
54
|
+
this.paths = data.boundaries.map(boundary => (boundary || []).split(';')
|
|
55
|
+
.map(point => (([lng, lat]) => ({lng, lat}))(point.split(',').map(p => +p))))
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import commonMixin from '../base/mixins/common.js'
|
|
3
|
+
import bindEvents from '../base/bindEvent.js'
|
|
4
|
+
import {createPoint} from '../base/factory.js'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
name: 'bm-circle',
|
|
8
|
+
render () {},
|
|
9
|
+
mixins: [commonMixin('overlay')],
|
|
10
|
+
props: {
|
|
11
|
+
center: {
|
|
12
|
+
},
|
|
13
|
+
radius: {
|
|
14
|
+
},
|
|
15
|
+
strokeColor: {
|
|
16
|
+
type: String
|
|
17
|
+
},
|
|
18
|
+
strokeWeight: {
|
|
19
|
+
type: Number
|
|
20
|
+
},
|
|
21
|
+
strokeOpacity: {
|
|
22
|
+
type: Number
|
|
23
|
+
},
|
|
24
|
+
strokeStyle: {
|
|
25
|
+
type: String
|
|
26
|
+
},
|
|
27
|
+
fillColor: {
|
|
28
|
+
type: String
|
|
29
|
+
},
|
|
30
|
+
fillOpacity: {
|
|
31
|
+
type: Number
|
|
32
|
+
},
|
|
33
|
+
massClear: {
|
|
34
|
+
type: Boolean,
|
|
35
|
+
default: true
|
|
36
|
+
},
|
|
37
|
+
clicking: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
default: true
|
|
40
|
+
},
|
|
41
|
+
editing: {
|
|
42
|
+
type: Boolean,
|
|
43
|
+
default: false
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
watch: {
|
|
47
|
+
'center.lng' (val, oldVal) {
|
|
48
|
+
const {BMap, originInstance, isEditing, disableEditing, enableEditing, center, editing} = this
|
|
49
|
+
if (!isEditing) {
|
|
50
|
+
disableEditing()
|
|
51
|
+
const lng = val
|
|
52
|
+
if (val.toString() !== oldVal.toString() && lng >= -180 && lng <= 180) {
|
|
53
|
+
originInstance.setCenter(createPoint(BMap, {lng, lat: center.lat}))
|
|
54
|
+
}
|
|
55
|
+
editing && enableEditing()
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
'center.lat' (val, oldVal) {
|
|
59
|
+
const {BMap, originInstance, isEditing, disableEditing, enableEditing, center, editing} = this
|
|
60
|
+
if (!isEditing) {
|
|
61
|
+
disableEditing()
|
|
62
|
+
const lat = val
|
|
63
|
+
if (val.toString() !== oldVal.toString() && lat >= -74 && lat <= 74) {
|
|
64
|
+
originInstance.setCenter(createPoint(BMap, {lng: center.lng, lat}))
|
|
65
|
+
}
|
|
66
|
+
editing && enableEditing()
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
radius (val, oldVal) {
|
|
70
|
+
const {originInstance, isEditing, disableEditing, enableEditing, editing} = this
|
|
71
|
+
if (!isEditing) {
|
|
72
|
+
disableEditing()
|
|
73
|
+
originInstance.setRadius(val)
|
|
74
|
+
editing && enableEditing()
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
strokeColor (val) {
|
|
78
|
+
this.originInstance.setStrokeColor(val)
|
|
79
|
+
},
|
|
80
|
+
strokeOpacity (val) {
|
|
81
|
+
this.originInstance.setStrokeOpacity(val)
|
|
82
|
+
},
|
|
83
|
+
strokeWeight (val) {
|
|
84
|
+
this.originInstance.setStrokeWeight(val)
|
|
85
|
+
},
|
|
86
|
+
strokeStyle (val) {
|
|
87
|
+
this.originInstance.setStrokeStyle(val)
|
|
88
|
+
},
|
|
89
|
+
fillColor (val) {
|
|
90
|
+
this.originInstance.setFillColor(val)
|
|
91
|
+
},
|
|
92
|
+
fillOpacity (val) {
|
|
93
|
+
this.originInstance.setFillOpacity(val)
|
|
94
|
+
},
|
|
95
|
+
editing (val) {
|
|
96
|
+
val ? this.enableEditing() : this.disableEditing()
|
|
97
|
+
},
|
|
98
|
+
massClear (val) {
|
|
99
|
+
val ? this.originInstance.enableMassClear() : this.originInstance.disableMassClear()
|
|
100
|
+
},
|
|
101
|
+
clicking (val) {
|
|
102
|
+
this.reload()
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
methods: {
|
|
106
|
+
dragStartHandler () {
|
|
107
|
+
this.isEditing = true
|
|
108
|
+
},
|
|
109
|
+
dragEndHandler () {
|
|
110
|
+
this.isEditing = false
|
|
111
|
+
this.bindEditingNodeEvents()
|
|
112
|
+
},
|
|
113
|
+
bindEditingNodeEvents () {
|
|
114
|
+
const {originInstance, editingKey, dragStartHandler, dragEndHandler} = this
|
|
115
|
+
originInstance[editingKey].forEach($node => {
|
|
116
|
+
$node.addEventListener('dragstart', dragStartHandler)
|
|
117
|
+
$node.addEventListener('dragend', dragEndHandler)
|
|
118
|
+
})
|
|
119
|
+
},
|
|
120
|
+
enableEditing () {
|
|
121
|
+
const {originInstance, bindEditingNodeEvents} = this
|
|
122
|
+
originInstance.enableEditing()
|
|
123
|
+
bindEditingNodeEvents()
|
|
124
|
+
},
|
|
125
|
+
disableEditing () {
|
|
126
|
+
const {originInstance} = this
|
|
127
|
+
originInstance.disableEditing()
|
|
128
|
+
},
|
|
129
|
+
getEditingKey (overlay) {
|
|
130
|
+
const stack = []
|
|
131
|
+
overlay.enableEditing()
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
for (const key in overlay) {
|
|
134
|
+
if (overlay[key] && overlay[key].length === 2) {
|
|
135
|
+
stack.push(key)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
overlay.disableEditing()
|
|
139
|
+
for (const key in overlay) {
|
|
140
|
+
if (overlay[key] && overlay[key].length === 0 && ~stack.indexOf(key)) {
|
|
141
|
+
this.editingKey = key
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, 0)
|
|
145
|
+
},
|
|
146
|
+
load () {
|
|
147
|
+
const {BMap, map, center, radius, strokeColor, strokeWeight, strokeOpacity, strokeStyle, fillColor, fillOpacity, editing, massClear, clicking, enableEditing, disableEditing, getEditingKey, editingKey} = this
|
|
148
|
+
const overlay = new BMap.Circle(createPoint(BMap, {lng: center.lng, lat: center.lat}), radius, {
|
|
149
|
+
strokeColor,
|
|
150
|
+
strokeWeight,
|
|
151
|
+
strokeOpacity,
|
|
152
|
+
strokeStyle,
|
|
153
|
+
fillColor,
|
|
154
|
+
fillOpacity,
|
|
155
|
+
// enableEditing: editing,
|
|
156
|
+
enableMassClear: massClear,
|
|
157
|
+
enableClicking: clicking
|
|
158
|
+
})
|
|
159
|
+
this.originInstance = overlay
|
|
160
|
+
map.addOverlay(overlay)
|
|
161
|
+
bindEvents.call(this, overlay)
|
|
162
|
+
// 解决圆形组件无法双向绑定的问题
|
|
163
|
+
!editingKey && getEditingKey(overlay)
|
|
164
|
+
setTimeout(() => {
|
|
165
|
+
editing ? enableEditing() : disableEditing()
|
|
166
|
+
}, 0)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
</script>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import commonMixin from '../base/mixins/common.js'
|
|
3
|
+
import bindEvents from '../base/bindEvent.js'
|
|
4
|
+
import {createBounds} from '../base/factory.js'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
name: 'bm-ground',
|
|
8
|
+
render () {},
|
|
9
|
+
mixins: [commonMixin('overlay')],
|
|
10
|
+
props: {
|
|
11
|
+
bounds: {
|
|
12
|
+
type: Object
|
|
13
|
+
},
|
|
14
|
+
opacity: {
|
|
15
|
+
type: Number
|
|
16
|
+
},
|
|
17
|
+
imageURL: {
|
|
18
|
+
type: String
|
|
19
|
+
},
|
|
20
|
+
displayOnMinLevel: {
|
|
21
|
+
type: Number
|
|
22
|
+
},
|
|
23
|
+
displayOnMaxLevel: {
|
|
24
|
+
type: Number
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
watch: {
|
|
28
|
+
bounds: {
|
|
29
|
+
handler (val) {
|
|
30
|
+
const {BMap} = this
|
|
31
|
+
this.originInstance.setBounds(createBounds(BMap, val))
|
|
32
|
+
},
|
|
33
|
+
deep: true
|
|
34
|
+
},
|
|
35
|
+
opacity (val) {
|
|
36
|
+
this.originInstance.setOpacity(val)
|
|
37
|
+
},
|
|
38
|
+
imageURL (val) {
|
|
39
|
+
this.originInstance.setImageURL(val)
|
|
40
|
+
},
|
|
41
|
+
displayOnMinLevel (val) {
|
|
42
|
+
this.originInstance.setDisplayOnMinLevel(val)
|
|
43
|
+
},
|
|
44
|
+
displayOnMaxLevel (val) {
|
|
45
|
+
this.originInstance.setDisplayOnMaxLevel(val)
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
methods: {
|
|
49
|
+
load () {
|
|
50
|
+
const {BMap, map, bounds, opacity, imageURL, displayOnMinLevel, displayOnMaxLevel} = this
|
|
51
|
+
const overlay = new BMap.GroundOverlay(bounds && createBounds(BMap, bounds), {
|
|
52
|
+
opacity,
|
|
53
|
+
imageURL,
|
|
54
|
+
displayOnMaxLevel,
|
|
55
|
+
displayOnMinLevel
|
|
56
|
+
})
|
|
57
|
+
// option 中配置 https 协议地址无法加载
|
|
58
|
+
overlay.setImageURL(imageURL)
|
|
59
|
+
this.originInstance = overlay
|
|
60
|
+
bindEvents.call(this, overlay)
|
|
61
|
+
map.addOverlay(overlay)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
</script>
|
|
File without changes
|