| | |
| | | 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); |
| | |
| | | |
| | | // 地图 |
| | | const initMap = () => { |
| | | if (!document.getElementById('spotMap')) { |
| | | return; |
| | | } |
| | | if (!document.getElementById('spotMap') || isMapReady.value) return; |
| | | |
| | | publicCesiumInstance = new PublicCesium({ |
| | | dom: 'spotMap', |
| | | flatMode: false, |
| | |
| | | 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; |
| | |
| | | }; |
| | | // 初始化所有图斑 |
| | | const entitiesAddSpot = () => { |
| | | if (!isMapReady.value || !viewer) return; |
| | | viewer?.entities.removeAll(); |
| | | tbJwdList = []; // 重置经纬度列表 |
| | | |
| | |
| | | |
| | | 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(); |
| | | }); |