Skip to content

Commit

Permalink
fix: 临时修复 legend 异步数据获取情况
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Mar 6, 2024
1 parent 3f3e8b2 commit 99e3c6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/l7plot/src/core/plot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export abstract class Plot<O extends PlotOptions> extends Map<O> {
source: Source,
label?: false | LabelOptions,
plotLayerConfig?: PlotLayerOptions,
labelLayer?: TextLayer
labelLayer?: TextLayer,
) {
if (label) {
if (labelLayer) {
Expand Down Expand Up @@ -259,7 +259,7 @@ export abstract class Plot<O extends PlotOptions> extends Map<O> {
if (legend) {
setTimeout(() => {
this.updateLegendControl(legend);
});
}, 500);
}

this.emit('change-data');
Expand Down
19 changes: 16 additions & 3 deletions packages/l7plot/src/plots/choropleth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class Choropleth extends Plot<ChoroplethOptions> {
if (legend) {
setTimeout(() => {
this.updateLegendControl(legend);
});
}, 500);
}

this.emit('change-data');
Expand Down Expand Up @@ -241,7 +241,7 @@ export class Choropleth extends Plot<ChoroplethOptions> {
private createCountryBoundaryLayer(data: FeatureCollection, plotConfig?: ChoroplethOptions) {
const { chinaBoundaryLayer, chinaHkmBoundaryLayer, chinaDisputeBoundaryLayer } = createCountryBoundaryLayer(
data,
plotConfig
plotConfig,
);
this.chinaBoundaryLayer = chinaBoundaryLayer;
this.chinaHkmBoundaryLayer = chinaHkmBoundaryLayer;
Expand All @@ -255,7 +255,7 @@ export class Choropleth extends Plot<ChoroplethOptions> {
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;
Expand Down Expand Up @@ -325,6 +325,7 @@ export class Choropleth extends Plot<ChoroplethOptions> {
*/
protected initLayersEvent() {
this.initDrillEvent();
// this.initLegendEvent();
}

/**
Expand Down Expand Up @@ -375,6 +376,18 @@ export class Choropleth extends Plot<ChoroplethOptions> {
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);
}

/**
* 重置钻取缓存数据
*/
Expand Down

0 comments on commit 99e3c6d

Please sign in to comment.