huweili-cesium 1.2.32 → 1.2.33
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/index.vue +8 -5
- package/js/basis.js +19 -0
- package/package.json +1 -1
package/index.vue
CHANGED
|
@@ -18,7 +18,7 @@ import { processMapConfigColors } from './js/tileProviders.js'
|
|
|
18
18
|
import { applyImageryLayers, resolveOnlineBasemap } from './js/utils/mapImagery.js'
|
|
19
19
|
import { createCustomToolbarButtons } from './js/customToolbarButtons.js'
|
|
20
20
|
const { merge } = objectUtils()
|
|
21
|
-
const { mouseController, setInitialCameraView, syncCameraInteractionMode } = basicConfig()
|
|
21
|
+
const { mouseController, setInitialCameraView, syncCameraInteractionMode, waitForMapReady } = basicConfig()
|
|
22
22
|
const {
|
|
23
23
|
addToolbarButton,
|
|
24
24
|
addToolbarButtons,
|
|
@@ -239,10 +239,13 @@ const initCesium = async () => {
|
|
|
239
239
|
})
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
const readyMap = await waitForMapReady(props.mapId)
|
|
243
|
+
if (readyMap) {
|
|
244
|
+
mouseController(readyMap, props.mapId, {
|
|
245
|
+
onRightClick: (position) => emit('rightClick', position),
|
|
246
|
+
onLeftClick: (event) => emit('leftClick', event),
|
|
247
|
+
}) // 初始化鼠标控制器
|
|
248
|
+
}
|
|
246
249
|
|
|
247
250
|
mapStore.setMapInfo(
|
|
248
251
|
'center',
|
package/js/basis.js
CHANGED
|
@@ -21,6 +21,24 @@ export function basicConfig() {
|
|
|
21
21
|
// 获取地图store实例
|
|
22
22
|
const mapStore = useMapStore()
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* 等待地图实例初始化完成
|
|
26
|
+
* @param {string} mapInstanceId 地图实例ID
|
|
27
|
+
* @param {number} maxRetry 最大重试次数
|
|
28
|
+
* @param {number} interval 每次重试间隔,单位毫秒
|
|
29
|
+
* @returns {Promise<Cesium.Viewer|null>} 地图实例或 null
|
|
30
|
+
*/
|
|
31
|
+
const waitForMapReady = async (mapInstanceId, maxRetry = 20, interval = 50) => {
|
|
32
|
+
for (let i = 0; i < maxRetry; i += 1) {
|
|
33
|
+
const map = mapStore.getMap(mapInstanceId)
|
|
34
|
+
if (map?.scene && map?.camera) {
|
|
35
|
+
return map
|
|
36
|
+
}
|
|
37
|
+
await new Promise((resolve) => setTimeout(resolve, interval))
|
|
38
|
+
}
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
|
|
24
42
|
/**
|
|
25
43
|
* 检查坐标是否在中国境内
|
|
26
44
|
* @param {*} longitude - 经度
|
|
@@ -741,6 +759,7 @@ export function basicConfig() {
|
|
|
741
759
|
}
|
|
742
760
|
|
|
743
761
|
return {
|
|
762
|
+
waitForMapReady,
|
|
744
763
|
isInChina,
|
|
745
764
|
mouseController,
|
|
746
765
|
setCesiumCenter,
|