| 
					
				 | 
			
			
				@@ -10,61 +10,96 @@ import { useRouter } from "vue-router"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import {unByKey} from "ol/Observable"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import Style from "ol/style/Style"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import Icon from "ol/style/Icon"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import {Cluster} from "ol/source"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import {Cluster, Vector as VectorSource} from "ol/source"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import {newPoint} from "../zhgl/map"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @description 地图层对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class SamplePointLayer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  constructor(map, farmId, regionId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  constructor(map, farm, region) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let that = this; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    this.farmId = farmId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    this.regionId = regionId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.farmId = farm.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.regionId = region.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let vectorStyle = new KMap.VectorStyle(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.vectorStyle = vectorStyle; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const clusterSource = new Cluster({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.clusterSource = new Cluster({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       distance: 15, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      // minDistance: 60, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      source: source, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      minDistance: 60, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.treeClusterLayer = new KMap.VectorLayer("tree-cluster",999,{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       minZoom:15, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      source:clusterSource, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      style:(feature)=> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        const size = feature.get('features').length; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // 只有一个数据,不需要聚合,直接使用第一项数据的图标 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let style = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (size == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          feature = feature.get('features')[0] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            style = new Style({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              image: new Icon({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                src: feature.get('imgSrc'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                scale:1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          return style 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return style; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      }}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      source:this.clusterSource, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      style:(f)=> this.getStyle(f)}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     map.addLayer(this.treeClusterLayer.layer) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.initData(this.farmId, this.regionId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  getIconStyle(feature){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let style = new Style({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      image: new Icon({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        src: feature.get('icon'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        scale:1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return style 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  //多点的过滤方法 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  manyFeatureFilter(features){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let res = features[0] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(features.length == 1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      return res 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for(let item of features){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      res = res.get('status') > item.get('status') ? res : item 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return res; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  //得到点样式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  getStyle(feature){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    feature = this.manyFeatureFilter(feature.get('features')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return this.getIconStyle(feature) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   initData(farmId, regionId){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let that = this 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     VE_API.sample.list({farmId,regionId}).then(({data})=>{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      let features = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      for(let item of data){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        that.getIcon(item) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let point = newPoint(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        features.push(point) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      const source = new VectorSource({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        features: features, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      that.clusterSource.setSource(source) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  getIcon(item){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let imgSrc = require('@/assets/status/status_xfdw.png') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(item.status == 1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      imgSrc = require('@/assets/status/status_dfh.png') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(item.status == 2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      imgSrc = require('@/assets/status/status_szyc.png') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(item.status == 3){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      imgSrc = require('@/assets/status/status_bcyc.png') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    item["icon"] = imgSrc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  reset(farm, region){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.clearCluster() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.initData(farm.id, region.id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // 清除聚合图层,解除绑定 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   clearCluster() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (this.treeClusterLayer) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       this.treeClusterLayer.layer.getSource().getSource().clear() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      this.treeClusterLayer = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      unByKey(this.listenKey) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |