Browse Source

fix:修复地图没有加载完成就添加图层导致报错问题

yangqishu 4 months atrás
parent
commit
83269e3a12
2 changed files with 18 additions and 14 deletions
  1. 4 3
      src/views/components/layerList/index.vue
  2. 14 11
      src/views/index.vue

+ 4 - 3
src/views/components/layerList/index.vue

@@ -78,12 +78,12 @@ export default {
           ]
         }
       ],
-      mainMenu:''
+      mainMenu: ''
     }
   },
-    created(){
+  created() {
     this.mainMenu = this.$route.params.menu
-  },  
+  },
   mounted() {
     this.$globalEventBus.$on('toggleLeftPanel', (val) => {
       this.leftPanelHide = val
@@ -128,6 +128,7 @@ export default {
             clampToGround: true,
             symbol: this.getStyleByName(node.label)
           })
+          console.log(window.map, 111111111)
           window.map.addLayer(layer)
           this.bindEvent(layer)
           layerCache[id] = layer

+ 14 - 11
src/views/index.vue

@@ -9,15 +9,15 @@
           <keep-alive>
             <MainMap :mapKey="mapName" :url="configUrl" :options="mapOptions" @onload="onMapload" />
           </keep-alive>
-          <LayerListPanel></LayerListPanel>
-          <SandMonitorLeft v-if="this.mainMenu === 'sandMonitor'"></SandMonitorLeft>
-          <SandMonitorRight v-if="this.mainMenu === 'sandMonitor'"></SandMonitorRight>
-          <SafetyInspectionLeft v-if="this.mainMenu === 'safetyInspection'"></SafetyInspectionLeft>
-          <SafetyInspectionRight v-if="this.mainMenu === 'safetyInspection'"></SafetyInspectionRight>
+          <LayerListPanel v-if="mapLoaded"></LayerListPanel>
+          <SandMonitorLeft v-if="mainMenu === 'sandMonitor'"></SandMonitorLeft>
+          <SandMonitorRight v-if="mainMenu === 'sandMonitor'"></SandMonitorRight>
+          <SafetyInspectionLeft v-if="mainMenu === 'safetyInspection'"></SafetyInspectionLeft>
+          <SafetyInspectionRight v-if="mainMenu === 'safetyInspection'"></SafetyInspectionRight>
           <AddInspectionTask />
-          <ComprehensiveOverview v-if="this.mainMenu === 'comprehensiveOverview'"></ComprehensiveOverview>
-          <HydrologicInfo v-if="this.mainMenu === 'hydrologicInfo'"></HydrologicInfo>
-          <SmartEarlyWarning v-if="this.mainMenu === 'smartEarlyWarning'" />
+          <ComprehensiveOverview v-if="mainMenu === 'comprehensiveOverview'"></ComprehensiveOverview>
+          <HydrologicInfo v-if="mainMenu === 'hydrologicInfo'"></HydrologicInfo>
+          <SmartEarlyWarning v-if="mainMenu === 'smartEarlyWarning'" />
           <WaterStationPopup />
         </div>
       </el-main>
@@ -83,16 +83,19 @@ export default {
           }
         ]
       },
-      mainMenu:'',
+      mapLoaded: false,
+      mainMenu: ''
     }
   },
-  created(){
+  created() {
     this.mainMenu = this.$route.params.menu
+    this.mapLoaded = false
   },
   methods: {
     // 地图加载回调优化
     async onMapload(map) {
       window.map = map
+      this.mapLoaded = true
       map.hasTerrain = true
       this.addWaterSurface(map)
     },
@@ -146,4 +149,4 @@ export default {
   height: 100%;
   box-sizing: border-box;
 }
-</style>
+</style>