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,254 +1,254 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 百度地图适配器 (BMap / Baidu)
|
|
3
|
-
* 百度地图 JS API 3.0 支持自定义样式
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { MapAdapterBase } from './base'
|
|
7
|
-
import { hasGlobal } from '../loaders/script-loader'
|
|
8
|
-
|
|
9
|
-
// 百度地图类型映射
|
|
10
|
-
const BAIDU_MAP_TYPES = {
|
|
11
|
-
standard: 'BMAP_NORMAL_MAP',
|
|
12
|
-
satellite: 'BMAP_SATELLITE_MAP',
|
|
13
|
-
hybrid: 'BMAP_HYBRID_MAP',
|
|
14
|
-
traffic: 'BMAP_NORMAL_MAP' // 路况通过图层叠加
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// 百度地图自定义样式 ID(主题)
|
|
18
|
-
// light: 官方 normal 样式
|
|
19
|
-
// dark: 午夜蓝 dark 样式
|
|
20
|
-
const BAIDU_STYLES = {
|
|
21
|
-
light: { style: 'normal' },
|
|
22
|
-
dark: { style: 'dark' }
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class BaiduAdapter extends MapAdapterBase {
|
|
26
|
-
constructor(container, options = {}) {
|
|
27
|
-
super(container, options)
|
|
28
|
-
this._mapTypeMap = { ...BAIDU_MAP_TYPES }
|
|
29
|
-
this._coordType = options.baiduCoordType || 'bd09ll'
|
|
30
|
-
this._trafficLayer = null
|
|
31
|
-
this._callbackName = null
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getScriptUrl() {
|
|
35
|
-
if (this.apiUrl) return this.apiUrl
|
|
36
|
-
if (!this.apiKey) {
|
|
37
|
-
console.warn('[XtMap] 百度地图需要配置 apiKey (ak)')
|
|
38
|
-
return ''
|
|
39
|
-
}
|
|
40
|
-
// 注意:_callbackName 在 beforeLoadScript 中已注册
|
|
41
|
-
return `https://api.map.baidu.com/api?v=3.0&ak=${encodeURIComponent(this.apiKey)}&callback=${this._callbackName}`
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 脚本加载前注册百度 SDK 回调函数
|
|
46
|
-
*/
|
|
47
|
-
beforeLoadScript() {
|
|
48
|
-
// 生成唯一 callback 名称,支持多实例
|
|
49
|
-
this._callbackName = `__xt_map_baidu_${Date.now()}_${Math.floor(Math.random() * 100000)}`
|
|
50
|
-
// 注册全局 callback(百度地图 SDK 加载完成后调用)
|
|
51
|
-
if (typeof window !== 'undefined') {
|
|
52
|
-
window[this._callbackName] = () => {
|
|
53
|
-
// 空实现,仅用于触发 Promise resolve
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
isSdkLoaded() {
|
|
59
|
-
return hasGlobal('BMap') && typeof window.BMap === 'function'
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async createMap() {
|
|
63
|
-
const BMap = window.BMap
|
|
64
|
-
if (!BMap) throw new Error('[XtMap] 百度地图 SDK 未加载')
|
|
65
|
-
|
|
66
|
-
const mapOptions = {
|
|
67
|
-
enableMapClick: false
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.mapInstance = new BMap.Map(this.container, mapOptions)
|
|
71
|
-
this.mapInstance.centerAndZoom(new BMap.Point(this.center[0], this.center[1]), this.zoom)
|
|
72
|
-
this.mapInstance.enableScrollWheelZoom(true)
|
|
73
|
-
|
|
74
|
-
// 应用地图类型
|
|
75
|
-
this._applyMapType(this.mapType)
|
|
76
|
-
|
|
77
|
-
// 应用主题
|
|
78
|
-
this._applyTheme(this.theme)
|
|
79
|
-
|
|
80
|
-
// 等待地图就绪
|
|
81
|
-
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
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 || !window.BMap) return
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
// 清除路况图层
|
|
93
|
-
if (this._trafficLayer) {
|
|
94
|
-
try {
|
|
95
|
-
this.mapInstance.removeTileLayer(this._trafficLayer)
|
|
96
|
-
} catch (e) {}
|
|
97
|
-
this._trafficLayer = null
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (type === 'satellite') {
|
|
101
|
-
this.mapInstance.setMapType(window.BMAP_SATELLITE_MAP || 1)
|
|
102
|
-
} else if (type === 'hybrid') {
|
|
103
|
-
this.mapInstance.setMapType(window.BMAP_HYBRID_MAP || 2)
|
|
104
|
-
} else if (type === 'traffic') {
|
|
105
|
-
this.mapInstance.setMapType(window.BMAP_NORMAL_MAP || 0)
|
|
106
|
-
// 叠加路况图层
|
|
107
|
-
try {
|
|
108
|
-
const BMap = window.BMap
|
|
109
|
-
this._trafficLayer = new BMap.TrafficLayer()
|
|
110
|
-
this.mapInstance.addTileLayer(this._trafficLayer)
|
|
111
|
-
} catch (e) {
|
|
112
|
-
console.warn('[XtMap] 百度地图加载路况图层失败:', e)
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
this.mapInstance.setMapType(window.BMAP_NORMAL_MAP || 0)
|
|
116
|
-
}
|
|
117
|
-
} catch (e) {
|
|
118
|
-
console.warn('[XtMap] 百度地图切换地图类型失败:', e)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
_applyTheme(theme) {
|
|
123
|
-
if (!this.mapInstance || !window.BMap) return
|
|
124
|
-
try {
|
|
125
|
-
// 百度 3.0 通过 setMapStyle 设置主题样式
|
|
126
|
-
const styleConfig = BAIDU_STYLES[theme] || BAIDU_STYLES.light
|
|
127
|
-
if (this.mapInstance.setMapStyleV2) {
|
|
128
|
-
// 新版 API
|
|
129
|
-
this.mapInstance.setMapStyleV2({ styleId: styleConfig.style === 'dark' ? 'midnight' : '' })
|
|
130
|
-
} else if (this.mapInstance.setMapStyle) {
|
|
131
|
-
// 旧版 API
|
|
132
|
-
const styleJson = theme === 'dark' ? this._getDarkStyleJson() : null
|
|
133
|
-
if (styleJson) {
|
|
134
|
-
this.mapInstance.setMapStyle({ styleJson: styleJson })
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch (e) {
|
|
138
|
-
console.warn('[XtMap] 百度地图设置主题失败:', e)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 简易百度地图 dark 样式 JSON 配置
|
|
144
|
-
*/
|
|
145
|
-
_getDarkStyleJson() {
|
|
146
|
-
return [
|
|
147
|
-
{ featureType: 'land', elementType: 'geometry', stylers: { color: '#1a1a1a' } },
|
|
148
|
-
{ featureType: 'water', elementType: 'geometry', stylers: { color: '#0a1a2a' } },
|
|
149
|
-
{ featureType: 'green', elementType: 'geometry', stylers: { color: '#0a2a1a' } },
|
|
150
|
-
{ featureType: 'building', elementType: 'geometry', stylers: { color: '#2a2a2a' } },
|
|
151
|
-
{ featureType: 'highway', elementType: 'geometry', stylers: { color: '#3a3a3a' } },
|
|
152
|
-
{ featureType: 'highway', elementType: 'geometry.stroke', stylers: { color: '#4a4a4a' } },
|
|
153
|
-
{ featureType: 'arterial', elementType: 'geometry', stylers: { color: '#333333' } },
|
|
154
|
-
{ featureType: 'arterial', elementType: 'geometry.stroke', stylers: { color: '#3d3d3d' } },
|
|
155
|
-
{ featureType: 'local', elementType: 'geometry', stylers: { color: '#2a2a2a' } },
|
|
156
|
-
{ featureType: 'railway', elementType: 'geometry', stylers: { color: '#3a3a3a' } },
|
|
157
|
-
{ featureType: 'subway', elementType: 'geometry', stylers: { color: '#3a3a3a' } },
|
|
158
|
-
{ featureType: 'boundary', elementType: 'geometry', stylers: { color: '#666666' } },
|
|
159
|
-
{ featureType: 'district', elementType: 'labels.text.fill', stylers: { color: '#888888' } },
|
|
160
|
-
{ featureType: 'poi', elementType: 'labels', stylers: { visibility: 'off' } }
|
|
161
|
-
]
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
_applyCenter(center) {
|
|
165
|
-
if (!this.mapInstance || !window.BMap) return
|
|
166
|
-
try {
|
|
167
|
-
this.mapInstance.centerAndZoom(new window.BMap.Point(center[0], center[1]), this.zoom)
|
|
168
|
-
} catch (e) {
|
|
169
|
-
// 忽略
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
_applyZoom(zoom) {
|
|
174
|
-
if (!this.mapInstance) return
|
|
175
|
-
try {
|
|
176
|
-
this.mapInstance.setZoom(zoom)
|
|
177
|
-
} catch (e) {
|
|
178
|
-
// 忽略
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
getCenter() {
|
|
183
|
-
if (this.mapInstance && this.mapInstance.getCenter) {
|
|
184
|
-
const c = this.mapInstance.getCenter()
|
|
185
|
-
if (c) return [c.lng, c.lat]
|
|
186
|
-
}
|
|
187
|
-
return this.center
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
getZoom() {
|
|
191
|
-
if (this.mapInstance && this.mapInstance.getZoom) {
|
|
192
|
-
return this.mapInstance.getZoom()
|
|
193
|
-
}
|
|
194
|
-
return this.zoom
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
_bindEvent(eventName, handler) {
|
|
198
|
-
if (!this.mapInstance) return
|
|
199
|
-
try {
|
|
200
|
-
const eventMap = {
|
|
201
|
-
click: 'click',
|
|
202
|
-
moveend: 'moveend',
|
|
203
|
-
zoomend: 'zoomend',
|
|
204
|
-
zoomchange: 'zoomend',
|
|
205
|
-
mapmove: 'movestart'
|
|
206
|
-
}
|
|
207
|
-
const nativeEvent = eventMap[eventName] || eventName
|
|
208
|
-
this.mapInstance.addEventListener(nativeEvent, (e) => {
|
|
209
|
-
const normalized = {
|
|
210
|
-
originalEvent: e,
|
|
211
|
-
lnglat: e && e.point ? [e.point.lng, e.point.lat] : null
|
|
212
|
-
}
|
|
213
|
-
handler(normalized)
|
|
214
|
-
})
|
|
215
|
-
} catch (err) {
|
|
216
|
-
console.warn('[XtMap] 百度地图事件绑定失败:', eventName, err)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
_unbindEvent(eventName, handler) {
|
|
221
|
-
if (!this.mapInstance) return
|
|
222
|
-
try {
|
|
223
|
-
this.mapInstance.removeEventListener(eventName, handler)
|
|
224
|
-
} catch (e) {
|
|
225
|
-
// 忽略
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
_applyResize() {
|
|
230
|
-
if (this.mapInstance && this.mapInstance.enableResize) {
|
|
231
|
-
try {
|
|
232
|
-
// 百度地图默认启用 resize,无需手动调用
|
|
233
|
-
if (typeof this.mapInstance.checkResize === 'function') {
|
|
234
|
-
this.mapInstance.checkResize()
|
|
235
|
-
}
|
|
236
|
-
} catch (e) {
|
|
237
|
-
// 忽略
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
destroy() {
|
|
243
|
-
if (this._callbackName && typeof window !== 'undefined') {
|
|
244
|
-
try {
|
|
245
|
-
delete window[this._callbackName]
|
|
246
|
-
} catch (e) {
|
|
247
|
-
// 忽略
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
super.destroy()
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export default BaiduAdapter
|
|
1
|
+
/**
|
|
2
|
+
* 百度地图适配器 (BMap / Baidu)
|
|
3
|
+
* 百度地图 JS API 3.0 支持自定义样式
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { MapAdapterBase } from './base'
|
|
7
|
+
import { hasGlobal } from '../loaders/script-loader'
|
|
8
|
+
|
|
9
|
+
// 百度地图类型映射
|
|
10
|
+
const BAIDU_MAP_TYPES = {
|
|
11
|
+
standard: 'BMAP_NORMAL_MAP',
|
|
12
|
+
satellite: 'BMAP_SATELLITE_MAP',
|
|
13
|
+
hybrid: 'BMAP_HYBRID_MAP',
|
|
14
|
+
traffic: 'BMAP_NORMAL_MAP' // 路况通过图层叠加
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 百度地图自定义样式 ID(主题)
|
|
18
|
+
// light: 官方 normal 样式
|
|
19
|
+
// dark: 午夜蓝 dark 样式
|
|
20
|
+
const BAIDU_STYLES = {
|
|
21
|
+
light: { style: 'normal' },
|
|
22
|
+
dark: { style: 'dark' }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class BaiduAdapter extends MapAdapterBase {
|
|
26
|
+
constructor(container, options = {}) {
|
|
27
|
+
super(container, options)
|
|
28
|
+
this._mapTypeMap = { ...BAIDU_MAP_TYPES }
|
|
29
|
+
this._coordType = options.baiduCoordType || 'bd09ll'
|
|
30
|
+
this._trafficLayer = null
|
|
31
|
+
this._callbackName = null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getScriptUrl() {
|
|
35
|
+
if (this.apiUrl) return this.apiUrl
|
|
36
|
+
if (!this.apiKey) {
|
|
37
|
+
console.warn('[XtMap] 百度地图需要配置 apiKey (ak)')
|
|
38
|
+
return ''
|
|
39
|
+
}
|
|
40
|
+
// 注意:_callbackName 在 beforeLoadScript 中已注册
|
|
41
|
+
return `https://api.map.baidu.com/api?v=3.0&ak=${encodeURIComponent(this.apiKey)}&callback=${this._callbackName}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 脚本加载前注册百度 SDK 回调函数
|
|
46
|
+
*/
|
|
47
|
+
beforeLoadScript() {
|
|
48
|
+
// 生成唯一 callback 名称,支持多实例
|
|
49
|
+
this._callbackName = `__xt_map_baidu_${Date.now()}_${Math.floor(Math.random() * 100000)}`
|
|
50
|
+
// 注册全局 callback(百度地图 SDK 加载完成后调用)
|
|
51
|
+
if (typeof window !== 'undefined') {
|
|
52
|
+
window[this._callbackName] = () => {
|
|
53
|
+
// 空实现,仅用于触发 Promise resolve
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
isSdkLoaded() {
|
|
59
|
+
return hasGlobal('BMap') && typeof window.BMap === 'function'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async createMap() {
|
|
63
|
+
const BMap = window.BMap
|
|
64
|
+
if (!BMap) throw new Error('[XtMap] 百度地图 SDK 未加载')
|
|
65
|
+
|
|
66
|
+
const mapOptions = {
|
|
67
|
+
enableMapClick: false
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.mapInstance = new BMap.Map(this.container, mapOptions)
|
|
71
|
+
this.mapInstance.centerAndZoom(new BMap.Point(this.center[0], this.center[1]), this.zoom)
|
|
72
|
+
this.mapInstance.enableScrollWheelZoom(true)
|
|
73
|
+
|
|
74
|
+
// 应用地图类型
|
|
75
|
+
this._applyMapType(this.mapType)
|
|
76
|
+
|
|
77
|
+
// 应用主题
|
|
78
|
+
this._applyTheme(this.theme)
|
|
79
|
+
|
|
80
|
+
// 等待地图就绪
|
|
81
|
+
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
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 || !window.BMap) return
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// 清除路况图层
|
|
93
|
+
if (this._trafficLayer) {
|
|
94
|
+
try {
|
|
95
|
+
this.mapInstance.removeTileLayer(this._trafficLayer)
|
|
96
|
+
} catch (e) {}
|
|
97
|
+
this._trafficLayer = null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (type === 'satellite') {
|
|
101
|
+
this.mapInstance.setMapType(window.BMAP_SATELLITE_MAP || 1)
|
|
102
|
+
} else if (type === 'hybrid') {
|
|
103
|
+
this.mapInstance.setMapType(window.BMAP_HYBRID_MAP || 2)
|
|
104
|
+
} else if (type === 'traffic') {
|
|
105
|
+
this.mapInstance.setMapType(window.BMAP_NORMAL_MAP || 0)
|
|
106
|
+
// 叠加路况图层
|
|
107
|
+
try {
|
|
108
|
+
const BMap = window.BMap
|
|
109
|
+
this._trafficLayer = new BMap.TrafficLayer()
|
|
110
|
+
this.mapInstance.addTileLayer(this._trafficLayer)
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.warn('[XtMap] 百度地图加载路况图层失败:', e)
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
this.mapInstance.setMapType(window.BMAP_NORMAL_MAP || 0)
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.warn('[XtMap] 百度地图切换地图类型失败:', e)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
_applyTheme(theme) {
|
|
123
|
+
if (!this.mapInstance || !window.BMap) return
|
|
124
|
+
try {
|
|
125
|
+
// 百度 3.0 通过 setMapStyle 设置主题样式
|
|
126
|
+
const styleConfig = BAIDU_STYLES[theme] || BAIDU_STYLES.light
|
|
127
|
+
if (this.mapInstance.setMapStyleV2) {
|
|
128
|
+
// 新版 API
|
|
129
|
+
this.mapInstance.setMapStyleV2({ styleId: styleConfig.style === 'dark' ? 'midnight' : '' })
|
|
130
|
+
} else if (this.mapInstance.setMapStyle) {
|
|
131
|
+
// 旧版 API
|
|
132
|
+
const styleJson = theme === 'dark' ? this._getDarkStyleJson() : null
|
|
133
|
+
if (styleJson) {
|
|
134
|
+
this.mapInstance.setMapStyle({ styleJson: styleJson })
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} catch (e) {
|
|
138
|
+
console.warn('[XtMap] 百度地图设置主题失败:', e)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 简易百度地图 dark 样式 JSON 配置
|
|
144
|
+
*/
|
|
145
|
+
_getDarkStyleJson() {
|
|
146
|
+
return [
|
|
147
|
+
{ featureType: 'land', elementType: 'geometry', stylers: { color: '#1a1a1a' } },
|
|
148
|
+
{ featureType: 'water', elementType: 'geometry', stylers: { color: '#0a1a2a' } },
|
|
149
|
+
{ featureType: 'green', elementType: 'geometry', stylers: { color: '#0a2a1a' } },
|
|
150
|
+
{ featureType: 'building', elementType: 'geometry', stylers: { color: '#2a2a2a' } },
|
|
151
|
+
{ featureType: 'highway', elementType: 'geometry', stylers: { color: '#3a3a3a' } },
|
|
152
|
+
{ featureType: 'highway', elementType: 'geometry.stroke', stylers: { color: '#4a4a4a' } },
|
|
153
|
+
{ featureType: 'arterial', elementType: 'geometry', stylers: { color: '#333333' } },
|
|
154
|
+
{ featureType: 'arterial', elementType: 'geometry.stroke', stylers: { color: '#3d3d3d' } },
|
|
155
|
+
{ featureType: 'local', elementType: 'geometry', stylers: { color: '#2a2a2a' } },
|
|
156
|
+
{ featureType: 'railway', elementType: 'geometry', stylers: { color: '#3a3a3a' } },
|
|
157
|
+
{ featureType: 'subway', elementType: 'geometry', stylers: { color: '#3a3a3a' } },
|
|
158
|
+
{ featureType: 'boundary', elementType: 'geometry', stylers: { color: '#666666' } },
|
|
159
|
+
{ featureType: 'district', elementType: 'labels.text.fill', stylers: { color: '#888888' } },
|
|
160
|
+
{ featureType: 'poi', elementType: 'labels', stylers: { visibility: 'off' } }
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_applyCenter(center) {
|
|
165
|
+
if (!this.mapInstance || !window.BMap) return
|
|
166
|
+
try {
|
|
167
|
+
this.mapInstance.centerAndZoom(new window.BMap.Point(center[0], center[1]), this.zoom)
|
|
168
|
+
} catch (e) {
|
|
169
|
+
// 忽略
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
_applyZoom(zoom) {
|
|
174
|
+
if (!this.mapInstance) return
|
|
175
|
+
try {
|
|
176
|
+
this.mapInstance.setZoom(zoom)
|
|
177
|
+
} catch (e) {
|
|
178
|
+
// 忽略
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getCenter() {
|
|
183
|
+
if (this.mapInstance && this.mapInstance.getCenter) {
|
|
184
|
+
const c = this.mapInstance.getCenter()
|
|
185
|
+
if (c) return [c.lng, c.lat]
|
|
186
|
+
}
|
|
187
|
+
return this.center
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
getZoom() {
|
|
191
|
+
if (this.mapInstance && this.mapInstance.getZoom) {
|
|
192
|
+
return this.mapInstance.getZoom()
|
|
193
|
+
}
|
|
194
|
+
return this.zoom
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
_bindEvent(eventName, handler) {
|
|
198
|
+
if (!this.mapInstance) return
|
|
199
|
+
try {
|
|
200
|
+
const eventMap = {
|
|
201
|
+
click: 'click',
|
|
202
|
+
moveend: 'moveend',
|
|
203
|
+
zoomend: 'zoomend',
|
|
204
|
+
zoomchange: 'zoomend',
|
|
205
|
+
mapmove: 'movestart'
|
|
206
|
+
}
|
|
207
|
+
const nativeEvent = eventMap[eventName] || eventName
|
|
208
|
+
this.mapInstance.addEventListener(nativeEvent, (e) => {
|
|
209
|
+
const normalized = {
|
|
210
|
+
originalEvent: e,
|
|
211
|
+
lnglat: e && e.point ? [e.point.lng, e.point.lat] : null
|
|
212
|
+
}
|
|
213
|
+
handler(normalized)
|
|
214
|
+
})
|
|
215
|
+
} catch (err) {
|
|
216
|
+
console.warn('[XtMap] 百度地图事件绑定失败:', eventName, err)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
_unbindEvent(eventName, handler) {
|
|
221
|
+
if (!this.mapInstance) return
|
|
222
|
+
try {
|
|
223
|
+
this.mapInstance.removeEventListener(eventName, handler)
|
|
224
|
+
} catch (e) {
|
|
225
|
+
// 忽略
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
_applyResize() {
|
|
230
|
+
if (this.mapInstance && this.mapInstance.enableResize) {
|
|
231
|
+
try {
|
|
232
|
+
// 百度地图默认启用 resize,无需手动调用
|
|
233
|
+
if (typeof this.mapInstance.checkResize === 'function') {
|
|
234
|
+
this.mapInstance.checkResize()
|
|
235
|
+
}
|
|
236
|
+
} catch (e) {
|
|
237
|
+
// 忽略
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
destroy() {
|
|
243
|
+
if (this._callbackName && typeof window !== 'undefined') {
|
|
244
|
+
try {
|
|
245
|
+
delete window[this._callbackName]
|
|
246
|
+
} catch (e) {
|
|
247
|
+
// 忽略
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
super.destroy()
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export default BaiduAdapter
|