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.
Files changed (3) hide show
  1. package/index.vue +8 -5
  2. package/js/basis.js +19 -0
  3. 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
- mouseController(map, props.mapId, {
243
- onRightClick: (position) => emit('rightClick', position),
244
- onLeftClick: (event) => emit('leftClick', event),
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.32",
3
+ "version": "1.2.33",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",