|
|
@@ -47,8 +47,6 @@ const containerRef = ref(null)
|
|
47
|
47
|
|
|
48
|
48
|
let map = null
|
|
49
|
49
|
let cmmapglRef = null
|
|
50
|
|
-let zoomLogTimer = null
|
|
51
|
|
-let lastMouseZoomLogAt = 0
|
|
52
|
50
|
let clampingZoom = false
|
|
53
|
51
|
let unbindWheelZoom = null
|
|
54
|
52
|
|
|
|
@@ -61,62 +59,30 @@ let wheelDebounceTimer = null
|
|
61
|
59
|
let lastWheelAround = null
|
|
62
|
60
|
let poiMarkers = []
|
|
63
|
61
|
|
|
64
|
|
-function formatLngLat(lngLat) {
|
|
|
62
|
+function logClickCoordinate(lngLat) {
|
|
65
|
63
|
if (!lngLat) {
|
|
66
|
|
- return '—'
|
|
|
64
|
+ return
|
|
67
|
65
|
}
|
|
68
|
66
|
const lng = Number(lngLat.lng ?? lngLat[0])
|
|
69
|
67
|
const lat = Number(lngLat.lat ?? lngLat[1])
|
|
70
|
68
|
if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
|
|
71
|
|
- return '—'
|
|
72
|
|
- }
|
|
73
|
|
- return `[${lng.toFixed(6)}, ${lat.toFixed(6)}]`
|
|
74
|
|
-}
|
|
75
|
|
-
|
|
76
|
|
-function logMapState(source, cursorLngLat) {
|
|
77
|
|
- if (!map || typeof map.getZoom !== 'function') {
|
|
78
|
69
|
return
|
|
79
|
70
|
}
|
|
80
|
|
- const z = map.getZoom()
|
|
81
|
|
- const zoomText = Number.isFinite(z) ? z.toFixed(2) : String(z)
|
|
82
|
|
- const center = typeof map.getCenter === 'function' ? map.getCenter() : null
|
|
83
|
|
- const parts = [
|
|
84
|
|
- `[GIS] ${source}`,
|
|
85
|
|
- `zoom: ${zoomText}`,
|
|
86
|
|
- `center: ${formatLngLat(center)}`
|
|
87
|
|
- ]
|
|
88
|
|
- if (cursorLngLat) {
|
|
89
|
|
- parts.push(`point: ${formatLngLat(cursorLngLat)}`)
|
|
90
|
|
- }
|
|
91
|
|
- console.log(parts.join(' | '))
|
|
|
71
|
+ console.log(
|
|
|
72
|
+ `[GIS] click | lng: ${lng.toFixed(6)}, lat: ${lat.toFixed(6)} | [${lng.toFixed(6)}, ${lat.toFixed(6)}]`
|
|
|
73
|
+ )
|
|
92
|
74
|
}
|
|
93
|
75
|
|
|
94
|
|
-function bindZoomDebugListeners() {
|
|
|
76
|
+function bindMapListeners() {
|
|
95
|
77
|
if (!map) {
|
|
96
|
78
|
return
|
|
97
|
79
|
}
|
|
98
|
|
- map.on('load', () => logMapState('load'))
|
|
99
|
80
|
map.on('zoomend', () => {
|
|
100
|
81
|
snapZoomToLimits()
|
|
101
|
|
- logMapState('zoomend')
|
|
102
|
|
- })
|
|
103
|
|
- map.on('moveend', () => logMapState('moveend'))
|
|
104
|
|
- map.on('wheel', () => {
|
|
105
|
|
- if (zoomLogTimer) {
|
|
106
|
|
- clearTimeout(zoomLogTimer)
|
|
107
|
|
- }
|
|
108
|
|
- zoomLogTimer = setTimeout(() => logMapState('wheel'), 80)
|
|
109
|
|
- })
|
|
110
|
|
- map.on('mousemove', (e) => {
|
|
111
|
|
- const now = Date.now()
|
|
112
|
|
- if (now - lastMouseZoomLogAt < 300) {
|
|
113
|
|
- return
|
|
114
|
|
- }
|
|
115
|
|
- lastMouseZoomLogAt = now
|
|
116
|
|
- logMapState('mousemove', e.lngLat)
|
|
117
|
82
|
})
|
|
118
|
83
|
map.on('click', (e) => {
|
|
119
|
|
- logMapState('click', e.lngLat)
|
|
|
84
|
+ logClickCoordinate(e.lngLat)
|
|
|
85
|
+ emit('click', e)
|
|
120
|
86
|
})
|
|
121
|
87
|
}
|
|
122
|
88
|
|
|
|
@@ -172,20 +138,16 @@ function createPoiMarkerElement(name) {
|
|
172
|
138
|
return wrap
|
|
173
|
139
|
}
|
|
174
|
140
|
|
|
175
|
|
-async function renderNearbyPoiMarkers() {
|
|
|
141
|
+async function renderPoiMarkers() {
|
|
176
|
142
|
if (!props.showPoiMarkers || !map || !cmmapglRef) {
|
|
177
|
143
|
return
|
|
178
|
144
|
}
|
|
179
|
145
|
clearPoiMarkers()
|
|
180
|
146
|
|
|
181
|
|
- const center = resolveCenter()
|
|
182
|
147
|
let pois = []
|
|
183
|
148
|
try {
|
|
184
|
149
|
pois = await searchNearbyPois({
|
|
185
|
|
- center,
|
|
186
|
|
- radius: 5000,
|
|
187
|
|
- pageSize: 50,
|
|
188
|
|
- pageNum: 1
|
|
|
150
|
+ center: resolveCenter()
|
|
189
|
151
|
})
|
|
190
|
152
|
} catch {
|
|
191
|
153
|
return
|
|
|
@@ -220,17 +182,12 @@ async function renderNearbyPoiMarkers() {
|
|
220
|
182
|
}
|
|
221
|
183
|
|
|
222
|
184
|
function destroyMap() {
|
|
223
|
|
- if (zoomLogTimer) {
|
|
224
|
|
- clearTimeout(zoomLogTimer)
|
|
225
|
|
- zoomLogTimer = null
|
|
226
|
|
- }
|
|
227
|
185
|
if (typeof unbindWheelZoom === 'function') {
|
|
228
|
186
|
unbindWheelZoom()
|
|
229
|
187
|
unbindWheelZoom = null
|
|
230
|
188
|
}
|
|
231
|
189
|
wheelDeltaAccum = 0
|
|
232
|
190
|
lastWheelAround = null
|
|
233
|
|
- lastMouseZoomLogAt = 0
|
|
234
|
191
|
clampingZoom = false
|
|
235
|
192
|
clearPoiMarkers()
|
|
236
|
193
|
if (map) {
|
|
|
@@ -461,7 +418,7 @@ async function initMap() {
|
|
461
|
418
|
if (props.showScale) {
|
|
462
|
419
|
map.addControl(new cmmapgl.ScaleControl({ unit: 'metric' }), 'bottom-left')
|
|
463
|
420
|
}
|
|
464
|
|
- bindZoomDebugListeners()
|
|
|
421
|
+ bindMapListeners()
|
|
465
|
422
|
bindZoomClampListener()
|
|
466
|
423
|
unbindWheelZoom = bindDebouncedWheelZoom()
|
|
467
|
424
|
configureScrollZoom()
|
|
|
@@ -470,10 +427,9 @@ async function initMap() {
|
|
470
|
427
|
configureScrollZoom()
|
|
471
|
428
|
snapZoomToLimits()
|
|
472
|
429
|
resizeMap()
|
|
473
|
|
- renderNearbyPoiMarkers()
|
|
|
430
|
+ renderPoiMarkers()
|
|
474
|
431
|
emit('ready', map)
|
|
475
|
432
|
})
|
|
476
|
|
- map.on('click', (e) => emit('click', e))
|
|
477
|
433
|
// 瓦片/遥测等非致命错误不向页面报错
|
|
478
|
434
|
map.on('error', () => {})
|
|
479
|
435
|
} catch {
|
|
|
@@ -490,7 +446,7 @@ watch(
|
|
490
|
446
|
zoom: resolveZoom()
|
|
491
|
447
|
})
|
|
492
|
448
|
if (props.showPoiMarkers) {
|
|
493
|
|
- renderNearbyPoiMarkers()
|
|
|
449
|
+ renderPoiMarkers()
|
|
494
|
450
|
}
|
|
495
|
451
|
},
|
|
496
|
452
|
{ deep: true }
|
|
|
@@ -501,7 +457,7 @@ watch(
|
|
501
|
457
|
(show) => {
|
|
502
|
458
|
if (!map || !cmmapglRef) return
|
|
503
|
459
|
if (show) {
|
|
504
|
|
- renderNearbyPoiMarkers()
|
|
|
460
|
+ renderPoiMarkers()
|
|
505
|
461
|
} else {
|
|
506
|
462
|
clearPoiMarkers()
|
|
507
|
463
|
}
|