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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-gallery",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "vue-library-ui组件库",
5
5
  "main": "dist/index.umd.js",
6
6
  "files": [
@@ -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
- // Vue 插件中封装高德地图的初始化和常用方法
5
- function AmapPlugin(Vue, options) {
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
- window.forceWebGL = true
9
- window._AMapSecurityConfig = {
10
- securityJsCode: options.securityJsCode
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
- /** 加载地图sdk */
14
- const AMap = AMapLoader.load({
15
- key: options.key, // 高德地图的API Key
16
- version: '2.0', // 指定API版本
17
- plugins: ['AMap.Geocoder', 'AMap.PlaceSearch', 'AMap.ControlBar'] // 需要使用的插件
18
- })
34
+ /** 抛出地图常用方法 */
35
+ Vue.prototype.$amapMethods = {
36
+ getMapAddress,
37
+ setMapDriving,
38
+ drawMapAnimation
39
+ }
19
40
 
20
- if (!AMap) {
21
- throw new Error('高德地图脚本还未加载,请确保在使用此插件前已经加载高德地图SDK。')
22
- }
41
+ } ).catch( error => { throw new Error('高德地图脚本还未加载,请确保在使用此插件前已经加载高德地图SDK。') } )
42
+
43
+ // 其他可能需要封装的高德地图常用方法...
23
44
 
24
- // 初始化高德地图
25
- Vue.prototype.$initAMap = function(el, callback) {
26
- this.$nextTick(() => {
27
- const map = new AMap.Map(el, {
28
- zoom: 11, // 初始化时地图的缩放级别
29
- ...options.config // 其他高德地图初始化参数
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
- geocoder.getAddress(new Array(longitude, latitude), (status, result) => {
54
- if (status === 'complete' && result.info === 'OK') {
55
- const { formattedAddress, pois } = result.regeocode
56
- const { district, township } = result.regeocode.addressComponent
57
- let address
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
- const division =
60
- township && formattedAddress.includes(township)
61
- ? formattedAddress.indexOf(township) + township.length
62
- : formattedAddress.indexOf(district) + district.length
60
+ const division =
61
+ township && formattedAddress.includes(township)
62
+ ? formattedAddress.indexOf(township) + township.length
63
+ : formattedAddress.indexOf(district) + district.length
63
64
 
64
- address = formattedAddress.slice(0, division) + pois[0]?.address
65
+ address = formattedAddress.slice(0, division) + pois[0]?.address
65
66
 
66
- callback && callback({
67
- address,
68
- addressInfo: result.regeocode.addressComponent
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
- function drawMapAnimation(AMapInit, options, pathOptions, callback) {
94
- AMapInit.plugin('AMap.MoveAnimation', () => {
95
- let animationMarker = new AMap.Marker({
96
- map: AMapInit,
97
- icon: options.icon,
98
- position: options.paths[0],
99
- ...options
100
- })
101
- let passedPolyline = new AMap.Polyline({
102
- map: AMapInit,
103
- ...pathOptions
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
- animationMarker.on('moving', e => {
107
- passedPolyline.setPath( e.passedPath )
108
- AMapInit.setCenter( e.target.getPosition(), true )
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
- animationMarker.moveAlong(paths, {
112
- // circlable 是否循环
113
- // 每段间隔时间
114
- // aniInterval: 5,
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
- // 解析DrivingRoute对象,构造成AMap.Polyline的path参数需要的格式
125
- function parseRouteToPath(route) {
126
- let path = []
127
- let ApproachPoint = []
128
- let pointI = 0
129
- for (let i = 0, l = route.steps.length; i < l; i++) {
130
- let step = route.steps[i]
131
- for (let j = 0, n = step.path.length; j < n; j++) {
132
- path.push(step.path[j])
133
- if( step.assistant_action == "到达途经地" && (j == n - 1) ) ApproachPoint.push( pointI )
134
- pointI++
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
- // 为了能够在 Vue 中全局使用插件,可以添加一个 install 方法
143
- AmapPlugin.install = function(Vue, options) {
144
- Vue.mixin({
145
- created() {
146
- if (this.$options.amap) {
147
- this.$initAMap(this.$options.amap.el, this.$options.amap.callback)
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
- Vue.prototype.$amap = AmapPlugin
153
- }
154
-
155
- export default AmapPlugin
140
+
141
+ }
142
+ }