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); + } + /** * 重置钻取缓存数据 */