|
|
@@ -1,9 +1,11 @@
|
|
|
import * as KMap from '@/utils/ol-map/KMap';
|
|
|
import Style from "ol/style/Style";
|
|
|
import Icon from "ol/style/Icon";
|
|
|
+import { Cluster, Vector as VectorSource } from "ol/source.js";
|
|
|
+import { Circle, Fill, Stroke, Text } from "ol/style.js";
|
|
|
import { newPoint } from "@/utils/map.js";
|
|
|
import flyPointIcon from "@/assets/images/warningHome/chat/fly-point.png";
|
|
|
-import activePointIcon from "@/assets/images/map/active-icon-small.png";
|
|
|
+import activePointIcon from "@/assets/images/map/poing-icon.png";
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -11,6 +13,17 @@ import activePointIcon from "@/assets/images/map/active-icon-small.png";
|
|
|
class pointLayer {
|
|
|
constructor(kmap) {
|
|
|
this.kmap = kmap
|
|
|
+
|
|
|
+ // 创建原始点位数据源
|
|
|
+ this.imgSource = new VectorSource({});
|
|
|
+
|
|
|
+ // 创建聚合数据源
|
|
|
+ this.clusterSource = new Cluster({
|
|
|
+ distance: 80, // 聚合距离(像素)
|
|
|
+ minDistance: 50, // 最小聚合距离
|
|
|
+ source: this.imgSource,
|
|
|
+ });
|
|
|
+
|
|
|
// 位置图标
|
|
|
this.pointLayer = new KMap.VectorLayer("pointLayer", 1000, {
|
|
|
visible: false,
|
|
|
@@ -26,14 +39,16 @@ class pointLayer {
|
|
|
});
|
|
|
this.kmap.addLayer(this.pointLayer.layer);
|
|
|
|
|
|
+ // 使用聚合数据源的图层
|
|
|
this.imgLayer = new KMap.VectorLayer("imgLayer", 1000, {
|
|
|
visible: false,
|
|
|
+ source: this.clusterSource,
|
|
|
style: () => {
|
|
|
return new Style({
|
|
|
image: new Icon({
|
|
|
- // 使用打包器可识别的静态资源路径
|
|
|
src: activePointIcon,
|
|
|
scale: 0.7,
|
|
|
+ anchor: [0.5, 0.5],
|
|
|
}),
|
|
|
});
|
|
|
},
|
|
|
@@ -137,10 +152,21 @@ class pointLayer {
|
|
|
}
|
|
|
|
|
|
showImg(arr) {
|
|
|
+ // 先清空之前的数据
|
|
|
+ this.imgSource.clear();
|
|
|
+
|
|
|
+ // 将数据添加到原始数据源
|
|
|
arr.map((item) => {
|
|
|
let point = newPoint(item, 'centerPoint');
|
|
|
- this.imgLayer.addFeature(point)
|
|
|
- })
|
|
|
+ // 保留原始数据属性
|
|
|
+ if(item.imageUrl) point.set('imageUrl', item.imageUrl);
|
|
|
+ if(item.id) point.set('id', item.id);
|
|
|
+ if(item.url) point.set('url', item.url);
|
|
|
+
|
|
|
+ this.imgSource.addFeature(point);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 显示图层
|
|
|
this.imgLayer.layer.setVisible(true);
|
|
|
this.pointLayer.layer.setVisible(false);
|
|
|
}
|
|
|
@@ -148,6 +174,8 @@ class pointLayer {
|
|
|
hidePoint() {
|
|
|
this.pointLayer.layer.setVisible(false);
|
|
|
this.imgLayer.layer.setVisible(false);
|
|
|
+ // 清空聚合数据源
|
|
|
+ this.imgSource.clear();
|
|
|
}
|
|
|
|
|
|
}
|