Quellcode durchsuchen

fix: 修复多次切换地图相关菜单时的错误

sequoia tungfang vor 1 Monat
Ursprung
Commit
48dd8939db
1 geänderte Dateien mit 5 neuen und 1 gelöschten Zeilen
  1. 5 1
      src/components/TongzhouTrafficMap.vue

+ 5 - 1
src/components/TongzhouTrafficMap.vue

@@ -159,6 +159,9 @@ export default {
       // 关闭信息窗口
       if (this.infoWindow) this.infoWindow.close();
       
+      // 确保地图已初始化
+      if (!this.map) return;
+      
       // 根据activeLegends数组更新地图上路线和标记的显示/隐藏状态
       Object.keys(this.routeGroups).forEach(name => {
         const overlays = this.routeGroups[name];
@@ -265,7 +268,8 @@ export default {
             const overlays = [...markers, polyline].filter(Boolean);
             this.routeGroups[config.name] = overlays;
 
-            if (this.activeLegends.includes(config.name)) {
+            // 确保地图已初始化
+            if (this.map && this.activeLegends.includes(config.name)) {
               this.map.add(overlays);
             }
           });