Browse Source

fix: 修复地图切换图例刷新的问题

TwoKe945 1 year ago
parent
commit
5aac0892b2
1 changed files with 19 additions and 3 deletions
  1. 19 3
      app/src/components/Map.vue

+ 19 - 3
app/src/components/Map.vue

@@ -184,6 +184,16 @@ export default {
       },
       showType: ["currentJzKey"],
       loading: false,
+      markerCache: {
+        "xfscKey": [],
+        "trsyKey": [],
+        "xhsKey": [],
+        "szxhsKey": [],
+        "jzKey": [],
+        "xfzKey": [],
+        "jgKey": [],
+        "xfcKey": []
+      }
     };
   },
   props: {
@@ -222,12 +232,16 @@ export default {
       let showType = JSON.parse(JSON.stringify(this.showType));
       if (showType.indexOf(type) >= 0) {
         showType = showType.filter((p) => p !== type);
+        this.markerCache[type].forEach(marker => {
+          this.map.remove(marker)
+        })
       } else {
         showType.push(type);
+        this.markerCache[type].forEach(marker => {
+          this.map.add(marker)
+        })
       }
-
       this.showType = showType;
-      this.getData();
     },
     async getData() {
       if (this.loading) {
@@ -365,6 +379,8 @@ export default {
                 offset: new AMap.Pixel(0, -70),
               });
 
+
+
               marker.on("mouseover", (e) => {
                 infoWindow.open(this.map, p.position); //后面的参数指的是经纬度,在此显示窗口
               });
@@ -372,7 +388,7 @@ export default {
               marker.on("mouseout", (e) => {
                 infoWindow.close();
               });
-
+              this.markerCache[type].push(marker)
               markers.push(marker);
             });
             this.map.add(markers);