Kaynağa Gözat

[Fix 0000] 地图销毁方法报错问题修复

houzekong 1 ay önce
ebeveyn
işleme
fe79c23f91
1 değiştirilmiş dosya ile 8 ekleme ve 4 silme
  1. 8 4
      src/layouts/default/feature/SimpleMap.vue

+ 8 - 4
src/layouts/default/feature/SimpleMap.vue

@@ -50,7 +50,7 @@
 
   // let svc = new vjmap.Service(env.serviceUrl, env.accessToken);
   // let app: vjmap3d.App;
-  let map: vjmap.Map;
+  let map: vjmap.Map | null;
   // 标记单位集合,用来为后续计算历史记录提供支持
   let markerCollection = [];
   // CAD是否可见
@@ -176,6 +176,7 @@
 
   /** 标记点点击事件处理,如果不是叶节点那么聚焦到下一级 */
   function markerClickHandler() {
+    if (!map) return;
     const node: any = last(historyStack.value);
     if (!node) return;
     if (node.isLeaf) return;
@@ -196,6 +197,7 @@
 
   /** 叶节点标记点击事件处理,叶节点需要显示该节点的详情框 */
   function laefNodeClickHandler(node: any) {
+    if (!map) return;
     if (!node) return;
     if (!node.isLeaf) return;
 
@@ -245,6 +247,7 @@
     cadOpened = visiable;
     mapLoading.value = true;
     map?.destory();
+    map = null;
 
     try {
       let markers;
@@ -294,7 +297,7 @@
   // 另一种方式是点击地图上的标记点,普通标点下钻到下一级,矿端标点不走watch的逻辑
   const { trigger } = watchTriggerable(
     () => mineStore.getDepartId,
-    async (id) => {
+    async () => {
       if (!mapContainer.value) return;
 
       // 如果是静默模式就简单展示默认地图/图纸即可
@@ -302,7 +305,7 @@
 
       // 先判断显示什么图纸,若是矿端显示CAD图纸
       if (mineStore.getDepart?.isLeaf) {
-        appStore.setSimpleMapParams({ deptId: id, isLeaf: true });
+        appStore.setSimpleMapParams({ deptId: mineStore.getDepartId, isLeaf: true });
 
         // 矿端需要先初始化图纸下拉框,下拉框触发一次change事件调用toggleCADMap,
         // 如果当前选项下没有已选中的地图,那么意味着需要新获取选项,否则无需发请求
@@ -314,7 +317,7 @@
       await toggleCADMap(mineStore.getDepart?.isLeaf || false);
 
       // 不论是不是矿端,历史记录都是一样的,用户点击返回上一级都能正常返回
-      historyStack.value = findPath(markerCollection, (n) => n.id === id) as any[];
+      historyStack.value = findPath(markerCollection, (n) => n.id === mineStore.getDepartId) as any[];
 
       // 此外如果是非矿端那么模拟触发地图点击事件
       markerClickHandler();
@@ -327,6 +330,7 @@
 
   onUnmounted(() => {
     map?.destory();
+    map = null;
   });
 </script>