|
|
@@ -26,6 +26,7 @@ class DistributionLayer {
|
|
|
style: function (f) {
|
|
|
const label = f.get("label") || "";
|
|
|
const baseColor = f.get("color") || "#2199F8";
|
|
|
+ const farmName = f.get("farmName") || "";
|
|
|
const imgUrl = f.get("imgUrl") || "";
|
|
|
const imgName = f.get("imgName") || "";
|
|
|
|
|
|
@@ -67,6 +68,25 @@ class DistributionLayer {
|
|
|
padding: [2, 14, 2, 14],
|
|
|
}),
|
|
|
});
|
|
|
+
|
|
|
+ // 农场名称(显示在点位下方,白色文字)
|
|
|
+ const farmNameStyle = farmName
|
|
|
+ ? new Style({
|
|
|
+ text: new Text({
|
|
|
+ text: farmName,
|
|
|
+ font: "normal 19px sans-serif",
|
|
|
+ offsetY: 45, // 向下偏移,位于点位下方
|
|
|
+ textAlign: "center",
|
|
|
+ fill: new Fill({
|
|
|
+ color: "#FFFFFF",
|
|
|
+ }),
|
|
|
+ stroke: new Stroke({
|
|
|
+ color: "rgba(0,0,0,0.6)",
|
|
|
+ width: 2,
|
|
|
+ }),
|
|
|
+ }),
|
|
|
+ })
|
|
|
+ : null;
|
|
|
const typeImgStyle = new Style({
|
|
|
// image: new Photo({
|
|
|
// // src: imgUrl,
|
|
|
@@ -84,17 +104,31 @@ class DistributionLayer {
|
|
|
}),
|
|
|
});
|
|
|
|
|
|
- // 先画纯色方块,再画白色描边 PNG 和文字
|
|
|
- return [squareBgStyle, iconAndTextStyle, typeImgStyle];
|
|
|
+ // 先画纯色方块,再画白色描边 PNG 和文字,最后画农场名称
|
|
|
+ const styles = [squareBgStyle, iconAndTextStyle, typeImgStyle];
|
|
|
+ if (farmNameStyle) styles.push(farmNameStyle);
|
|
|
+ return styles;
|
|
|
},
|
|
|
});
|
|
|
this.kmap.addLayer(this.distributionPointLayer.layer)
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 清空当前图层上的所有数据
|
|
|
+ */
|
|
|
+ clear() {
|
|
|
+ if (this.distributionLayer && this.distributionLayer.source) {
|
|
|
+ this.distributionLayer.source.clear();
|
|
|
+ }
|
|
|
+ if (this.distributionPointLayer && this.distributionPointLayer.source) {
|
|
|
+ this.distributionPointLayer.source.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
initData(data) {
|
|
|
- let that = this;
|
|
|
- that.distributionLayer.source.clear();
|
|
|
- that.distributionPointLayer.source.clear();
|
|
|
+ let that = this;
|
|
|
+ // 每次加载前先清空旧数据
|
|
|
+ this.clear();
|
|
|
for (let item of data) {
|
|
|
if (item.geom) {
|
|
|
const f = new Feature({
|
|
|
@@ -114,6 +148,10 @@ class DistributionLayer {
|
|
|
f.set("imgName", item.imgName);
|
|
|
f.set("label", item.label);
|
|
|
f.set("color", item.color);
|
|
|
+ // 农场名称,用于点位下方显示
|
|
|
+ if (item.farmName) {
|
|
|
+ f.set("farmName", item.farmName);
|
|
|
+ }
|
|
|
this.distributionPointLayer.source.addFeature(f);
|
|
|
}
|
|
|
}
|