|
|
@@ -11,29 +11,32 @@ class WaterLayer {
|
|
|
this.vectorStyle = new KMap.VectorStyle();
|
|
|
// 河流动画相位
|
|
|
this.riverAnimationPhase = 0;
|
|
|
+ // 图例配置(用于控制不同水利图层颜色)
|
|
|
+ this.legend = [];
|
|
|
|
|
|
this.waterLayer = new KMap.VectorLayer("waterLayer", 99, {
|
|
|
style: (f) => {
|
|
|
- const style = that.vectorStyle.getPolygonStyle("#00000010", "#ffffffcc", 3)
|
|
|
- // const style2 = that.vectorStyle.getPointTextStyle(f.get('name'), "#000000", "#ffffff", 0, 22)
|
|
|
+ const strokeColor = that.getLayerColor("water");
|
|
|
+ const style = that.vectorStyle.getPolygonStyle("#00000010", strokeColor, 3);
|
|
|
return [style]
|
|
|
}
|
|
|
});
|
|
|
|
|
|
this.riverLayer = new KMap.VectorLayer("riverLayer", 99, {
|
|
|
style: (f) => {
|
|
|
- // 简单“呼吸”动画效果:通过 stroke 透明度和宽度轻微变化
|
|
|
+ // 简单“呼吸”动画效果:通过线宽轻微变化
|
|
|
const phase = that.riverAnimationPhase || 0;
|
|
|
- const alpha = 0.4 + 0.3 * Math.sin(phase);
|
|
|
const strokeWidth = 2 + 1.5 * (0.5 + 0.5 * Math.sin(phase));
|
|
|
- const strokeColor = `rgba(66, 184, 132, ${alpha.toFixed(2)})`;
|
|
|
+ const strokeColor = that.getLayerColor("river");
|
|
|
return that.vectorStyle.getPolygonStyle("rgba(0,0,0,0)", strokeColor, strokeWidth);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
this.canalLayer = new KMap.VectorLayer("canalLayer", 99, {
|
|
|
style: (f) => {
|
|
|
- return that.vectorStyle.getPolygonStyle("#00000010", "#42b884cc", 3)
|
|
|
+ const strokeColor = that.getLayerColor("canal");
|
|
|
+ console.log('strokeColor', strokeColor);
|
|
|
+ return that.vectorStyle.getPolygonStyle("#00000010", strokeColor, 3)
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -52,6 +55,26 @@ class WaterLayer {
|
|
|
}, 80);
|
|
|
}
|
|
|
|
|
|
+ // 根据当前图例配置获取不同图层的颜色
|
|
|
+ getLayerColor(type) {
|
|
|
+ const list = this.legend || [];
|
|
|
+ // 约定:水域 / 河流 / 水渠 分别对应图例数组的第 1、2、3 项
|
|
|
+ if (type === "water") {
|
|
|
+ return (list[0] && list[0].color) || "#ffffffcc";
|
|
|
+ }
|
|
|
+ if (type === "river") {
|
|
|
+ return (list[1] && list[1].color) || "#42b884cc";
|
|
|
+ }
|
|
|
+ if (type === "canal") {
|
|
|
+ // 如果有灌渠与泵站专用颜色,则优先生效
|
|
|
+ if (this.canalColorOverride) {
|
|
|
+ return this.canalColorOverride;
|
|
|
+ }
|
|
|
+ return (list[2] && list[2].color) || "#42b884cc";
|
|
|
+ }
|
|
|
+ return "#42b884cc";
|
|
|
+ }
|
|
|
+
|
|
|
initData(arr) {
|
|
|
if (this.waterLayer) {
|
|
|
this.waterLayer.source.clear();
|
|
|
@@ -88,6 +111,30 @@ class WaterLayer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 设置图例数据,从外部注入颜色配置
|
|
|
+ setLegend(list) {
|
|
|
+ this.legend = Array.isArray(list) ? list : [];
|
|
|
+ // 图例变化后触发三层重绘
|
|
|
+ if (this.waterLayer && this.waterLayer.layer) {
|
|
|
+ this.waterLayer.layer.changed && this.waterLayer.layer.changed();
|
|
|
+ }
|
|
|
+ if (this.riverLayer && this.riverLayer.layer) {
|
|
|
+ this.riverLayer.layer.changed && this.riverLayer.layer.changed();
|
|
|
+ }
|
|
|
+ if (this.canalLayer && this.canalLayer.layer) {
|
|
|
+ this.canalLayer.layer.changed && this.canalLayer.layer.changed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置“灌渠与泵站”图例颜色(facility 图例),只影响灌渠图层颜色
|
|
|
+ setCanalLegend(list) {
|
|
|
+ const arr = Array.isArray(list) ? list : [];
|
|
|
+ this.canalColorOverride = (arr[0] && arr[0].color) || null;
|
|
|
+ if (this.canalLayer && this.canalLayer.layer) {
|
|
|
+ this.canalLayer.layer.changed && this.canalLayer.layer.changed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
fitView() {
|
|
|
const source = this.waterLayer.layer.getSource();
|
|
|
if (!source || source.getFeatures().length === 0) {
|