无人机管理后台前端(已迁走)
张含笑
2025-10-09 bfce3effc9a1ac61a0f2d65a6a02d4df62a170d6
feat:地图加载之后加载图斑
1 files modified
40 ■■■■ changed files
src/views/resource/components/spotDetails.vue 40 ●●●● patch | view | raw | blame | history
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();
});