From 99e3c6d00c400d790a94da620eab2b1b1bcd3067 Mon Sep 17 00:00:00 2001 From: yunji Date: Wed, 6 Mar 2024 19:41:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=B4=E6=97=B6=E4=BF=AE=E5=A4=8D=20l?= =?UTF-8?q?egend=20=E5=BC=82=E6=AD=A5=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/l7plot/src/core/plot/index.ts | 4 ++-- packages/l7plot/src/plots/choropleth/index.ts | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/l7plot/src/core/plot/index.ts b/packages/l7plot/src/core/plot/index.ts index 24943f510..4fcccf864 100644 --- a/packages/l7plot/src/core/plot/index.ts +++ b/packages/l7plot/src/core/plot/index.ts @@ -118,7 +118,7 @@ export abstract class Plot extends Map { source: Source, label?: false | LabelOptions, plotLayerConfig?: PlotLayerOptions, - labelLayer?: TextLayer + labelLayer?: TextLayer, ) { if (label) { if (labelLayer) { @@ -259,7 +259,7 @@ export abstract class Plot extends Map { if (legend) { setTimeout(() => { this.updateLegendControl(legend); - }); + }, 500); } this.emit('change-data'); diff --git a/packages/l7plot/src/plots/choropleth/index.ts b/packages/l7plot/src/plots/choropleth/index.ts index 8d04b47f9..43decfc1d 100644 --- a/packages/l7plot/src/plots/choropleth/index.ts +++ b/packages/l7plot/src/plots/choropleth/index.ts @@ -203,7 +203,7 @@ export class Choropleth extends Plot { if (legend) { setTimeout(() => { this.updateLegendControl(legend); - }); + }, 500); } this.emit('change-data'); @@ -241,7 +241,7 @@ export class Choropleth extends Plot { private createCountryBoundaryLayer(data: FeatureCollection, plotConfig?: ChoroplethOptions) { const { chinaBoundaryLayer, chinaHkmBoundaryLayer, chinaDisputeBoundaryLayer } = createCountryBoundaryLayer( data, - plotConfig + plotConfig, ); this.chinaBoundaryLayer = chinaBoundaryLayer; this.chinaHkmBoundaryLayer = chinaHkmBoundaryLayer; @@ -255,7 +255,7 @@ export class Choropleth extends Plot { protected createLabelLayer(source: Source, label: LabelOptions): TextLayer { const data = source['originData'].features .map(({ properties }) => - Object.assign({}, properties, { centroid: properties['centroid'] || properties['center'] }) + Object.assign({}, properties, { centroid: properties['centroid'] || properties['center'] }), ) .filter(({ centroid }) => centroid); const { visible, minZoom, maxZoom, zIndex = 0 } = this.options; @@ -325,6 +325,7 @@ export class Choropleth extends Plot { */ protected initLayersEvent() { this.initDrillEvent(); + // this.initLegendEvent(); } /** @@ -375,6 +376,18 @@ export class Choropleth extends Plot { this.fillAreaLayer.on(triggerDown, this.onDrillDownHander); } + /** + * 初始化图例事件 + */ + private initLegendEvent() { + const legend = this.options.legend; + if (!legend) return; + const onUpdateLegendData = () => { + this.updateLegendControl(legend); + }; + this.fillAreaLayer.on('legend:color', onUpdateLegendData); + } + /** * 重置钻取缓存数据 */