xt-element-ui 1.3.3 → 1.3.4
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/CHANGELOG.md +72 -72
- package/LICENSE +21 -21
- package/README.md +240 -240
- package/docs/README.md +100 -100
- package/docs/components/base/xt-button.md +114 -114
- package/docs/components/base/xt-card-item.md +104 -104
- package/docs/components/base/xt-card.md +108 -108
- package/docs/components/base/xt-config-provider.md +199 -199
- package/docs/components/base/xt-flex-box.md +115 -115
- package/docs/components/base/xt-grid-box.md +302 -302
- package/docs/components/base/xt-input.md +150 -150
- package/docs/components/base/xt-map-provider.md +23 -23
- package/docs/components/base/xt-map.md +331 -331
- package/docs/components/base/xt-step-price.md +165 -165
- package/docs/components/base/xt-text.md +212 -212
- package/docs/components/base/xt-time.md +165 -165
- package/docs/components/extend/ex-bar.md +67 -67
- package/docs/components/extend/ex-button.md +62 -62
- package/docs/components/extend/ex-card.md +86 -86
- package/docs/components/extend/ex-chart.md +463 -463
- package/docs/components/extend/ex-icon.md +189 -189
- package/docs/components/extend/ex-line.md +70 -70
- package/docs/components/extend/ex-multi.md +155 -155
- package/docs/components/extend/ex-pie.md +69 -69
- package/docs/components/extend/ex-select-tree.md +210 -210
- package/docs/components/extend/ex-table.md +590 -590
- package/docs/components/extend/ex-upload.md +134 -134
- package/docs/components/utils/size.md +147 -147
- package/docs/components/utils/theme.md +182 -182
- package/lib/index.common.js +4112 -4122
- package/lib/index.umd.js +4072 -4081
- package/lib/index.umd.min.js +3 -3
- package/package.json +80 -81
- package/src/components/ex-button/index.js +7 -7
- package/src/components/ex-button/index.vue +66 -66
- package/src/components/ex-button/style/index.scss +67 -67
- package/src/components/ex-card/index.js +7 -7
- package/src/components/ex-card/index.vue +68 -68
- package/src/components/ex-card/style/index.scss +73 -73
- package/src/components/ex-chart/index.js +7 -7
- package/src/components/ex-chart/index.vue +136 -136
- package/src/components/ex-date-picker/index.js +7 -7
- package/src/components/ex-icon/index.js +7 -7
- package/src/components/ex-icon/index.vue +168 -168
- package/src/components/ex-icon/style/index.scss +7 -7
- package/src/components/ex-page/index.js +7 -7
- package/src/components/ex-select-tree/index.js +7 -7
- package/src/components/ex-table/ExTableCell.vue +22 -22
- package/src/components/ex-table/index.js +7 -7
- package/src/components/ex-table/virtualScrollData.js +35 -35
- package/src/components/ex-upload/index.js +7 -7
- package/src/components/index.scss +39 -39
- package/src/components/xt-button/index.js +7 -7
- package/src/components/xt-button/index.vue +97 -97
- package/src/components/xt-card/index.js +7 -7
- package/src/components/xt-card/style/index.scss +48 -48
- package/src/components/xt-card-item/index.js +7 -7
- package/src/components/xt-card-item/style/index copy.scss +71 -71
- package/src/components/xt-card-item/style/index.scss +82 -82
- package/src/components/xt-config-provider/index.js +7 -7
- package/src/components/xt-config-provider/index.vue +362 -362
- package/src/components/xt-config-provider/style/index.scss +11 -11
- package/src/components/xt-flex-box/index.js +7 -7
- package/src/components/xt-flex-box/style/index.scss +81 -81
- package/src/components/xt-grid-box/index.js +7 -7
- package/src/components/xt-grid-box/style/index.scss +92 -92
- package/src/components/xt-grid-item/index.js +7 -7
- package/src/components/xt-grid-item/index.vue +106 -106
- package/src/components/xt-input/index.js +7 -7
- package/src/components/xt-input/index.vue +66 -66
- package/src/components/xt-input/style/index.scss +84 -84
- package/src/components/xt-map/adapters/amap.js +235 -235
- package/src/components/xt-map/adapters/baidu.js +254 -254
- package/src/components/xt-map/adapters/base.js +267 -267
- package/src/components/xt-map/adapters/index.js +29 -29
- package/src/components/xt-map/adapters/tianditu.js +242 -242
- package/src/components/xt-map/config/xt-map-config.js +197 -197
- package/src/components/xt-map/index.js +8 -8
- package/src/components/xt-map/index.vue +351 -351
- package/src/components/xt-map/loaders/script-loader.js +114 -114
- package/src/components/xt-map/provider.vue +200 -200
- package/src/components/xt-map/style/index.scss +77 -77
- package/src/components/xt-map-provider/index.js +8 -8
- package/src/components/xt-step-price/index.js +10 -10
- package/src/components/xt-step-price/index.vue +272 -272
- package/src/components/xt-step-price/style/index.scss +123 -123
- package/src/components/xt-step-price-item/index.js +7 -7
- package/src/components/xt-step-price-item/index.vue +187 -187
- package/src/components/xt-text/index.js +7 -7
- package/src/components/xt-text/index.vue +1 -1
- package/src/components/xt-text/style/index.scss +92 -92
- package/src/components/xt-time/index.js +7 -7
- package/src/components/xt-time/index.vue +313 -313
- package/src/components/xt-time/style/index.scss +23 -23
- package/src/config/element-registry.js +135 -135
- package/src/index.js +162 -178
- package/src/styles/css-variables.scss +257 -257
- package/src/styles/theme/background.scss +5 -5
- package/src/styles/theme/border-radius.scss +3 -3
- package/src/styles/theme/borders.scss +3 -3
- package/src/styles/theme/colors.scss +101 -101
- package/src/styles/theme/component-variables.scss +69 -69
- package/src/styles/theme/dark-variables.scss +28 -28
- package/src/styles/theme/font.scss +12 -12
- package/src/styles/theme/index.scss +11 -11
- package/src/styles/theme/shadows.scss +2 -2
- package/src/styles/theme/spacing.scss +4 -4
- package/src/styles/theme/transitions.scss +2 -2
- package/src/styles/theme/typography.scss +4 -4
- package/src/styles/variables-export.scss +85 -85
- package/src/utils/index.js +191 -202
|
@@ -1,235 +1,235 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 高德地图适配器 (AMap)
|
|
3
|
-
* 以高德为基准,所有 xt-map 枚举直接映射
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { MapAdapterBase } from './base'
|
|
7
|
-
import { hasGlobal } from '../loaders/script-loader'
|
|
8
|
-
|
|
9
|
-
const A_MAP_MAP_TYPES = {
|
|
10
|
-
standard: 'amap', // 标准/矢量
|
|
11
|
-
satellite: 'satellite', // 卫星
|
|
12
|
-
hybrid: 'satellite', // 混合(卫星+路网,用卫星+路网图层组合实现)
|
|
13
|
-
traffic: 'traffic' // 实时路况(叠加在 standard 上)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// 高德地图样式 ID(主题映射)
|
|
17
|
-
const A_MAP_STYLES = {
|
|
18
|
-
light: 'amap://styles/normal',
|
|
19
|
-
dark: 'amap://styles/dark'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class AMapAdapter extends MapAdapterBase {
|
|
23
|
-
constructor(container, options = {}) {
|
|
24
|
-
super(container, options)
|
|
25
|
-
this._mapTypeMap = { ...A_MAP_MAP_TYPES }
|
|
26
|
-
this._trafficLayer = null // 路况图层引用
|
|
27
|
-
this._satelliteLayer = null // 卫星图层
|
|
28
|
-
this._roadnetLayer = null // 路网图层(用于 hybrid)
|
|
29
|
-
this._currentLayers = [] // 当前叠加图层
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getScriptUrl() {
|
|
33
|
-
if (this.apiUrl) return this.apiUrl
|
|
34
|
-
if (!this.apiKey) {
|
|
35
|
-
console.warn('[XtMap] 高德地图需要配置 apiKey')
|
|
36
|
-
return ''
|
|
37
|
-
}
|
|
38
|
-
// 高德 2.0 Web API
|
|
39
|
-
return `https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(this.apiKey)}&plugin=AMap.Scale,AMap.ToolBar`
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 脚本加载前设置高德 2.0 安全密钥
|
|
44
|
-
*/
|
|
45
|
-
beforeLoadScript() {
|
|
46
|
-
const securityJsCode = this.options.securityJsCode || (typeof window !== 'undefined' && window._AMapSecurityConfig && window._AMapSecurityConfig.securityJsCode) || ''
|
|
47
|
-
if (securityJsCode && typeof window !== 'undefined') {
|
|
48
|
-
window._AMapSecurityConfig = {
|
|
49
|
-
securityJsCode: securityJsCode
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
isSdkLoaded() {
|
|
55
|
-
return hasGlobal('AMap') && typeof window.AMap === 'function'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async createMap() {
|
|
59
|
-
const AMap = window.AMap
|
|
60
|
-
if (!AMap) throw new Error('[XtMap] 高德地图 SDK 未加载')
|
|
61
|
-
|
|
62
|
-
const mapOptions = {
|
|
63
|
-
center: this.center,
|
|
64
|
-
zoom: this.zoom,
|
|
65
|
-
mapStyle: A_MAP_STYLES[this.theme] || A_MAP_STYLES.light,
|
|
66
|
-
viewMode: '2D',
|
|
67
|
-
resizeEnable: true
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.mapInstance = new AMap.Map(this.container, mapOptions)
|
|
71
|
-
|
|
72
|
-
// 应用地图类型
|
|
73
|
-
this._applyMapType(this.mapType)
|
|
74
|
-
|
|
75
|
-
// 绑定事件(延迟到地图就绪后)
|
|
76
|
-
await new Promise((resolve) => {
|
|
77
|
-
this.mapInstance.on('complete', () => resolve())
|
|
78
|
-
// 兜底:1秒后强制 resolve
|
|
79
|
-
setTimeout(resolve, 1500)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
// 重新绑定已注册事件
|
|
83
|
-
for (const [eventName, handler] of this.eventHandlers.entries()) {
|
|
84
|
-
this._bindEvent(eventName, handler)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_applyMapType(type) {
|
|
89
|
-
if (!this.mapInstance) return
|
|
90
|
-
const AMap = window.AMap
|
|
91
|
-
if (!AMap) return
|
|
92
|
-
|
|
93
|
-
// 清除所有叠加图层
|
|
94
|
-
this._clearLayers()
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
// 设置底图样式
|
|
98
|
-
this.mapInstance.setMapStyle(A_MAP_STYLES[this.theme] || A_MAP_STYLES.light)
|
|
99
|
-
|
|
100
|
-
if (type === 'satellite') {
|
|
101
|
-
this._satelliteLayer = new AMap.TileLayer.Satellite()
|
|
102
|
-
this.mapInstance.add(this._satelliteLayer)
|
|
103
|
-
this._currentLayers.push(this._satelliteLayer)
|
|
104
|
-
} else if (type === 'hybrid') {
|
|
105
|
-
// 卫星 + 路网
|
|
106
|
-
this._satelliteLayer = new AMap.TileLayer.Satellite()
|
|
107
|
-
this._roadnetLayer = new AMap.TileLayer.RoadNet()
|
|
108
|
-
this.mapInstance.add([this._satelliteLayer, this._roadnetLayer])
|
|
109
|
-
this._currentLayers.push(this._satelliteLayer, this._roadnetLayer)
|
|
110
|
-
} else if (type === 'traffic') {
|
|
111
|
-
// 路况图层叠加在 standard 上
|
|
112
|
-
this._trafficLayer = new AMap.TileLayer.Traffic({
|
|
113
|
-
autoRefresh: true,
|
|
114
|
-
interval: 180
|
|
115
|
-
})
|
|
116
|
-
this.mapInstance.add(this._trafficLayer)
|
|
117
|
-
this._currentLayers.push(this._trafficLayer)
|
|
118
|
-
}
|
|
119
|
-
} catch (e) {
|
|
120
|
-
console.warn('[XtMap] 设置地图类型失败:', e)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
_clearLayers() {
|
|
125
|
-
if (!this.mapInstance) return
|
|
126
|
-
try {
|
|
127
|
-
if (this._currentLayers.length > 0) {
|
|
128
|
-
this.mapInstance.remove(this._currentLayers)
|
|
129
|
-
}
|
|
130
|
-
} catch (e) {
|
|
131
|
-
// 忽略
|
|
132
|
-
}
|
|
133
|
-
this._currentLayers = []
|
|
134
|
-
this._trafficLayer = null
|
|
135
|
-
this._satelliteLayer = null
|
|
136
|
-
this._roadnetLayer = null
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
_applyTheme(theme) {
|
|
140
|
-
if (!this.mapInstance) return
|
|
141
|
-
try {
|
|
142
|
-
this.mapInstance.setMapStyle(A_MAP_STYLES[theme] || A_MAP_STYLES.light)
|
|
143
|
-
// 主题变更可能影响图层显示,重新应用地图类型
|
|
144
|
-
this._applyMapType(this.mapType)
|
|
145
|
-
} catch (e) {
|
|
146
|
-
console.warn('[XtMap] 设置主题失败:', e)
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
_applyCenter(center) {
|
|
151
|
-
if (!this.mapInstance) return
|
|
152
|
-
try {
|
|
153
|
-
this.mapInstance.setCenter(center)
|
|
154
|
-
} catch (e) {
|
|
155
|
-
// 忽略
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
_applyZoom(zoom) {
|
|
160
|
-
if (!this.mapInstance) return
|
|
161
|
-
try {
|
|
162
|
-
this.mapInstance.setZoom(zoom)
|
|
163
|
-
} catch (e) {
|
|
164
|
-
// 忽略
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
getCenter() {
|
|
169
|
-
if (this.mapInstance && this.mapInstance.getCenter) {
|
|
170
|
-
const c = this.mapInstance.getCenter()
|
|
171
|
-
return [c.lng, c.lat]
|
|
172
|
-
}
|
|
173
|
-
return this.center
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
getZoom() {
|
|
177
|
-
if (this.mapInstance && this.mapInstance.getZoom) {
|
|
178
|
-
return this.mapInstance.getZoom()
|
|
179
|
-
}
|
|
180
|
-
return this.zoom
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
_bindEvent(eventName, handler) {
|
|
184
|
-
if (!this.mapInstance) return
|
|
185
|
-
try {
|
|
186
|
-
// 统一事件名映射
|
|
187
|
-
const eventMap = {
|
|
188
|
-
click: 'click',
|
|
189
|
-
moveend: 'moveend',
|
|
190
|
-
zoomend: 'zoomend',
|
|
191
|
-
zoomchange: 'zoomchange',
|
|
192
|
-
mapmove: 'mapmove',
|
|
193
|
-
complete: 'complete',
|
|
194
|
-
resize: 'resize'
|
|
195
|
-
}
|
|
196
|
-
const nativeEvent = eventMap[eventName] || eventName
|
|
197
|
-
this.mapInstance.on(nativeEvent, (e) => {
|
|
198
|
-
// 统一事件参数格式
|
|
199
|
-
const normalized = {
|
|
200
|
-
originalEvent: e,
|
|
201
|
-
lnglat: e && e.lnglat ? [e.lnglat.lng, e.lnglat.lat] : null
|
|
202
|
-
}
|
|
203
|
-
handler(normalized)
|
|
204
|
-
})
|
|
205
|
-
} catch (err) {
|
|
206
|
-
console.warn('[XtMap] 事件绑定失败:', eventName, err)
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
_unbindEvent(eventName, handler) {
|
|
211
|
-
if (!this.mapInstance) return
|
|
212
|
-
try {
|
|
213
|
-
this.mapInstance.off(eventName, handler)
|
|
214
|
-
} catch (e) {
|
|
215
|
-
// 忽略
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
_applyResize() {
|
|
220
|
-
if (this.mapInstance && this.mapInstance.resize) {
|
|
221
|
-
try {
|
|
222
|
-
this.mapInstance.resize()
|
|
223
|
-
} catch (e) {
|
|
224
|
-
// 忽略
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
destroy() {
|
|
230
|
-
this._clearLayers()
|
|
231
|
-
super.destroy()
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export default AMapAdapter
|
|
1
|
+
/**
|
|
2
|
+
* 高德地图适配器 (AMap)
|
|
3
|
+
* 以高德为基准,所有 xt-map 枚举直接映射
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { MapAdapterBase } from './base'
|
|
7
|
+
import { hasGlobal } from '../loaders/script-loader'
|
|
8
|
+
|
|
9
|
+
const A_MAP_MAP_TYPES = {
|
|
10
|
+
standard: 'amap', // 标准/矢量
|
|
11
|
+
satellite: 'satellite', // 卫星
|
|
12
|
+
hybrid: 'satellite', // 混合(卫星+路网,用卫星+路网图层组合实现)
|
|
13
|
+
traffic: 'traffic' // 实时路况(叠加在 standard 上)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 高德地图样式 ID(主题映射)
|
|
17
|
+
const A_MAP_STYLES = {
|
|
18
|
+
light: 'amap://styles/normal',
|
|
19
|
+
dark: 'amap://styles/dark'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class AMapAdapter extends MapAdapterBase {
|
|
23
|
+
constructor(container, options = {}) {
|
|
24
|
+
super(container, options)
|
|
25
|
+
this._mapTypeMap = { ...A_MAP_MAP_TYPES }
|
|
26
|
+
this._trafficLayer = null // 路况图层引用
|
|
27
|
+
this._satelliteLayer = null // 卫星图层
|
|
28
|
+
this._roadnetLayer = null // 路网图层(用于 hybrid)
|
|
29
|
+
this._currentLayers = [] // 当前叠加图层
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getScriptUrl() {
|
|
33
|
+
if (this.apiUrl) return this.apiUrl
|
|
34
|
+
if (!this.apiKey) {
|
|
35
|
+
console.warn('[XtMap] 高德地图需要配置 apiKey')
|
|
36
|
+
return ''
|
|
37
|
+
}
|
|
38
|
+
// 高德 2.0 Web API
|
|
39
|
+
return `https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(this.apiKey)}&plugin=AMap.Scale,AMap.ToolBar`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 脚本加载前设置高德 2.0 安全密钥
|
|
44
|
+
*/
|
|
45
|
+
beforeLoadScript() {
|
|
46
|
+
const securityJsCode = this.options.securityJsCode || (typeof window !== 'undefined' && window._AMapSecurityConfig && window._AMapSecurityConfig.securityJsCode) || ''
|
|
47
|
+
if (securityJsCode && typeof window !== 'undefined') {
|
|
48
|
+
window._AMapSecurityConfig = {
|
|
49
|
+
securityJsCode: securityJsCode
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
isSdkLoaded() {
|
|
55
|
+
return hasGlobal('AMap') && typeof window.AMap === 'function'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async createMap() {
|
|
59
|
+
const AMap = window.AMap
|
|
60
|
+
if (!AMap) throw new Error('[XtMap] 高德地图 SDK 未加载')
|
|
61
|
+
|
|
62
|
+
const mapOptions = {
|
|
63
|
+
center: this.center,
|
|
64
|
+
zoom: this.zoom,
|
|
65
|
+
mapStyle: A_MAP_STYLES[this.theme] || A_MAP_STYLES.light,
|
|
66
|
+
viewMode: '2D',
|
|
67
|
+
resizeEnable: true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.mapInstance = new AMap.Map(this.container, mapOptions)
|
|
71
|
+
|
|
72
|
+
// 应用地图类型
|
|
73
|
+
this._applyMapType(this.mapType)
|
|
74
|
+
|
|
75
|
+
// 绑定事件(延迟到地图就绪后)
|
|
76
|
+
await new Promise((resolve) => {
|
|
77
|
+
this.mapInstance.on('complete', () => resolve())
|
|
78
|
+
// 兜底:1秒后强制 resolve
|
|
79
|
+
setTimeout(resolve, 1500)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// 重新绑定已注册事件
|
|
83
|
+
for (const [eventName, handler] of this.eventHandlers.entries()) {
|
|
84
|
+
this._bindEvent(eventName, handler)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
_applyMapType(type) {
|
|
89
|
+
if (!this.mapInstance) return
|
|
90
|
+
const AMap = window.AMap
|
|
91
|
+
if (!AMap) return
|
|
92
|
+
|
|
93
|
+
// 清除所有叠加图层
|
|
94
|
+
this._clearLayers()
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
// 设置底图样式
|
|
98
|
+
this.mapInstance.setMapStyle(A_MAP_STYLES[this.theme] || A_MAP_STYLES.light)
|
|
99
|
+
|
|
100
|
+
if (type === 'satellite') {
|
|
101
|
+
this._satelliteLayer = new AMap.TileLayer.Satellite()
|
|
102
|
+
this.mapInstance.add(this._satelliteLayer)
|
|
103
|
+
this._currentLayers.push(this._satelliteLayer)
|
|
104
|
+
} else if (type === 'hybrid') {
|
|
105
|
+
// 卫星 + 路网
|
|
106
|
+
this._satelliteLayer = new AMap.TileLayer.Satellite()
|
|
107
|
+
this._roadnetLayer = new AMap.TileLayer.RoadNet()
|
|
108
|
+
this.mapInstance.add([this._satelliteLayer, this._roadnetLayer])
|
|
109
|
+
this._currentLayers.push(this._satelliteLayer, this._roadnetLayer)
|
|
110
|
+
} else if (type === 'traffic') {
|
|
111
|
+
// 路况图层叠加在 standard 上
|
|
112
|
+
this._trafficLayer = new AMap.TileLayer.Traffic({
|
|
113
|
+
autoRefresh: true,
|
|
114
|
+
interval: 180
|
|
115
|
+
})
|
|
116
|
+
this.mapInstance.add(this._trafficLayer)
|
|
117
|
+
this._currentLayers.push(this._trafficLayer)
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.warn('[XtMap] 设置地图类型失败:', e)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
_clearLayers() {
|
|
125
|
+
if (!this.mapInstance) return
|
|
126
|
+
try {
|
|
127
|
+
if (this._currentLayers.length > 0) {
|
|
128
|
+
this.mapInstance.remove(this._currentLayers)
|
|
129
|
+
}
|
|
130
|
+
} catch (e) {
|
|
131
|
+
// 忽略
|
|
132
|
+
}
|
|
133
|
+
this._currentLayers = []
|
|
134
|
+
this._trafficLayer = null
|
|
135
|
+
this._satelliteLayer = null
|
|
136
|
+
this._roadnetLayer = null
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_applyTheme(theme) {
|
|
140
|
+
if (!this.mapInstance) return
|
|
141
|
+
try {
|
|
142
|
+
this.mapInstance.setMapStyle(A_MAP_STYLES[theme] || A_MAP_STYLES.light)
|
|
143
|
+
// 主题变更可能影响图层显示,重新应用地图类型
|
|
144
|
+
this._applyMapType(this.mapType)
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.warn('[XtMap] 设置主题失败:', e)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
_applyCenter(center) {
|
|
151
|
+
if (!this.mapInstance) return
|
|
152
|
+
try {
|
|
153
|
+
this.mapInstance.setCenter(center)
|
|
154
|
+
} catch (e) {
|
|
155
|
+
// 忽略
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_applyZoom(zoom) {
|
|
160
|
+
if (!this.mapInstance) return
|
|
161
|
+
try {
|
|
162
|
+
this.mapInstance.setZoom(zoom)
|
|
163
|
+
} catch (e) {
|
|
164
|
+
// 忽略
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
getCenter() {
|
|
169
|
+
if (this.mapInstance && this.mapInstance.getCenter) {
|
|
170
|
+
const c = this.mapInstance.getCenter()
|
|
171
|
+
return [c.lng, c.lat]
|
|
172
|
+
}
|
|
173
|
+
return this.center
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
getZoom() {
|
|
177
|
+
if (this.mapInstance && this.mapInstance.getZoom) {
|
|
178
|
+
return this.mapInstance.getZoom()
|
|
179
|
+
}
|
|
180
|
+
return this.zoom
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
_bindEvent(eventName, handler) {
|
|
184
|
+
if (!this.mapInstance) return
|
|
185
|
+
try {
|
|
186
|
+
// 统一事件名映射
|
|
187
|
+
const eventMap = {
|
|
188
|
+
click: 'click',
|
|
189
|
+
moveend: 'moveend',
|
|
190
|
+
zoomend: 'zoomend',
|
|
191
|
+
zoomchange: 'zoomchange',
|
|
192
|
+
mapmove: 'mapmove',
|
|
193
|
+
complete: 'complete',
|
|
194
|
+
resize: 'resize'
|
|
195
|
+
}
|
|
196
|
+
const nativeEvent = eventMap[eventName] || eventName
|
|
197
|
+
this.mapInstance.on(nativeEvent, (e) => {
|
|
198
|
+
// 统一事件参数格式
|
|
199
|
+
const normalized = {
|
|
200
|
+
originalEvent: e,
|
|
201
|
+
lnglat: e && e.lnglat ? [e.lnglat.lng, e.lnglat.lat] : null
|
|
202
|
+
}
|
|
203
|
+
handler(normalized)
|
|
204
|
+
})
|
|
205
|
+
} catch (err) {
|
|
206
|
+
console.warn('[XtMap] 事件绑定失败:', eventName, err)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
_unbindEvent(eventName, handler) {
|
|
211
|
+
if (!this.mapInstance) return
|
|
212
|
+
try {
|
|
213
|
+
this.mapInstance.off(eventName, handler)
|
|
214
|
+
} catch (e) {
|
|
215
|
+
// 忽略
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
_applyResize() {
|
|
220
|
+
if (this.mapInstance && this.mapInstance.resize) {
|
|
221
|
+
try {
|
|
222
|
+
this.mapInstance.resize()
|
|
223
|
+
} catch (e) {
|
|
224
|
+
// 忽略
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
destroy() {
|
|
230
|
+
this._clearLayers()
|
|
231
|
+
super.destroy()
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export default AMapAdapter
|