vue-baidu-map-api-v3 1.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/LICENSE +21 -0
- package/README.md +95 -0
- package/README.zh.md +97 -0
- package/components/base/bindEvent.js +11 -0
- package/components/base/events.js +120 -0
- package/components/base/factory.js +63 -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 +302 -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 +107 -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.js +1 -0
- package/package.json +104 -0
- package/types/auto-complete.d.ts +22 -0
- package/types/base/base-control.d.ts +14 -0
- package/types/base/common.d.ts +171 -0
- package/types/base/component.d.ts +5 -0
- package/types/boundary.d.ts +41 -0
- package/types/bus.d.ts +28 -0
- package/types/circle.d.ts +47 -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 +37 -0
- package/types/driving.d.ts +48 -0
- package/types/geolocation.d.ts +18 -0
- package/types/ground.d.ts +25 -0
- package/types/heatmap.d.ts +29 -0
- package/types/index.d.ts +93 -0
- package/types/info-window.d.ts +52 -0
- package/types/item.d.ts +26 -0
- package/types/label.d.ts +36 -0
- package/types/local-search.d.ts +63 -0
- package/types/lushu.d.ts +54 -0
- package/types/map-type.d.ts +13 -0
- package/types/map-view.d.ts +4 -0
- package/types/map.d.ts +88 -0
- package/types/marker-clusterer.d.ts +26 -0
- package/types/marker.d.ts +79 -0
- package/types/menu.d.ts +8 -0
- package/types/navigation.d.ts +18 -0
- package/types/overlay.d.ts +17 -0
- package/types/overview-map.d.ts +14 -0
- package/types/panorama.d.ts +3 -0
- package/types/point-collection.d.ts +27 -0
- package/types/polygon.d.ts +47 -0
- package/types/polyline.d.ts +43 -0
- package/types/scale.d.ts +3 -0
- package/types/tile.d.ts +22 -0
- package/types/traffic.d.ts +9 -0
- package/types/transit.d.ts +40 -0
- package/types/tsconfig.json +17 -0
- package/types/walking.d.ts +36 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span>
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</span>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import MarkerClusterer from 'bmaplib.markerclusterer'
|
|
9
|
+
import {createSize} from '../base/factory.js'
|
|
10
|
+
import commonMixin from '../base/mixins/common.js'
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
name: 'bml-marker-clusterer',
|
|
14
|
+
mixins: [commonMixin('markerClusterer')],
|
|
15
|
+
props: {
|
|
16
|
+
gridSize: {
|
|
17
|
+
type: Object
|
|
18
|
+
},
|
|
19
|
+
maxZoom: {
|
|
20
|
+
type: Number
|
|
21
|
+
},
|
|
22
|
+
minClusterSize: {
|
|
23
|
+
type: Number
|
|
24
|
+
},
|
|
25
|
+
styles: {
|
|
26
|
+
type: Array,
|
|
27
|
+
default () {
|
|
28
|
+
return []
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
averageCenter: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: false
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
watch: {
|
|
37
|
+
gridSize: {
|
|
38
|
+
handler (val) {
|
|
39
|
+
const {BMap, originInstance} = this
|
|
40
|
+
originInstance.setGridSize(BMap, val.map)
|
|
41
|
+
},
|
|
42
|
+
deep: true
|
|
43
|
+
},
|
|
44
|
+
maxZoom (val) {
|
|
45
|
+
const {originInstance} = this
|
|
46
|
+
originInstance.setMaxZoom(val)
|
|
47
|
+
},
|
|
48
|
+
minClusterSize: {
|
|
49
|
+
handler (val) {
|
|
50
|
+
const {BMap, originInstance} = this
|
|
51
|
+
originInstance.setMinClusterSize(createSize(BMap, val))
|
|
52
|
+
},
|
|
53
|
+
deep: true
|
|
54
|
+
},
|
|
55
|
+
styles: {
|
|
56
|
+
handler (val) {
|
|
57
|
+
const {BMap, originInstance} = this
|
|
58
|
+
const obj = JSON.parse(JSON.stringify(val)).map(item => {
|
|
59
|
+
item.size = item.size && createSize(BMap, item.size)
|
|
60
|
+
return item
|
|
61
|
+
})
|
|
62
|
+
originInstance.setStyles(obj)
|
|
63
|
+
},
|
|
64
|
+
deep: true
|
|
65
|
+
},
|
|
66
|
+
averageCenter (val) {
|
|
67
|
+
this.reload()
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
methods: {
|
|
71
|
+
load () {
|
|
72
|
+
const {BMap, map, gridSize, minClusterSize, maxZoom, styles, averageCenter} = this
|
|
73
|
+
this.originInstance = new MarkerClusterer(map, {
|
|
74
|
+
gridSize: gridSize && createSize(BMap, gridSize),
|
|
75
|
+
maxZoom,
|
|
76
|
+
minClusterSize: minClusterSize && createSize(BMap, minClusterSize),
|
|
77
|
+
styles: styles.map(item => {
|
|
78
|
+
item.size = createSize(BMap, item.size)
|
|
79
|
+
return item
|
|
80
|
+
}),
|
|
81
|
+
isAverageCenter: averageCenter
|
|
82
|
+
})
|
|
83
|
+
this.$nextTick(() => {
|
|
84
|
+
const markers = this.$children.map(inst => inst.originInstance).filter(marker => marker instanceof BMap.Marker)
|
|
85
|
+
this.originInstance.addMarkers(markers)
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
beforeCreate () {
|
|
90
|
+
this.preventChildrenRender = true
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
</script>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import BaiduMap from './map/Map.vue'
|
|
2
|
+
import BmView from './map/MapView.vue'
|
|
3
|
+
import BmScale from './controls/Scale.vue'
|
|
4
|
+
import BmNavigation from './controls/Navigation.vue'
|
|
5
|
+
import BmMapType from './controls/MapType.vue'
|
|
6
|
+
import BmOverviewMap from './controls/OverviewMap.vue'
|
|
7
|
+
import BmGeolocation from './controls/Geolocation.vue'
|
|
8
|
+
import BmCopyright from './controls/Copyright.vue'
|
|
9
|
+
import BmCityList from './controls/CityList.vue'
|
|
10
|
+
import BmPanorama from './controls/Panorama.vue'
|
|
11
|
+
import BmControl from './controls/Control.vue'
|
|
12
|
+
import BmMarker from './overlays/Marker.vue'
|
|
13
|
+
import BmPointCollection from './overlays/PointCollection.vue'
|
|
14
|
+
import BmPolyline from './overlays/Polyline.vue'
|
|
15
|
+
import BmPolygon from './overlays/Polygon.vue'
|
|
16
|
+
import BmCircle from './overlays/Circle.vue'
|
|
17
|
+
import BmGround from './overlays/Ground.vue'
|
|
18
|
+
import BmLabel from './overlays/Label.vue'
|
|
19
|
+
import BmInfoWindow from './overlays/InfoWindow.vue'
|
|
20
|
+
import BmOverlay from './overlays/Overlay.vue'
|
|
21
|
+
import BmContextMenu from './context-menu/Menu.vue'
|
|
22
|
+
import BmContextMenuItem from './context-menu/Item.vue'
|
|
23
|
+
import BmLocalSearch from './search/LocalSearch.vue'
|
|
24
|
+
import BmTransit from './search/Transit.vue'
|
|
25
|
+
import BmWalking from './search/Walking.vue'
|
|
26
|
+
import BmDriving from './search/Driving.vue'
|
|
27
|
+
import BmBus from './search/Bus.vue'
|
|
28
|
+
import BmTile from './layers/Tile.vue'
|
|
29
|
+
import BmTraffic from './layers/Traffic.vue'
|
|
30
|
+
import BmBoundary from './others/Boundary.vue'
|
|
31
|
+
import BmAutoComplete from './others/AutoComplete.vue'
|
|
32
|
+
|
|
33
|
+
import BmlMarkerClusterer from './extra/MarkerClusterer.vue'
|
|
34
|
+
import BmlLushu from './extra/Lushu.vue'
|
|
35
|
+
import BmlHeatmap from './extra/Heatmap.vue'
|
|
36
|
+
import BmlCurveLine from './extra/CurveLine.vue'
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
install (Vue, options) {
|
|
40
|
+
const {ak, apiV} = options
|
|
41
|
+
Vue.prototype._BMap = () => ({ak, apiV})
|
|
42
|
+
|
|
43
|
+
Vue.component('baidu-map', BaiduMap)
|
|
44
|
+
Vue.component('bm-view', BmView)
|
|
45
|
+
|
|
46
|
+
Vue.component('bm-scale', BmScale)
|
|
47
|
+
Vue.component('bm-navigation', BmNavigation)
|
|
48
|
+
Vue.component('bm-map-type', BmMapType)
|
|
49
|
+
Vue.component('bm-overview-map', BmOverviewMap)
|
|
50
|
+
Vue.component('bm-geolocation', BmGeolocation)
|
|
51
|
+
Vue.component('bm-copyright', BmCopyright)
|
|
52
|
+
Vue.component('bm-city-list', BmCityList)
|
|
53
|
+
Vue.component('bm-panorama', BmPanorama)
|
|
54
|
+
Vue.component('bm-control', BmControl)
|
|
55
|
+
|
|
56
|
+
Vue.component('bm-marker', BmMarker)
|
|
57
|
+
Vue.component('bm-point-collection', BmPointCollection)
|
|
58
|
+
Vue.component('bm-polyline', BmPolyline)
|
|
59
|
+
Vue.component('bm-polygon', BmPolygon)
|
|
60
|
+
Vue.component('bm-circle', BmCircle)
|
|
61
|
+
Vue.component('bm-ground', BmGround)
|
|
62
|
+
Vue.component('bm-label', BmLabel)
|
|
63
|
+
Vue.component('bm-info-window', BmInfoWindow)
|
|
64
|
+
Vue.component('bm-overlay', BmOverlay)
|
|
65
|
+
|
|
66
|
+
Vue.component('bm-context-menu', BmContextMenu)
|
|
67
|
+
Vue.component('bm-context-menu-item', BmContextMenuItem)
|
|
68
|
+
|
|
69
|
+
Vue.component('bm-local-search', BmLocalSearch)
|
|
70
|
+
Vue.component('bm-transit', BmTransit)
|
|
71
|
+
Vue.component('bm-walking', BmWalking)
|
|
72
|
+
Vue.component('bm-driving', BmDriving)
|
|
73
|
+
Vue.component('bm-bus', BmBus)
|
|
74
|
+
|
|
75
|
+
Vue.component('bm-tile', BmTile)
|
|
76
|
+
Vue.component('bm-traffic', BmTraffic)
|
|
77
|
+
|
|
78
|
+
Vue.component('bm-auto-complete', BmAutoComplete)
|
|
79
|
+
Vue.component('bm-boundary', BmBoundary)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
BaiduMap, BmView,
|
|
85
|
+
BmScale, BmNavigation, BmMapType, BmOverviewMap, BmGeolocation, BmCopyright, BmCityList, BmPanorama, BmControl,
|
|
86
|
+
BmMarker, BmPointCollection, BmPolyline, BmPolygon, BmCircle, BmGround, BmLabel, BmInfoWindow, BmOverlay,
|
|
87
|
+
BmContextMenu, BmContextMenuItem,
|
|
88
|
+
BmLocalSearch, BmTransit, BmWalking, BmDriving, BmBus,
|
|
89
|
+
BmTile, BmTraffic,
|
|
90
|
+
BmBoundary, BmAutoComplete
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
BmlMarkerClusterer,
|
|
95
|
+
BmlLushu,
|
|
96
|
+
BmlHeatmap,
|
|
97
|
+
BmlCurveLine
|
|
98
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import commonMixin from '../base/mixins/common.js'
|
|
3
|
+
import {createBounds} from '../base/factory.js'
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
name: 'bm-tile',
|
|
7
|
+
render (h) {},
|
|
8
|
+
mixins: [commonMixin('layer')],
|
|
9
|
+
props: {
|
|
10
|
+
transparentPng: {
|
|
11
|
+
type: Boolean
|
|
12
|
+
},
|
|
13
|
+
tileUrlTemplate: {
|
|
14
|
+
type: String
|
|
15
|
+
},
|
|
16
|
+
copyright: {
|
|
17
|
+
},
|
|
18
|
+
zIndex: {
|
|
19
|
+
type: Number
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
watch: {
|
|
23
|
+
transparentPng () {
|
|
24
|
+
this.reload()
|
|
25
|
+
},
|
|
26
|
+
tileUrlTemplate () {
|
|
27
|
+
this.reload()
|
|
28
|
+
},
|
|
29
|
+
copyright () {
|
|
30
|
+
this.reload()
|
|
31
|
+
},
|
|
32
|
+
zIndex () {
|
|
33
|
+
this.reload()
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
methods: {
|
|
37
|
+
load () {
|
|
38
|
+
const {BMap, map, transparentPng, tileUrlTemplate, copyright, zIndex} = this
|
|
39
|
+
this.originInstance = new BMap.TileLayer({
|
|
40
|
+
transparentPng,
|
|
41
|
+
tileUrlTemplate,
|
|
42
|
+
copyright: copyright && {
|
|
43
|
+
id: copyright.id,
|
|
44
|
+
content: copyright.content,
|
|
45
|
+
bounds: copyright.bounds && createBounds(copyright.bounds)
|
|
46
|
+
},
|
|
47
|
+
zIndex
|
|
48
|
+
})
|
|
49
|
+
map.addTileLayer(this.originInstance)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import commonMixin from '../base/mixins/common.js'
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: 'bm-triffic',
|
|
6
|
+
render (h) {},
|
|
7
|
+
mixins: [commonMixin('layer')],
|
|
8
|
+
props: {
|
|
9
|
+
predictDate: {
|
|
10
|
+
type: Object
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
watch: {
|
|
14
|
+
'pridictDate.weekday' () {
|
|
15
|
+
this.reload()
|
|
16
|
+
},
|
|
17
|
+
'pridictDate.hour' () {
|
|
18
|
+
this.reload()
|
|
19
|
+
},
|
|
20
|
+
pridictDate () {
|
|
21
|
+
this.reload()
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
methods: {
|
|
25
|
+
load () {
|
|
26
|
+
const {pridictDate, BMap, map} = this
|
|
27
|
+
this.originInstance = new BMap.TrafficLayer({
|
|
28
|
+
pridictDate
|
|
29
|
+
})
|
|
30
|
+
map.addTileLayer(this.originInstance)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
@@ -0,0 +1,302 @@
|
|
|
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
|
+
/**
|
|
20
|
+
* 自定义的百度地图API地址,对于需要私有化部署百度地图服务的公司,可以在这里制定api,不指定则默认使用“https://api.map.baidu.com/api”
|
|
21
|
+
*/
|
|
22
|
+
apiSrc: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: 'https://api.map.baidu.com/api',
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* 自定义版本号,默认为3.0
|
|
28
|
+
*/
|
|
29
|
+
apiV: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: '3.0',
|
|
32
|
+
},
|
|
33
|
+
center: {
|
|
34
|
+
type: [Object, String]
|
|
35
|
+
},
|
|
36
|
+
zoom: {
|
|
37
|
+
type: Number
|
|
38
|
+
},
|
|
39
|
+
minZoom: {
|
|
40
|
+
type: Number
|
|
41
|
+
},
|
|
42
|
+
maxZoom: {
|
|
43
|
+
type: Number
|
|
44
|
+
},
|
|
45
|
+
highResolution: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
default: true
|
|
48
|
+
},
|
|
49
|
+
mapClick: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: true
|
|
52
|
+
},
|
|
53
|
+
mapType: {
|
|
54
|
+
type: String
|
|
55
|
+
},
|
|
56
|
+
dragging: {
|
|
57
|
+
type: Boolean,
|
|
58
|
+
default: true
|
|
59
|
+
},
|
|
60
|
+
scrollWheelZoom: {
|
|
61
|
+
type: Boolean,
|
|
62
|
+
default: false
|
|
63
|
+
},
|
|
64
|
+
doubleClickZoom: {
|
|
65
|
+
type: Boolean,
|
|
66
|
+
default: true
|
|
67
|
+
},
|
|
68
|
+
keyboard: {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
default: true
|
|
71
|
+
},
|
|
72
|
+
inertialDragging: {
|
|
73
|
+
type: Boolean,
|
|
74
|
+
default: true
|
|
75
|
+
},
|
|
76
|
+
continuousZoom: {
|
|
77
|
+
type: Boolean,
|
|
78
|
+
default: true
|
|
79
|
+
},
|
|
80
|
+
pinchToZoom: {
|
|
81
|
+
type: Boolean,
|
|
82
|
+
default: true
|
|
83
|
+
},
|
|
84
|
+
autoResize: {
|
|
85
|
+
type: Boolean,
|
|
86
|
+
default: true
|
|
87
|
+
},
|
|
88
|
+
theme: {
|
|
89
|
+
type: Array
|
|
90
|
+
},
|
|
91
|
+
mapStyle: {
|
|
92
|
+
type: Object
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
watch: {
|
|
96
|
+
center (val, oldVal) {
|
|
97
|
+
const {map, zoom} = this
|
|
98
|
+
if (checkType(val) === 'String' && val !== oldVal) {
|
|
99
|
+
map.centerAndZoom(val, zoom)
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
'center.lng' (val, oldVal) {
|
|
103
|
+
const {BMap, map, zoom, center} = this
|
|
104
|
+
if (val !== oldVal && val >= -180 && val <= 180) {
|
|
105
|
+
map.centerAndZoom(new BMap.Point(val, center.lat), zoom)
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
'center.lat' (val, oldVal) {
|
|
109
|
+
const {BMap, map, zoom, center} = this
|
|
110
|
+
if (val !== oldVal && val >= -74 && val <= 74) {
|
|
111
|
+
map.centerAndZoom(new BMap.Point(center.lng, val), zoom)
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
zoom (val, oldVal) {
|
|
115
|
+
const {map} = this
|
|
116
|
+
if (val !== oldVal && val >= 3 && val <= 19) {
|
|
117
|
+
map.setZoom(val)
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
minZoom (val) {
|
|
121
|
+
const {map} = this
|
|
122
|
+
map.setMinZoom(val)
|
|
123
|
+
},
|
|
124
|
+
maxZoom (val) {
|
|
125
|
+
const {map} = this
|
|
126
|
+
map.setMaxZoom(val)
|
|
127
|
+
},
|
|
128
|
+
highResolution () {
|
|
129
|
+
this.reset()
|
|
130
|
+
},
|
|
131
|
+
mapClick () {
|
|
132
|
+
this.reset()
|
|
133
|
+
},
|
|
134
|
+
mapType (val) {
|
|
135
|
+
const {map} = this
|
|
136
|
+
map.setMapType(global[val])
|
|
137
|
+
},
|
|
138
|
+
dragging (val) {
|
|
139
|
+
const {map} = this
|
|
140
|
+
val ? map.enableDragging() : map.disableDragging()
|
|
141
|
+
},
|
|
142
|
+
scrollWheelZoom (val) {
|
|
143
|
+
const {map} = this
|
|
144
|
+
val ? map.enableScrollWheelZoom() : map.disableScrollWheelZoom()
|
|
145
|
+
},
|
|
146
|
+
doubleClickZoom (val) {
|
|
147
|
+
const {map} = this
|
|
148
|
+
val ? map.enableDoubleClickZoom() : map.disableDoubleClickZoom()
|
|
149
|
+
},
|
|
150
|
+
keyboard (val) {
|
|
151
|
+
const {map} = this
|
|
152
|
+
val ? map.enableKeyboard() : map.disableKeyboard()
|
|
153
|
+
},
|
|
154
|
+
inertialDragging (val) {
|
|
155
|
+
const {map} = this
|
|
156
|
+
val ? map.enableInertialDragging() : map.disableInertialDragging()
|
|
157
|
+
},
|
|
158
|
+
continuousZoom (val) {
|
|
159
|
+
const {map} = this
|
|
160
|
+
val ? map.enableContinuousZoom() : map.disableContinuousZoom()
|
|
161
|
+
},
|
|
162
|
+
pinchToZoom (val) {
|
|
163
|
+
const {map} = this
|
|
164
|
+
val ? map.enablePinchToZoom() : map.disablePinchToZoom()
|
|
165
|
+
},
|
|
166
|
+
autoResize (val) {
|
|
167
|
+
const {map} = this
|
|
168
|
+
val ? map.enableAutoResize() : map.disableAutoResize()
|
|
169
|
+
},
|
|
170
|
+
theme (val) {
|
|
171
|
+
const {map} = this
|
|
172
|
+
map.setMapStyle({styleJson: val})
|
|
173
|
+
},
|
|
174
|
+
'mapStyle.features': {
|
|
175
|
+
handler (val, oldVal) {
|
|
176
|
+
const {map, mapStyle} = this
|
|
177
|
+
const {style, styleJson} = mapStyle
|
|
178
|
+
map.setMapStyle({
|
|
179
|
+
styleJson,
|
|
180
|
+
features: val,
|
|
181
|
+
style
|
|
182
|
+
})
|
|
183
|
+
},
|
|
184
|
+
deep: true
|
|
185
|
+
},
|
|
186
|
+
'mapStyle.style' (val, oldVal) {
|
|
187
|
+
const {map, mapStyle} = this
|
|
188
|
+
const {features, styleJson} = mapStyle
|
|
189
|
+
map.setMapStyle({
|
|
190
|
+
styleJson,
|
|
191
|
+
features,
|
|
192
|
+
style: val
|
|
193
|
+
})
|
|
194
|
+
},
|
|
195
|
+
'mapStyle.styleJson': {
|
|
196
|
+
handler (val, oldVal) {
|
|
197
|
+
const {map, mapStyle} = this
|
|
198
|
+
const {features, style} = mapStyle
|
|
199
|
+
map.setMapStyle({
|
|
200
|
+
styleJson: val,
|
|
201
|
+
features,
|
|
202
|
+
style
|
|
203
|
+
})
|
|
204
|
+
},
|
|
205
|
+
deep: true
|
|
206
|
+
},
|
|
207
|
+
mapStyle (val) {
|
|
208
|
+
const {map, theme} = this
|
|
209
|
+
!theme && map.setMapStyle(val)
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
methods: {
|
|
213
|
+
setMapOptions () {
|
|
214
|
+
const {map, minZoom, maxZoom, mapType, dragging, scrollWheelZoom, doubleClickZoom, keyboard, inertialDragging, continuousZoom, pinchToZoom, autoResize} = this
|
|
215
|
+
minZoom && map.setMinZoom(minZoom)
|
|
216
|
+
maxZoom && map.setMaxZoom(maxZoom)
|
|
217
|
+
mapType && map.setMapType(global[mapType])
|
|
218
|
+
dragging ? map.enableDragging() : map.disableDragging()
|
|
219
|
+
scrollWheelZoom ? map.enableScrollWheelZoom() : map.disableScrollWheelZoom()
|
|
220
|
+
doubleClickZoom ? map.enableDoubleClickZoom() : map.disableDoubleClickZoom()
|
|
221
|
+
keyboard ? map.enableKeyboard() : map.disableKeyboard()
|
|
222
|
+
inertialDragging ? map.enableInertialDragging() : map.disableInertialDragging()
|
|
223
|
+
continuousZoom ? map.enableContinuousZoom() : map.disableContinuousZoom()
|
|
224
|
+
pinchToZoom ? map.enablePinchToZoom() : map.disablePinchToZoom()
|
|
225
|
+
autoResize ? map.enableAutoResize() : map.disableAutoResize()
|
|
226
|
+
},
|
|
227
|
+
init (BMap) {
|
|
228
|
+
if (this.map) {
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
let $el = this.$refs.view
|
|
232
|
+
for (let $node of this.$slots.default || []) {
|
|
233
|
+
if ($node.componentOptions && $node.componentOptions.tag === 'bm-view') {
|
|
234
|
+
this.hasBmView = true
|
|
235
|
+
$el = $node.elm
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const map = new BMap.Map($el, {enableHighResolution: this.highResolution, enableMapClick: this.mapClick})
|
|
239
|
+
this.map = map
|
|
240
|
+
const {setMapOptions, zoom, getCenterPoint, theme, mapStyle} = this
|
|
241
|
+
theme ? map.setMapStyle({styleJson: theme}) : map.setMapStyle(mapStyle)
|
|
242
|
+
setMapOptions()
|
|
243
|
+
bindEvents.call(this, map)
|
|
244
|
+
// 此处强行初始化一次地图 回避一个由于错误的 center 字符串导致初始化失败抛出的错误
|
|
245
|
+
map.reset()
|
|
246
|
+
map.centerAndZoom(getCenterPoint(), zoom)
|
|
247
|
+
this.$emit('ready', {BMap, map})
|
|
248
|
+
// Debug
|
|
249
|
+
// global.map = map
|
|
250
|
+
// global.mapComponent = this
|
|
251
|
+
},
|
|
252
|
+
getCenterPoint () {
|
|
253
|
+
const {center, BMap} = this
|
|
254
|
+
switch (checkType(center)) {
|
|
255
|
+
case 'String': return center
|
|
256
|
+
case 'Object': return new BMap.Point(center.lng, center.lat)
|
|
257
|
+
default: return new BMap.Point()
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
initMap (BMap) {
|
|
261
|
+
this.BMap = BMap
|
|
262
|
+
this.init(BMap)
|
|
263
|
+
},
|
|
264
|
+
getMapScript () {
|
|
265
|
+
if (!global.BMap) {
|
|
266
|
+
const ak = this.ak || this._BMap().ak
|
|
267
|
+
const apiV = this.apiV || this._BMap().apiV
|
|
268
|
+
global.BMap = {}
|
|
269
|
+
global.BMap._preloader = new Promise((resolve, reject) => {
|
|
270
|
+
global._initBaiduMap = function () {
|
|
271
|
+
resolve(global.BMap)
|
|
272
|
+
global.document.body.removeChild($script)
|
|
273
|
+
global.BMap._preloader = null
|
|
274
|
+
global._initBaiduMap = null
|
|
275
|
+
}
|
|
276
|
+
const $script = document.createElement('script')
|
|
277
|
+
global.document.body.appendChild($script)
|
|
278
|
+
$script.src = `${this.apiSrc}?v=${apiV}&ak=${ak}&callback=_initBaiduMap`
|
|
279
|
+
})
|
|
280
|
+
return global.BMap._preloader
|
|
281
|
+
} else if (!global.BMap._preloader) {
|
|
282
|
+
return Promise.resolve(global.BMap)
|
|
283
|
+
} else {
|
|
284
|
+
return global.BMap._preloader
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
reset () {
|
|
288
|
+
const {getMapScript, initMap} = this
|
|
289
|
+
getMapScript()
|
|
290
|
+
.then(initMap)
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
mounted () {
|
|
294
|
+
this.reset()
|
|
295
|
+
},
|
|
296
|
+
data () {
|
|
297
|
+
return {
|
|
298
|
+
hasBmView: false
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
</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>
|