web-component-gallery 0.1.13 → 0.1.15
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/package.json +1 -1
- package/plugins/method/AMap.js +122 -135
- package/dist/avatar.umd.js +0 -5375
- package/dist/button.umd.js +0 -5927
- package/dist/css/index.css +0 -1
- package/dist/form.umd.js +0 -9992
- package/dist/index.umd.js +0 -11618
- package/dist/svgIcon.umd.js +0 -957
- package/dist/table.umd.js +0 -6383
- package/dist/tree.umd.js +0 -5272
package/package.json
CHANGED
package/plugins/method/AMap.js
CHANGED
|
@@ -1,155 +1,142 @@
|
|
|
1
1
|
// amap-plugin.js
|
|
2
2
|
import AMapLoader from '@amap/amap-jsapi-loader'
|
|
3
|
+
|
|
4
|
+
// 在 Vue 插件中封装高德地图的初始化和常用方法
|
|
5
|
+
export default {
|
|
6
|
+
install(Vue, options) {
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
/** 设置高德地图密钥 */
|
|
9
|
+
window.forceWebGL = true
|
|
10
|
+
window._AMapSecurityConfig = {
|
|
11
|
+
securityJsCode: options.securityJsCode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** 加载地图sdk */
|
|
15
|
+
AMapLoader.load({
|
|
16
|
+
key: options.key, // 高德地图的API Key
|
|
17
|
+
version: '2.0', // 指定API版本
|
|
18
|
+
plugins: ['AMap.Geocoder', 'AMap.PlaceSearch', 'AMap.ControlBar'] // 需要使用的插件
|
|
19
|
+
}).then( AMap => {
|
|
20
|
+
|
|
21
|
+
Vue.prototype.$amap = AMap
|
|
6
22
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
// 初始化高德地图
|
|
24
|
+
Vue.prototype.$initAMap = function(el, callback) {
|
|
25
|
+
this.$nextTick(() => {
|
|
26
|
+
const map = new AMap.Map(el, {
|
|
27
|
+
zoom: 11, // 初始化时地图的缩放级别
|
|
28
|
+
...options.config // 其他高德地图初始化参数
|
|
29
|
+
})
|
|
30
|
+
callback && callback(map)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
12
33
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
34
|
+
/** 抛出地图常用方法 */
|
|
35
|
+
Vue.prototype.$amapMethods = {
|
|
36
|
+
getMapAddress,
|
|
37
|
+
setMapDriving,
|
|
38
|
+
drawMapAnimation
|
|
39
|
+
}
|
|
19
40
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
41
|
+
} ).catch( error => { throw new Error('高德地图脚本还未加载,请确保在使用此插件前已经加载高德地图SDK。') } )
|
|
42
|
+
|
|
43
|
+
// 其他可能需要封装的高德地图常用方法...
|
|
23
44
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
/** 后续考虑加入一些map方法 */
|
|
46
|
+
/** 地图逆地理编码 */
|
|
47
|
+
function getMapAddress({longitude, latitude}, callback) {
|
|
48
|
+
const geocoder = new AMap.Geocoder({
|
|
49
|
+
city: '全国',
|
|
50
|
+
// 获取道路poi等详细信息
|
|
51
|
+
extensions: 'all'
|
|
30
52
|
})
|
|
31
|
-
callback && callback(map)
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** 抛出地图常用方法 */
|
|
36
|
-
Vue.prototype.$amapMethods = {
|
|
37
|
-
getMapAddress,
|
|
38
|
-
setMapDriving,
|
|
39
|
-
drawMapAnimation
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 其他可能需要封装的高德地图常用方法...
|
|
43
|
-
|
|
44
|
-
/** 后续考虑加入一些map方法 */
|
|
45
|
-
/** 地图逆地理编码 */
|
|
46
|
-
function getMapAddress({longitude, latitude}, callback) {
|
|
47
|
-
const geocoder = new AMap.Geocoder({
|
|
48
|
-
city: '全国',
|
|
49
|
-
// 获取道路poi等详细信息
|
|
50
|
-
extensions: 'all'
|
|
51
|
-
})
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
geocoder.getAddress(new Array(longitude, latitude), (status, result) => {
|
|
55
|
+
if (status === 'complete' && result.info === 'OK') {
|
|
56
|
+
const { formattedAddress, pois } = result.regeocode
|
|
57
|
+
const { district, township } = result.regeocode.addressComponent
|
|
58
|
+
let address
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const division =
|
|
61
|
+
township && formattedAddress.includes(township)
|
|
62
|
+
? formattedAddress.indexOf(township) + township.length
|
|
63
|
+
: formattedAddress.indexOf(district) + district.length
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
address = formattedAddress.slice(0, division) + pois[0]?.address
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/** 道路规划 */
|
|
75
|
-
function setMapDriving(AMapInit, paths, callback) {
|
|
76
|
-
AMapInit.plugin("AMap.Driving", () => {
|
|
77
|
-
let planRoutes = new AMap.Driving({ map: AMapInit })
|
|
78
|
-
planRoutes.search(
|
|
79
|
-
setLngLat( paths[ 0 ] ),
|
|
80
|
-
setLngLat( paths[ paths.length - 1 ] ),
|
|
81
|
-
{ waypoints: paths.slice( 1, paths.length - 1 ).map( path => setLngLat( path ) ) },
|
|
82
|
-
function (status, result) {
|
|
83
|
-
if(status == 'complete') return
|
|
84
|
-
callback && callback( parseRouteToPath( e.routes[0] ), roadDriving )
|
|
85
|
-
//status:complete 表示查询成功,no_data 为查询无结果,error 代表查询错误
|
|
86
|
-
//查询成功时,result 即为对应的驾车导航信息
|
|
87
|
-
}
|
|
88
|
-
)
|
|
89
|
-
})
|
|
90
|
-
}
|
|
67
|
+
callback && callback({
|
|
68
|
+
address,
|
|
69
|
+
addressInfo: result.regeocode.addressComponent
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}
|
|
91
74
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
75
|
+
/** 道路规划 */
|
|
76
|
+
function setMapDriving(AMapInit, paths, callback) {
|
|
77
|
+
AMapInit.plugin("AMap.Driving", () => {
|
|
78
|
+
let planRoutes = new AMap.Driving({ map: AMapInit })
|
|
79
|
+
planRoutes.search(
|
|
80
|
+
setLngLat( paths[ 0 ] ),
|
|
81
|
+
setLngLat( paths[ paths.length - 1 ] ),
|
|
82
|
+
{ waypoints: paths.slice( 1, paths.length - 1 ).map( path => setLngLat( path ) ) },
|
|
83
|
+
function (status, result) {
|
|
84
|
+
if(status == 'complete') return
|
|
85
|
+
callback && callback( parseRouteToPath( e.routes[0] ), roadDriving )
|
|
86
|
+
//status:complete 表示查询成功,no_data 为查询无结果,error 代表查询错误
|
|
87
|
+
//查询成功时,result 即为对应的驾车导航信息
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
105
92
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
/** 轨迹动画 */
|
|
94
|
+
function drawMapAnimation(AMapInit, options, pathOptions, callback) {
|
|
95
|
+
AMapInit.plugin('AMap.MoveAnimation', () => {
|
|
96
|
+
let animationMarker = new AMap.Marker({
|
|
97
|
+
map: AMapInit,
|
|
98
|
+
icon: options.icon,
|
|
99
|
+
position: options.paths[0],
|
|
100
|
+
...options
|
|
101
|
+
})
|
|
102
|
+
let passedPolyline = new AMap.Polyline({
|
|
103
|
+
map: AMapInit,
|
|
104
|
+
...pathOptions
|
|
105
|
+
})
|
|
110
106
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// 每一段的时长
|
|
116
|
-
duration: 500, // 可根据实际采集时间间隔设置
|
|
117
|
-
// JSAPI2.0 是否延道路自动设置角度在 moveAlong 里设置
|
|
118
|
-
autoRotation: true
|
|
119
|
-
})
|
|
120
|
-
callback && callback( animationMarker, passedPolyline )
|
|
121
|
-
})
|
|
122
|
-
}
|
|
107
|
+
animationMarker.on('moving', e => {
|
|
108
|
+
passedPolyline.setPath( e.passedPath )
|
|
109
|
+
AMapInit.setCenter( e.target.getPosition(), true )
|
|
110
|
+
})
|
|
123
111
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
112
|
+
animationMarker.moveAlong(paths, {
|
|
113
|
+
// circlable 是否循环
|
|
114
|
+
// 每段间隔时间
|
|
115
|
+
// aniInterval: 5,
|
|
116
|
+
// 每一段的时长
|
|
117
|
+
duration: 500, // 可根据实际采集时间间隔设置
|
|
118
|
+
// JSAPI2.0 是否延道路自动设置角度在 moveAlong 里设置
|
|
119
|
+
autoRotation: true
|
|
120
|
+
})
|
|
121
|
+
callback && callback( animationMarker, passedPolyline )
|
|
122
|
+
})
|
|
136
123
|
}
|
|
137
|
-
return { path, ApproachPoint }
|
|
138
|
-
}
|
|
139
124
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
125
|
+
// 解析DrivingRoute对象,构造成AMap.Polyline的path参数需要的格式
|
|
126
|
+
function parseRouteToPath(route) {
|
|
127
|
+
let path = []
|
|
128
|
+
let ApproachPoint = []
|
|
129
|
+
let pointI = 0
|
|
130
|
+
for (let i = 0, l = route.steps.length; i < l; i++) {
|
|
131
|
+
let step = route.steps[i]
|
|
132
|
+
for (let j = 0, n = step.path.length; j < n; j++) {
|
|
133
|
+
path.push(step.path[j])
|
|
134
|
+
if( step.assistant_action == "到达途经地" && (j == n - 1) ) ApproachPoint.push( pointI )
|
|
135
|
+
pointI++
|
|
136
|
+
}
|
|
148
137
|
}
|
|
138
|
+
return { path, ApproachPoint }
|
|
149
139
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export default AmapPlugin
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
}
|