Browse Source

fix: 修复loadFeatures问题

刘秀芳 8 months ago
parent
commit
9b96734032
1 changed files with 9 additions and 26 deletions
  1. 9 26
      src/views/home/map/samplePointLayer.js

+ 9 - 26
src/views/home/map/samplePointLayer.js

@@ -42,28 +42,7 @@ class SamplePointLayer {
       source: this.clusterSource,
       style: (f) => this.getStyle(f)
     })
-    this.yellowBlockLayer = new KMap.VectorLayer("yellow-block", 999, {
-      minZoom: 15,
-      // source:this.clusterSource,
-      // source:"POINT(113.61396985128522 23.5859386716038)",
-      style: () => {
-        return new Style({
-          image: new Icon({
-            src: require("@/assets/images/map/yellow-block.png"),
-            scale: 0.4,
-          }),
-        });
-      },
-    })
-    map.addLayer(this.treeClusterLayer.layer)
-    // map.addLayer(this.yellowBlockLayer.layer);
-
-    let point = new Feature(new Point([113.61396985128522, 23.5859386716038]));
-    let point1 = new Feature(new Point([113.61390710255375, 23.586379215663726]));
-    let point2 = new Feature(new Point([113.61491218688275, 23.58671519555776]));
-    // this.yellowBlockLayer.addFeature(point);
-    // this.yellowBlockLayer.addFeature(point1);
-    // this.yellowBlockLayer.addFeature(point2);
+    // map.addLayer(this.treeClusterLayer.layer)
 
     this.addMapSingerClick(map.map);
 
@@ -171,6 +150,14 @@ class SamplePointLayer {
         features: features,
       });
       that.clusterSource.setSource(source)
+
+      
+      const layers = that.mapRef.map.getLayers().getArray();
+      const exists = layers.includes(that.treeClusterLayer.layer);
+
+      if (!exists) {
+        that.mapRef.addLayer(that.treeClusterLayer.layer);
+      }
       setTimeout(() => {
         that.mapRef.fit(that.clusterSource.source.getExtent(), { padding: [100, 100, 100, 100] })
       }, 100)
@@ -404,10 +391,6 @@ class SamplePointLayer {
             eventBus.emit("clickToCompare:point", that.comparePointArr)
           }
         }
-        if (layer instanceof VectorLayer && layer.get("name") === "yellow-block") {
-          hasFeature = true
-          eventBus.emit("click:yellowBlock", feature.get("geometry").flatCoordinates[0])
-        }
       })
       if (!hasFeature) {
         kmap.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {