From bfce3effc9a1ac61a0f2d65a6a02d4df62a170d6 Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Thu, 09 Oct 2025 10:34:12 +0800
Subject: [PATCH] feat:地图加载之后加载图斑

---
 src/views/resource/components/spotDetails.vue |   40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/views/resource/components/spotDetails.vue b/src/views/resource/components/spotDetails.vue
index 13bcdc7..28eb3a8 100644
--- a/src/views/resource/components/spotDetails.vue
+++ b/src/views/resource/components/spotDetails.vue
@@ -133,6 +133,8 @@
 import * as Cesium from 'cesium';
 import { PublicCesium } from '@/utils/cesium/publicCesium';
 import { ref, watch, onBeforeUnmount, onMounted } from 'vue';
+// 标记地图是否初始化完成
+const isMapReady = ref(false);
 const uploadPatchDialog = defineModel('show');
 const props = defineProps(['title', 'detailid', 'detailList', 'spotTypeOption', 'regionalData']);
 const polygonTableEle = ref(null);
@@ -266,9 +268,8 @@
 
 // 地图
 const initMap = () => {
-  if (!document.getElementById('spotMap')) {
-    return;
-  }
+  if (!document.getElementById('spotMap') || isMapReady.value) return;
+  
   publicCesiumInstance = new PublicCesium({
     dom: 'spotMap',
     flatMode: false,
@@ -276,12 +277,33 @@
     layerMode: 4,
     contour: false,
   });
+  
   homeViewer.value = publicCesiumInstance.getViewer();
   viewer = publicCesiumInstance.getViewer();
-  viewInstance.value = publicCesiumInstance;
+  viewInstance.value = publicCesiumInstance; 
   viewer.scene.globe.depthTestAgainstTerrain = true;
   viewInstance.value.switchContour(true);
+
+  // 确保 readyPromise 存在
+  if (viewer.readyPromise) {
+    viewer.readyPromise.then(() => {
+      isMapReady.value = true; 
+      getTableList();
+    }).catch((error) => {
+      console.error('地图加载失败:', error);
+      ElMessage.error('地图加载失败,请刷新重试');
+    });
+  } else {
+
+    // 如果没有 readyPromise
+    setTimeout(() => {
+      isMapReady.value = true;
+      getTableList();
+    }, 1000);
+  }
 };
+
+
 // 仅弹框初始化时执行的定位逻辑
 const initMapLocation = () => {
   if (tbJwdList.length === 0 || !homeViewer.value) return;
@@ -303,6 +325,7 @@
 };
 // 初始化所有图斑
 const entitiesAddSpot = () => {
+if (!isMapReady.value || !viewer) return;
   viewer?.entities.removeAll();
   tbJwdList = []; // 重置经纬度列表
   
@@ -594,20 +617,21 @@
 
 watch(uploadPatchDialog, newVal => {
   if (newVal) {
-
     isInit.value = true; 
+    isMapReady.value = false; 
     setTimeout(() => {
       initMap();      
-      getTableList();  
-      getspotManagementTableApi();
+      getspotManagementTableApi(); 
     }, 0);
   } else {
- tableData.value = []; 
+ 
+    tableData.value = []; 
     isEditing.value = false;
     handleUpDateDrawState(false);
     destroyMap();
     isInit.value = false; 
     clearSelect();
+    isMapReady.value = false; 
   }
   refreshonload();
 });

--
Gitblit v1.9.3