xy-map 1.0.56 → 1.0.58
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/src/layers/Point.js +383 -383
- package/src/layers/Text.js +52 -52
- package/src/map.js +2 -1
- package/src/util/gaodeApi.js +66 -66
- package/vue.config.js +3 -2
package/package.json
CHANGED
package/src/layers/Point.js
CHANGED
|
@@ -1,384 +1,384 @@
|
|
|
1
|
-
import mapSdk from '../map'
|
|
2
|
-
import {
|
|
3
|
-
hasSource,
|
|
4
|
-
hasLayer,
|
|
5
|
-
setSource
|
|
6
|
-
} from './index'
|
|
7
|
-
import {
|
|
8
|
-
addLayerText
|
|
9
|
-
} from './Text'
|
|
10
|
-
import {
|
|
11
|
-
loadImage
|
|
12
|
-
} from '../util/mapTools'
|
|
13
|
-
import {
|
|
14
|
-
mapClick
|
|
15
|
-
} from '../util/mapEvent'
|
|
16
|
-
|
|
17
|
-
const defaultOptions = {
|
|
18
|
-
id: '',
|
|
19
|
-
data: [],
|
|
20
|
-
text: {
|
|
21
|
-
show: true,
|
|
22
|
-
layout: {
|
|
23
|
-
'text-size': 10,
|
|
24
|
-
'text-offset': [0, 1],
|
|
25
|
-
},
|
|
26
|
-
paint: {}
|
|
27
|
-
},
|
|
28
|
-
image: {
|
|
29
|
-
width: 24,
|
|
30
|
-
height: 24,
|
|
31
|
-
src: '',
|
|
32
|
-
imageList: [],
|
|
33
|
-
},
|
|
34
|
-
style: {
|
|
35
|
-
layout: {},
|
|
36
|
-
paint: {}
|
|
37
|
-
},
|
|
38
|
-
cluster: {
|
|
39
|
-
cluster: false,
|
|
40
|
-
clusterMaxZoom: 16,
|
|
41
|
-
clusterRadius: 500,
|
|
42
|
-
style: {
|
|
43
|
-
layout: {},
|
|
44
|
-
paint: {}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
click: null,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 添加点图层
|
|
52
|
-
*/
|
|
53
|
-
export const addLayerPoint = (option, layerId) => { // 点
|
|
54
|
-
let {
|
|
55
|
-
map
|
|
56
|
-
} = mapSdk
|
|
57
|
-
|
|
58
|
-
let opt = Object.assign({}, defaultOptions, option)
|
|
59
|
-
let id = opt.id
|
|
60
|
-
if (hasLayer(id)) {
|
|
61
|
-
setSource(id, opt.data)
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let paint = opt.style ? opt.style.paint : {}
|
|
66
|
-
let paintOpt = Object.assign({
|
|
67
|
-
'circle-color': '#11b4da',
|
|
68
|
-
'circle-radius': 4,
|
|
69
|
-
'circle-stroke-width': 1,
|
|
70
|
-
'circle-stroke-color': '#fff'
|
|
71
|
-
}, paint)
|
|
72
|
-
|
|
73
|
-
if (!hasSource(id)) {
|
|
74
|
-
map.addSource(id, {
|
|
75
|
-
type: 'geojson',
|
|
76
|
-
data: opt.data,
|
|
77
|
-
cluster: opt.cluster.cluster,
|
|
78
|
-
clusterMaxZoom: opt.cluster.clusterMaxZoom,
|
|
79
|
-
clusterRadius: opt.cluster.clusterRadius
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
map.addLayer({
|
|
84
|
-
id: id,
|
|
85
|
-
type: 'circle',
|
|
86
|
-
source: id,
|
|
87
|
-
paint: paintOpt,
|
|
88
|
-
...opt.other
|
|
89
|
-
}, layerId)
|
|
90
|
-
|
|
91
|
-
if (opt.cluster.cluster) {
|
|
92
|
-
let style = opt.cluster.style || {}
|
|
93
|
-
clusterLayer(id, style)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (opt.click) {
|
|
97
|
-
mapClick(id, opt.click)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 添加文本图层
|
|
101
|
-
if (opt.text && opt.text.show) {
|
|
102
|
-
addLayerText('point', opt)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// 高亮样式
|
|
106
|
-
if (opt.high) {
|
|
107
|
-
let highPaint = opt.high.paint ? opt.high.paint : {
|
|
108
|
-
'circle-color': '#f00'
|
|
109
|
-
}
|
|
110
|
-
let highPaintOpt = Object.assign({
|
|
111
|
-
...paintOpt,
|
|
112
|
-
}, highPaint)
|
|
113
|
-
|
|
114
|
-
map.addLayer({
|
|
115
|
-
id: id + '-high',
|
|
116
|
-
type: 'circle',
|
|
117
|
-
source: id,
|
|
118
|
-
paint: highPaintOpt,
|
|
119
|
-
filter: ['==', ['boolean', ['get', 'high']], true]
|
|
120
|
-
}, layerId)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 添加自定义点图层
|
|
126
|
-
*/
|
|
127
|
-
export const addDiyPoint = (option, layerId) => { // 点
|
|
128
|
-
let {
|
|
129
|
-
map
|
|
130
|
-
} = mapSdk
|
|
131
|
-
|
|
132
|
-
let opt = Object.assign({}, defaultOptions, option)
|
|
133
|
-
let id = opt.id
|
|
134
|
-
if (hasLayer(id)) {
|
|
135
|
-
setSource(id, opt.data)
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
let layout = opt.style ? opt.style.layout : {}
|
|
140
|
-
let layoutOpt = Object.assign({
|
|
141
|
-
'text-field': '{name}',
|
|
142
|
-
/* 使用text标签显示的值,Feature属性使用{域名}格式*/
|
|
143
|
-
'text-font': ['Open Sans Semibold'],
|
|
144
|
-
/* 文本字体 */
|
|
145
|
-
'text-size': 10,
|
|
146
|
-
'text-offset': [0, 1], // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
|
|
147
|
-
'text-anchor': 'top', // 图标与锚点的位置关系
|
|
148
|
-
'icon-allow-overlap': false, // 是否允许图标重叠
|
|
149
|
-
'icon-ignore-placement': false, // 是否忽略图标位置(可选,默认值为 false。当值为 true 时,其他符号即使与此图标触碰也会显示)
|
|
150
|
-
'text-allow-overlap': false, // 是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
|
|
151
|
-
'text-ignore-placement': false, // 是否忽略文本位置(可选,默认值为 false。当值为 true 时,其他符号即使与此文本触碰也会显示)
|
|
152
|
-
// 'text-max-width': 12, // 文本宽度
|
|
153
|
-
'visibility': 'visible'
|
|
154
|
-
}, layout)
|
|
155
|
-
|
|
156
|
-
let paint = opt.style ? opt.style.paint : {}
|
|
157
|
-
let paintOpt = Object.assign({
|
|
158
|
-
'text-color': '#ffffff',
|
|
159
|
-
'text-halo-color': 'rgba(0, 0, 0, .5)',
|
|
160
|
-
'text-halo-width': 0.8,
|
|
161
|
-
'text-opacity': 1
|
|
162
|
-
}, paint)
|
|
163
|
-
|
|
164
|
-
if (!hasSource(id)) {
|
|
165
|
-
map.addSource(id, {
|
|
166
|
-
type: 'geojson',
|
|
167
|
-
data: opt.data,
|
|
168
|
-
cluster: opt.cluster.cluster,
|
|
169
|
-
clusterMaxZoom: opt.cluster.clusterMaxZoom,
|
|
170
|
-
clusterRadius: opt.cluster.clusterRadius
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
map.addLayer({
|
|
175
|
-
id: id,
|
|
176
|
-
type: 'symbol',
|
|
177
|
-
source: id,
|
|
178
|
-
layout: layoutOpt,
|
|
179
|
-
paint: paintOpt,
|
|
180
|
-
...opt.other
|
|
181
|
-
}, layerId)
|
|
182
|
-
|
|
183
|
-
if (opt.cluster.cluster) {
|
|
184
|
-
let style = opt.cluster.style || {}
|
|
185
|
-
clusterLayer(id, style)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (opt.click) {
|
|
189
|
-
mapClick(id, opt.click)
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* 添加图片点图层
|
|
195
|
-
*/
|
|
196
|
-
export const addLayerImagePoint = async (option, layerId) => { // 点
|
|
197
|
-
let {
|
|
198
|
-
map
|
|
199
|
-
} = mapSdk
|
|
200
|
-
|
|
201
|
-
let opt = Object.assign({}, defaultOptions, option)
|
|
202
|
-
let id = opt.id
|
|
203
|
-
if (hasLayer(id)) {
|
|
204
|
-
setSource(id, opt.data)
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
let image = opt.image
|
|
209
|
-
|
|
210
|
-
let layout = opt.style ? opt.style.layout : {}
|
|
211
|
-
let layoutOpt = Object.assign({
|
|
212
|
-
'icon-image': image.imageList && image.imageList.length > 0 ? ['get', opt.image.key || 'imgId'] : `${id}-marker`,
|
|
213
|
-
'icon-size': 1,
|
|
214
|
-
'text-field': '{name}',
|
|
215
|
-
/* 使用text标签显示的值,Feature属性使用{域名}格式*/
|
|
216
|
-
'text-font': ['Open Sans Semibold'],
|
|
217
|
-
/* 文本字体 */
|
|
218
|
-
'text-size': 10,
|
|
219
|
-
'text-offset': [0, 1], // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
|
|
220
|
-
'text-anchor': 'top', // 图标与锚点的位置关系
|
|
221
|
-
'icon-allow-overlap': false, // 是否允许图标重叠
|
|
222
|
-
'icon-ignore-placement': false, // 是否忽略图标位置(可选,默认值为 false。当值为 true 时,其他符号即使与此图标触碰也会显示)
|
|
223
|
-
'text-allow-overlap': false, // 是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
|
|
224
|
-
'text-ignore-placement': false, // 是否忽略文本位置(可选,默认值为 false。当值为 true 时,其他符号即使与此文本触碰也会显示)
|
|
225
|
-
// 'text-max-width': 12, // 文本宽度
|
|
226
|
-
'visibility': 'visible'
|
|
227
|
-
}, layout)
|
|
228
|
-
|
|
229
|
-
let paint = opt.style ? opt.style.paint : {}
|
|
230
|
-
let paintOpt = Object.assign({
|
|
231
|
-
'text-color': '#ffffff',
|
|
232
|
-
'text-halo-color': 'rgba(0, 0, 0, .5)',
|
|
233
|
-
'text-halo-width': 0.8,
|
|
234
|
-
'text-opacity': 1
|
|
235
|
-
}, paint)
|
|
236
|
-
|
|
237
|
-
if (!hasSource(id)) {
|
|
238
|
-
map.addSource(id, {
|
|
239
|
-
type: 'geojson',
|
|
240
|
-
data: opt.data,
|
|
241
|
-
cluster: opt.cluster.cluster,
|
|
242
|
-
clusterMaxZoom: opt.cluster.clusterMaxZoom,
|
|
243
|
-
clusterRadius: opt.cluster.clusterRadius
|
|
244
|
-
})
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// 图片加载完成后的操作
|
|
248
|
-
const afterOperation = () => {
|
|
249
|
-
map.addLayer({
|
|
250
|
-
id: id,
|
|
251
|
-
type: 'symbol',
|
|
252
|
-
source: id,
|
|
253
|
-
layout: layoutOpt,
|
|
254
|
-
paint: paintOpt,
|
|
255
|
-
...opt.other
|
|
256
|
-
}, layerId)
|
|
257
|
-
|
|
258
|
-
// 高亮样式
|
|
259
|
-
if (opt.high) {
|
|
260
|
-
let highLayout = opt.high.layout ? opt.high.layout : {}
|
|
261
|
-
let highLayoutOpt = Object.assign({
|
|
262
|
-
...layoutOpt,
|
|
263
|
-
}, highLayout)
|
|
264
|
-
|
|
265
|
-
let highPaint = opt.high.paint ? opt.high.paint : {
|
|
266
|
-
'text-color': '#ff0'
|
|
267
|
-
}
|
|
268
|
-
let highPaintOpt = Object.assign({
|
|
269
|
-
...paintOpt,
|
|
270
|
-
}, highPaint)
|
|
271
|
-
|
|
272
|
-
map.addLayer({
|
|
273
|
-
id: id + '-high',
|
|
274
|
-
type: 'symbol',
|
|
275
|
-
source: id,
|
|
276
|
-
layout: highLayoutOpt,
|
|
277
|
-
paint: highPaintOpt,
|
|
278
|
-
filter: ['==', ['boolean', ['get', 'high']], true]
|
|
279
|
-
}, layerId)
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (opt.cluster.cluster) {
|
|
283
|
-
let style = opt.cluster.style || {}
|
|
284
|
-
clusterLayer(id, style)
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (opt.click) {
|
|
288
|
-
mapClick(id, opt.click)
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
//图像处理导入
|
|
292
|
-
if (image.imageList && image.imageList.length > 0) {
|
|
293
|
-
// 循环遍历图片,同步执行,避免layer重复创建
|
|
294
|
-
for (let i = 0; i < image.imageList.length; i++) {
|
|
295
|
-
const img = image.imageList[i]
|
|
296
|
-
const loadImg = new Promise((resolve, reject) => {
|
|
297
|
-
loadImage(img.url, image.width, image.height).then(image => {
|
|
298
|
-
if (map.hasImage(`${img.id}`)) {
|
|
299
|
-
map.updateImage(`${img.id}`, image)
|
|
300
|
-
} else {
|
|
301
|
-
map.addImage(`${img.id}`, image)
|
|
302
|
-
}
|
|
303
|
-
resolve()
|
|
304
|
-
})
|
|
305
|
-
})
|
|
306
|
-
await loadImg
|
|
307
|
-
}
|
|
308
|
-
afterOperation()
|
|
309
|
-
} else {
|
|
310
|
-
const img = image.src || require('../image/marker.png')
|
|
311
|
-
loadImage(img, image.width, image.height).then(image => {
|
|
312
|
-
if (map.hasImage(`${id}-marker`)) {
|
|
313
|
-
map.updateImage(`${id}-marker`, image)
|
|
314
|
-
} else {
|
|
315
|
-
map.addImage(`${id}-marker`, image)
|
|
316
|
-
}
|
|
317
|
-
afterOperation()
|
|
318
|
-
})
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* 点聚合图层
|
|
324
|
-
*/
|
|
325
|
-
export const clusterLayer = (option, style) => {
|
|
326
|
-
let {
|
|
327
|
-
map
|
|
328
|
-
} = mapSdk
|
|
329
|
-
|
|
330
|
-
let id = option.id
|
|
331
|
-
if (hasLayer(id)) {
|
|
332
|
-
setSource(id, option.data)
|
|
333
|
-
return
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
let layout = style ? style.layout : {}
|
|
337
|
-
let layoutOpt = Object.assign({
|
|
338
|
-
'text-field': '{point_count_abbreviated}',
|
|
339
|
-
'text-size': 12,
|
|
340
|
-
'visibility': 'visible'
|
|
341
|
-
}, layout)
|
|
342
|
-
|
|
343
|
-
let paint = style ? style.paint : {}
|
|
344
|
-
let paintOpt = Object.assign({
|
|
345
|
-
'circle-color': [
|
|
346
|
-
'step',
|
|
347
|
-
['get', 'point_count'],
|
|
348
|
-
'#51bbd6',
|
|
349
|
-
100,
|
|
350
|
-
'#f1f075',
|
|
351
|
-
350,
|
|
352
|
-
'#f28cb1'
|
|
353
|
-
],
|
|
354
|
-
'circle-radius': [
|
|
355
|
-
'step',
|
|
356
|
-
['get', 'point_count'],
|
|
357
|
-
20,
|
|
358
|
-
100,
|
|
359
|
-
30,
|
|
360
|
-
750,
|
|
361
|
-
40
|
|
362
|
-
]
|
|
363
|
-
}, paint)
|
|
364
|
-
|
|
365
|
-
map.addLayer({
|
|
366
|
-
id: id + '-clusters',
|
|
367
|
-
type: 'circle',
|
|
368
|
-
source: id,
|
|
369
|
-
filter: ['has', 'point_count'],
|
|
370
|
-
paint: paintOpt
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
map.addLayer({
|
|
374
|
-
id: id + '-cluster-count',
|
|
375
|
-
type: 'symbol',
|
|
376
|
-
source: option.id,
|
|
377
|
-
filter: ['has', 'point_count'],
|
|
378
|
-
layout: layoutOpt
|
|
379
|
-
})
|
|
380
|
-
|
|
381
|
-
mapClick(id + 'clusters', (e) => {
|
|
382
|
-
mapSdk.zoom('in', e.position)
|
|
383
|
-
})
|
|
1
|
+
import mapSdk from '../map'
|
|
2
|
+
import {
|
|
3
|
+
hasSource,
|
|
4
|
+
hasLayer,
|
|
5
|
+
setSource
|
|
6
|
+
} from './index'
|
|
7
|
+
import {
|
|
8
|
+
addLayerText
|
|
9
|
+
} from './Text'
|
|
10
|
+
import {
|
|
11
|
+
loadImage
|
|
12
|
+
} from '../util/mapTools'
|
|
13
|
+
import {
|
|
14
|
+
mapClick
|
|
15
|
+
} from '../util/mapEvent'
|
|
16
|
+
|
|
17
|
+
const defaultOptions = {
|
|
18
|
+
id: '',
|
|
19
|
+
data: [],
|
|
20
|
+
text: {
|
|
21
|
+
show: true,
|
|
22
|
+
layout: {
|
|
23
|
+
'text-size': 10,
|
|
24
|
+
'text-offset': [0, 1],
|
|
25
|
+
},
|
|
26
|
+
paint: {}
|
|
27
|
+
},
|
|
28
|
+
image: {
|
|
29
|
+
width: 24,
|
|
30
|
+
height: 24,
|
|
31
|
+
src: '',
|
|
32
|
+
imageList: [],
|
|
33
|
+
},
|
|
34
|
+
style: {
|
|
35
|
+
layout: {},
|
|
36
|
+
paint: {}
|
|
37
|
+
},
|
|
38
|
+
cluster: {
|
|
39
|
+
cluster: false,
|
|
40
|
+
clusterMaxZoom: 16,
|
|
41
|
+
clusterRadius: 500,
|
|
42
|
+
style: {
|
|
43
|
+
layout: {},
|
|
44
|
+
paint: {}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
click: null,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 添加点图层
|
|
52
|
+
*/
|
|
53
|
+
export const addLayerPoint = (option, layerId) => { // 点
|
|
54
|
+
let {
|
|
55
|
+
map
|
|
56
|
+
} = mapSdk
|
|
57
|
+
|
|
58
|
+
let opt = Object.assign({}, defaultOptions, option)
|
|
59
|
+
let id = opt.id
|
|
60
|
+
if (hasLayer(id)) {
|
|
61
|
+
setSource(id, opt.data)
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let paint = opt.style ? opt.style.paint : {}
|
|
66
|
+
let paintOpt = Object.assign({
|
|
67
|
+
'circle-color': '#11b4da',
|
|
68
|
+
'circle-radius': 4,
|
|
69
|
+
'circle-stroke-width': 1,
|
|
70
|
+
'circle-stroke-color': '#fff'
|
|
71
|
+
}, paint)
|
|
72
|
+
|
|
73
|
+
if (!hasSource(id)) {
|
|
74
|
+
map.addSource(id, {
|
|
75
|
+
type: 'geojson',
|
|
76
|
+
data: opt.data,
|
|
77
|
+
cluster: opt.cluster.cluster,
|
|
78
|
+
clusterMaxZoom: opt.cluster.clusterMaxZoom,
|
|
79
|
+
clusterRadius: opt.cluster.clusterRadius
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
map.addLayer({
|
|
84
|
+
id: id,
|
|
85
|
+
type: 'circle',
|
|
86
|
+
source: id,
|
|
87
|
+
paint: paintOpt,
|
|
88
|
+
...opt.other
|
|
89
|
+
}, layerId)
|
|
90
|
+
|
|
91
|
+
if (opt.cluster.cluster) {
|
|
92
|
+
let style = opt.cluster.style || {}
|
|
93
|
+
clusterLayer(id, style)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (opt.click) {
|
|
97
|
+
mapClick(id, opt.click)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 添加文本图层
|
|
101
|
+
if (opt.text && opt.text.show) {
|
|
102
|
+
addLayerText('point', opt)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 高亮样式
|
|
106
|
+
if (opt.high) {
|
|
107
|
+
let highPaint = opt.high.paint ? opt.high.paint : {
|
|
108
|
+
'circle-color': '#f00'
|
|
109
|
+
}
|
|
110
|
+
let highPaintOpt = Object.assign({
|
|
111
|
+
...paintOpt,
|
|
112
|
+
}, highPaint)
|
|
113
|
+
|
|
114
|
+
map.addLayer({
|
|
115
|
+
id: id + '-high',
|
|
116
|
+
type: 'circle',
|
|
117
|
+
source: id,
|
|
118
|
+
paint: highPaintOpt,
|
|
119
|
+
filter: ['==', ['boolean', ['get', 'high']], true]
|
|
120
|
+
}, layerId)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 添加自定义点图层
|
|
126
|
+
*/
|
|
127
|
+
export const addDiyPoint = (option, layerId) => { // 点
|
|
128
|
+
let {
|
|
129
|
+
map
|
|
130
|
+
} = mapSdk
|
|
131
|
+
|
|
132
|
+
let opt = Object.assign({}, defaultOptions, option)
|
|
133
|
+
let id = opt.id
|
|
134
|
+
if (hasLayer(id)) {
|
|
135
|
+
setSource(id, opt.data)
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let layout = opt.style ? opt.style.layout : {}
|
|
140
|
+
let layoutOpt = Object.assign({
|
|
141
|
+
'text-field': '{name}',
|
|
142
|
+
/* 使用text标签显示的值,Feature属性使用{域名}格式*/
|
|
143
|
+
'text-font': ['Open Sans Semibold'],
|
|
144
|
+
/* 文本字体 */
|
|
145
|
+
'text-size': 10,
|
|
146
|
+
'text-offset': [0, 1], // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
|
|
147
|
+
'text-anchor': 'top', // 图标与锚点的位置关系
|
|
148
|
+
'icon-allow-overlap': false, // 是否允许图标重叠
|
|
149
|
+
'icon-ignore-placement': false, // 是否忽略图标位置(可选,默认值为 false。当值为 true 时,其他符号即使与此图标触碰也会显示)
|
|
150
|
+
'text-allow-overlap': false, // 是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
|
|
151
|
+
'text-ignore-placement': false, // 是否忽略文本位置(可选,默认值为 false。当值为 true 时,其他符号即使与此文本触碰也会显示)
|
|
152
|
+
// 'text-max-width': 12, // 文本宽度
|
|
153
|
+
'visibility': 'visible'
|
|
154
|
+
}, layout)
|
|
155
|
+
|
|
156
|
+
let paint = opt.style ? opt.style.paint : {}
|
|
157
|
+
let paintOpt = Object.assign({
|
|
158
|
+
'text-color': '#ffffff',
|
|
159
|
+
'text-halo-color': 'rgba(0, 0, 0, .5)',
|
|
160
|
+
'text-halo-width': 0.8,
|
|
161
|
+
'text-opacity': 1
|
|
162
|
+
}, paint)
|
|
163
|
+
|
|
164
|
+
if (!hasSource(id)) {
|
|
165
|
+
map.addSource(id, {
|
|
166
|
+
type: 'geojson',
|
|
167
|
+
data: opt.data,
|
|
168
|
+
cluster: opt.cluster.cluster,
|
|
169
|
+
clusterMaxZoom: opt.cluster.clusterMaxZoom,
|
|
170
|
+
clusterRadius: opt.cluster.clusterRadius
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
map.addLayer({
|
|
175
|
+
id: id,
|
|
176
|
+
type: 'symbol',
|
|
177
|
+
source: id,
|
|
178
|
+
layout: layoutOpt,
|
|
179
|
+
paint: paintOpt,
|
|
180
|
+
...opt.other
|
|
181
|
+
}, layerId)
|
|
182
|
+
|
|
183
|
+
if (opt.cluster.cluster) {
|
|
184
|
+
let style = opt.cluster.style || {}
|
|
185
|
+
clusterLayer(id, style)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (opt.click) {
|
|
189
|
+
mapClick(id, opt.click)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 添加图片点图层
|
|
195
|
+
*/
|
|
196
|
+
export const addLayerImagePoint = async (option, layerId) => { // 点
|
|
197
|
+
let {
|
|
198
|
+
map
|
|
199
|
+
} = mapSdk
|
|
200
|
+
|
|
201
|
+
let opt = Object.assign({}, defaultOptions, option)
|
|
202
|
+
let id = opt.id
|
|
203
|
+
if (hasLayer(id)) {
|
|
204
|
+
setSource(id, opt.data)
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let image = opt.image
|
|
209
|
+
|
|
210
|
+
let layout = opt.style ? opt.style.layout : {}
|
|
211
|
+
let layoutOpt = Object.assign({
|
|
212
|
+
'icon-image': image.imageList && image.imageList.length > 0 ? ['get', opt.image.key || 'imgId'] : `${id}-marker`,
|
|
213
|
+
'icon-size': 1,
|
|
214
|
+
'text-field': '{name}',
|
|
215
|
+
/* 使用text标签显示的值,Feature属性使用{域名}格式*/
|
|
216
|
+
'text-font': ['Open Sans Semibold'],
|
|
217
|
+
/* 文本字体 */
|
|
218
|
+
'text-size': 10,
|
|
219
|
+
'text-offset': [0, 1], // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
|
|
220
|
+
'text-anchor': 'top', // 图标与锚点的位置关系
|
|
221
|
+
'icon-allow-overlap': false, // 是否允许图标重叠
|
|
222
|
+
'icon-ignore-placement': false, // 是否忽略图标位置(可选,默认值为 false。当值为 true 时,其他符号即使与此图标触碰也会显示)
|
|
223
|
+
'text-allow-overlap': false, // 是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
|
|
224
|
+
'text-ignore-placement': false, // 是否忽略文本位置(可选,默认值为 false。当值为 true 时,其他符号即使与此文本触碰也会显示)
|
|
225
|
+
// 'text-max-width': 12, // 文本宽度
|
|
226
|
+
'visibility': 'visible'
|
|
227
|
+
}, layout)
|
|
228
|
+
|
|
229
|
+
let paint = opt.style ? opt.style.paint : {}
|
|
230
|
+
let paintOpt = Object.assign({
|
|
231
|
+
'text-color': '#ffffff',
|
|
232
|
+
'text-halo-color': 'rgba(0, 0, 0, .5)',
|
|
233
|
+
'text-halo-width': 0.8,
|
|
234
|
+
'text-opacity': 1
|
|
235
|
+
}, paint)
|
|
236
|
+
|
|
237
|
+
if (!hasSource(id)) {
|
|
238
|
+
map.addSource(id, {
|
|
239
|
+
type: 'geojson',
|
|
240
|
+
data: opt.data,
|
|
241
|
+
cluster: opt.cluster.cluster,
|
|
242
|
+
clusterMaxZoom: opt.cluster.clusterMaxZoom,
|
|
243
|
+
clusterRadius: opt.cluster.clusterRadius
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 图片加载完成后的操作
|
|
248
|
+
const afterOperation = () => {
|
|
249
|
+
map.addLayer({
|
|
250
|
+
id: id,
|
|
251
|
+
type: 'symbol',
|
|
252
|
+
source: id,
|
|
253
|
+
layout: layoutOpt,
|
|
254
|
+
paint: paintOpt,
|
|
255
|
+
...opt.other
|
|
256
|
+
}, layerId)
|
|
257
|
+
|
|
258
|
+
// 高亮样式
|
|
259
|
+
if (opt.high) {
|
|
260
|
+
let highLayout = opt.high.layout ? opt.high.layout : {}
|
|
261
|
+
let highLayoutOpt = Object.assign({
|
|
262
|
+
...layoutOpt,
|
|
263
|
+
}, highLayout)
|
|
264
|
+
|
|
265
|
+
let highPaint = opt.high.paint ? opt.high.paint : {
|
|
266
|
+
'text-color': '#ff0'
|
|
267
|
+
}
|
|
268
|
+
let highPaintOpt = Object.assign({
|
|
269
|
+
...paintOpt,
|
|
270
|
+
}, highPaint)
|
|
271
|
+
|
|
272
|
+
map.addLayer({
|
|
273
|
+
id: id + '-high',
|
|
274
|
+
type: 'symbol',
|
|
275
|
+
source: id,
|
|
276
|
+
layout: highLayoutOpt,
|
|
277
|
+
paint: highPaintOpt,
|
|
278
|
+
filter: ['==', ['boolean', ['get', 'high']], true]
|
|
279
|
+
}, layerId)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (opt.cluster.cluster) {
|
|
283
|
+
let style = opt.cluster.style || {}
|
|
284
|
+
clusterLayer(id, style)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (opt.click) {
|
|
288
|
+
mapClick(id, opt.click)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
//图像处理导入
|
|
292
|
+
if (image.imageList && image.imageList.length > 0) {
|
|
293
|
+
// 循环遍历图片,同步执行,避免layer重复创建
|
|
294
|
+
for (let i = 0; i < image.imageList.length; i++) {
|
|
295
|
+
const img = image.imageList[i]
|
|
296
|
+
const loadImg = new Promise((resolve, reject) => {
|
|
297
|
+
loadImage(img.url, image.width, image.height).then(image => {
|
|
298
|
+
if (map.hasImage(`${img.id}`)) {
|
|
299
|
+
map.updateImage(`${img.id}`, image)
|
|
300
|
+
} else {
|
|
301
|
+
map.addImage(`${img.id}`, image)
|
|
302
|
+
}
|
|
303
|
+
resolve()
|
|
304
|
+
})
|
|
305
|
+
})
|
|
306
|
+
await loadImg
|
|
307
|
+
}
|
|
308
|
+
afterOperation()
|
|
309
|
+
} else {
|
|
310
|
+
const img = image.src || require('../image/marker.png')
|
|
311
|
+
loadImage(img, image.width, image.height).then(image => {
|
|
312
|
+
if (map.hasImage(`${id}-marker`)) {
|
|
313
|
+
map.updateImage(`${id}-marker`, image)
|
|
314
|
+
} else {
|
|
315
|
+
map.addImage(`${id}-marker`, image)
|
|
316
|
+
}
|
|
317
|
+
afterOperation()
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* 点聚合图层
|
|
324
|
+
*/
|
|
325
|
+
export const clusterLayer = (option, style) => {
|
|
326
|
+
let {
|
|
327
|
+
map
|
|
328
|
+
} = mapSdk
|
|
329
|
+
|
|
330
|
+
let id = option.id
|
|
331
|
+
if (hasLayer(id)) {
|
|
332
|
+
setSource(id, option.data)
|
|
333
|
+
return
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
let layout = style ? style.layout : {}
|
|
337
|
+
let layoutOpt = Object.assign({
|
|
338
|
+
'text-field': '{point_count_abbreviated}',
|
|
339
|
+
'text-size': 12,
|
|
340
|
+
'visibility': 'visible'
|
|
341
|
+
}, layout)
|
|
342
|
+
|
|
343
|
+
let paint = style ? style.paint : {}
|
|
344
|
+
let paintOpt = Object.assign({
|
|
345
|
+
'circle-color': [
|
|
346
|
+
'step',
|
|
347
|
+
['get', 'point_count'],
|
|
348
|
+
'#51bbd6',
|
|
349
|
+
100,
|
|
350
|
+
'#f1f075',
|
|
351
|
+
350,
|
|
352
|
+
'#f28cb1'
|
|
353
|
+
],
|
|
354
|
+
'circle-radius': [
|
|
355
|
+
'step',
|
|
356
|
+
['get', 'point_count'],
|
|
357
|
+
20,
|
|
358
|
+
100,
|
|
359
|
+
30,
|
|
360
|
+
750,
|
|
361
|
+
40
|
|
362
|
+
]
|
|
363
|
+
}, paint)
|
|
364
|
+
|
|
365
|
+
map.addLayer({
|
|
366
|
+
id: id + '-clusters',
|
|
367
|
+
type: 'circle',
|
|
368
|
+
source: id,
|
|
369
|
+
filter: ['has', 'point_count'],
|
|
370
|
+
paint: paintOpt
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
map.addLayer({
|
|
374
|
+
id: id + '-cluster-count',
|
|
375
|
+
type: 'symbol',
|
|
376
|
+
source: option.id,
|
|
377
|
+
filter: ['has', 'point_count'],
|
|
378
|
+
layout: layoutOpt
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
mapClick(id + 'clusters', (e) => {
|
|
382
|
+
mapSdk.zoom('in', e.position)
|
|
383
|
+
})
|
|
384
384
|
}
|
package/src/layers/Text.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import mapSdk from '../map'
|
|
2
|
-
import {
|
|
3
|
-
setSource,
|
|
4
|
-
hasLayer
|
|
5
|
-
} from './index'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 添加文字图层
|
|
9
|
-
*/
|
|
10
|
-
export const addLayerText = (placement = 'point', option, layerId) => { // 文本
|
|
11
|
-
let {
|
|
12
|
-
map
|
|
13
|
-
} = mapSdk
|
|
14
|
-
|
|
15
|
-
let opt = option
|
|
16
|
-
let parentId = opt.id
|
|
17
|
-
let id = parentId + '-text'
|
|
18
|
-
if (hasLayer(id)) {
|
|
19
|
-
setSource(id, opt.data)
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let layout = opt.text ? opt.text.layout : {}
|
|
24
|
-
let layoutOpt = Object.assign({
|
|
25
|
-
'symbol-placement': placement,
|
|
26
|
-
'text-field': '{name}',
|
|
27
|
-
/* 使用text标签显示的值,Feature属性使用{域名}格式*/
|
|
28
|
-
'text-font': ['Open Sans Semibold'],
|
|
29
|
-
/* 文本字体 */
|
|
30
|
-
'text-size': 10,
|
|
31
|
-
'text-offset': [0, 0], // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
|
|
32
|
-
// 'text-anchor': 'top',
|
|
33
|
-
'text-ignore-placement': false, // 是否忽略文本位置
|
|
34
|
-
'visibility': 'visible'
|
|
35
|
-
}, layout)
|
|
36
|
-
|
|
37
|
-
let paint = opt.text ? opt.text.paint : {}
|
|
38
|
-
let paintOpt = Object.assign({
|
|
39
|
-
'text-color': '#ffffff',
|
|
40
|
-
'text-halo-color': 'rgba(0, 0, 0, .5)',
|
|
41
|
-
'text-halo-width': 0.8,
|
|
42
|
-
'text-opacity': 1
|
|
43
|
-
}, paint)
|
|
44
|
-
|
|
45
|
-
map.addLayer({
|
|
46
|
-
id: id,
|
|
47
|
-
type: 'symbol',
|
|
48
|
-
source: opt.source || parentId,
|
|
49
|
-
layout: layoutOpt,
|
|
50
|
-
paint: paintOpt,
|
|
51
|
-
...opt.other
|
|
52
|
-
}, layerId)
|
|
1
|
+
import mapSdk from '../map'
|
|
2
|
+
import {
|
|
3
|
+
setSource,
|
|
4
|
+
hasLayer
|
|
5
|
+
} from './index'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 添加文字图层
|
|
9
|
+
*/
|
|
10
|
+
export const addLayerText = (placement = 'point', option, layerId) => { // 文本
|
|
11
|
+
let {
|
|
12
|
+
map
|
|
13
|
+
} = mapSdk
|
|
14
|
+
|
|
15
|
+
let opt = option
|
|
16
|
+
let parentId = opt.id
|
|
17
|
+
let id = parentId + '-text'
|
|
18
|
+
if (hasLayer(id)) {
|
|
19
|
+
setSource(id, opt.data)
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let layout = opt.text ? opt.text.layout : {}
|
|
24
|
+
let layoutOpt = Object.assign({
|
|
25
|
+
'symbol-placement': placement,
|
|
26
|
+
'text-field': '{name}',
|
|
27
|
+
/* 使用text标签显示的值,Feature属性使用{域名}格式*/
|
|
28
|
+
'text-font': ['Open Sans Semibold'],
|
|
29
|
+
/* 文本字体 */
|
|
30
|
+
'text-size': 10,
|
|
31
|
+
'text-offset': [0, 0], // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
|
|
32
|
+
// 'text-anchor': 'top',
|
|
33
|
+
'text-ignore-placement': false, // 是否忽略文本位置
|
|
34
|
+
'visibility': 'visible'
|
|
35
|
+
}, layout)
|
|
36
|
+
|
|
37
|
+
let paint = opt.text ? opt.text.paint : {}
|
|
38
|
+
let paintOpt = Object.assign({
|
|
39
|
+
'text-color': '#ffffff',
|
|
40
|
+
'text-halo-color': 'rgba(0, 0, 0, .5)',
|
|
41
|
+
'text-halo-width': 0.8,
|
|
42
|
+
'text-opacity': 1
|
|
43
|
+
}, paint)
|
|
44
|
+
|
|
45
|
+
map.addLayer({
|
|
46
|
+
id: id,
|
|
47
|
+
type: 'symbol',
|
|
48
|
+
source: opt.source || parentId,
|
|
49
|
+
layout: layoutOpt,
|
|
50
|
+
paint: paintOpt,
|
|
51
|
+
...opt.other
|
|
52
|
+
}, layerId)
|
|
53
53
|
}
|
package/src/map.js
CHANGED
|
@@ -25,7 +25,8 @@ var defaultOptions = {
|
|
|
25
25
|
'type': 'raster',
|
|
26
26
|
'tiles': [
|
|
27
27
|
'https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.jpg?access_token=pk.eyJ1IjoiaGo0NjI3NzEzOTYiLCJhIjoiY2w5YzNjOTZvMDF6NDNwb2d6YmJkYWRpMCJ9.-fW-OChGB1oY2DCMO_c8sg',
|
|
28
|
-
// 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
|
|
28
|
+
// 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
|
|
29
|
+
// 'https://map.ynmdgq.com/{z}/{x}/{y}.png'
|
|
29
30
|
],
|
|
30
31
|
'tileSize': 256
|
|
31
32
|
}
|
package/src/util/gaodeApi.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
|
|
3
|
-
// 获取浏览器定位
|
|
4
|
-
export function GeoAddress(lnglat) {
|
|
5
|
-
return new Promise((resolve) => {
|
|
6
|
-
axios.get(`https://restapi.amap.com/v3/geocode/regeo?key=39d46e3fcb4c9740d08e8ecb1f15ff8c&location=${lnglat[0]},${lnglat[1]}&extensions=all`).then(({
|
|
7
|
-
data
|
|
8
|
-
}) => {
|
|
9
|
-
if (data.status === '1') {
|
|
10
|
-
// result为对应的地理位置详细信息
|
|
11
|
-
let address = {
|
|
12
|
-
formattedAddress: data.regeocode.formatted_address,
|
|
13
|
-
...data.regeocode.addressComponent
|
|
14
|
-
}
|
|
15
|
-
// console.log(address)
|
|
16
|
-
resolve(address)
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// 获取浏览器定位
|
|
24
|
-
export function Geolocation() {
|
|
25
|
-
return new Promise((resolve) => {
|
|
26
|
-
// eslint-disable-next-line no-undef
|
|
27
|
-
new AMap.plugin('AMap.Geolocation', () => {
|
|
28
|
-
// eslint-disable-next-line no-undef
|
|
29
|
-
const geolocation = new AMap.Geolocation({
|
|
30
|
-
// 是否使用高精度定位,默认:true
|
|
31
|
-
enableHighAccuracy: true,
|
|
32
|
-
// 设置定位超时时间,默认:无穷大
|
|
33
|
-
timeout: 10000,
|
|
34
|
-
// 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
|
|
35
|
-
// eslint-disable-next-line no-undef
|
|
36
|
-
buttonOffset: new AMap.Pixel(10, 20),
|
|
37
|
-
// 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
|
|
38
|
-
zoomToAccuracy: true,
|
|
39
|
-
// 定位按钮的排放位置, RB表示右下
|
|
40
|
-
buttonPosition: 'RB'
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
geolocation.getCurrentPosition((status, result) => {
|
|
44
|
-
if (status === 'complete') {
|
|
45
|
-
onComplete(result)
|
|
46
|
-
} else {
|
|
47
|
-
onError(result)
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
function onComplete(data) {
|
|
52
|
-
// data是具体的定位信息
|
|
53
|
-
const info = {
|
|
54
|
-
lng: data.position.lng,
|
|
55
|
-
lat: data.position.lat,
|
|
56
|
-
formattedAddress: data.formattedAddress,
|
|
57
|
-
...data.addressComponent
|
|
58
|
-
}
|
|
59
|
-
resolve(info)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function onError(data) {
|
|
63
|
-
// 定位出错
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
})
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
|
|
3
|
+
// 获取浏览器定位
|
|
4
|
+
export function GeoAddress(lnglat) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
axios.get(`https://restapi.amap.com/v3/geocode/regeo?key=39d46e3fcb4c9740d08e8ecb1f15ff8c&location=${lnglat[0]},${lnglat[1]}&extensions=all`).then(({
|
|
7
|
+
data
|
|
8
|
+
}) => {
|
|
9
|
+
if (data.status === '1') {
|
|
10
|
+
// result为对应的地理位置详细信息
|
|
11
|
+
let address = {
|
|
12
|
+
formattedAddress: data.regeocode.formatted_address,
|
|
13
|
+
...data.regeocode.addressComponent
|
|
14
|
+
}
|
|
15
|
+
// console.log(address)
|
|
16
|
+
resolve(address)
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// 获取浏览器定位
|
|
24
|
+
export function Geolocation() {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
// eslint-disable-next-line no-undef
|
|
27
|
+
new AMap.plugin('AMap.Geolocation', () => {
|
|
28
|
+
// eslint-disable-next-line no-undef
|
|
29
|
+
const geolocation = new AMap.Geolocation({
|
|
30
|
+
// 是否使用高精度定位,默认:true
|
|
31
|
+
enableHighAccuracy: true,
|
|
32
|
+
// 设置定位超时时间,默认:无穷大
|
|
33
|
+
timeout: 10000,
|
|
34
|
+
// 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
|
|
35
|
+
// eslint-disable-next-line no-undef
|
|
36
|
+
buttonOffset: new AMap.Pixel(10, 20),
|
|
37
|
+
// 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
|
|
38
|
+
zoomToAccuracy: true,
|
|
39
|
+
// 定位按钮的排放位置, RB表示右下
|
|
40
|
+
buttonPosition: 'RB'
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
geolocation.getCurrentPosition((status, result) => {
|
|
44
|
+
if (status === 'complete') {
|
|
45
|
+
onComplete(result)
|
|
46
|
+
} else {
|
|
47
|
+
onError(result)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
function onComplete(data) {
|
|
52
|
+
// data是具体的定位信息
|
|
53
|
+
const info = {
|
|
54
|
+
lng: data.position.lng,
|
|
55
|
+
lat: data.position.lat,
|
|
56
|
+
formattedAddress: data.formattedAddress,
|
|
57
|
+
...data.addressComponent
|
|
58
|
+
}
|
|
59
|
+
resolve(info)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function onError(data) {
|
|
63
|
+
// 定位出错
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
67
|
}
|
package/vue.config.js
CHANGED
|
@@ -17,7 +17,8 @@ module.exports = defineConfig({
|
|
|
17
17
|
// proxyon为代理前缀,如果请求中包含该前缀,就走代理
|
|
18
18
|
'/api': {
|
|
19
19
|
// 真实的后端服务器地址
|
|
20
|
-
target: '
|
|
20
|
+
target: 'http://39.129.112.151:9091/api',
|
|
21
|
+
// target: 'https://www.ynmdgq.com/api',
|
|
21
22
|
ws: true,
|
|
22
23
|
// 控制请求头中的host
|
|
23
24
|
changeOrigin: true,
|
|
@@ -25,7 +26,7 @@ module.exports = defineConfig({
|
|
|
25
26
|
pathRewrite: {
|
|
26
27
|
'^/api': ''
|
|
27
28
|
}
|
|
28
|
-
}
|
|
29
|
+
}
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
})
|