mirror of https://gitee.com/antv-l7/antv-l7
fix: 修复 feature scale 可能存在的 source 取值问题 (#1315)
* fix: 修复 featureScale 错误 * style: lint style * fix: 修复 feature scale 映射问题 * style: lint style Co-authored-by: shihui <yiqianyao.yqy@alibaba-inc.com>
This commit is contained in:
parent
33c34764b7
commit
9f2f834960
|
@ -11,6 +11,7 @@ import {
|
|||
ScaleTypes,
|
||||
StyleScaleType,
|
||||
TYPES,
|
||||
IParserData,
|
||||
} from '@antv/l7-core';
|
||||
import { IParseDataItem } from '@antv/l7-source';
|
||||
import { extent } from 'd3-array';
|
||||
|
@ -50,6 +51,17 @@ export default class FeatureScalePlugin implements ILayerPlugin {
|
|||
|
||||
private scaleOptions: IScaleOptions = {};
|
||||
|
||||
private getSourceData(layer: ILayer, callback: (data: IParserData) => void) {
|
||||
const source = layer.getSource();
|
||||
if (source.inited) {
|
||||
callback(source.data);
|
||||
} else {
|
||||
source.once('sourceUpdate', () => {
|
||||
callback(source.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public apply(
|
||||
layer: ILayer,
|
||||
{
|
||||
|
@ -59,20 +71,45 @@ export default class FeatureScalePlugin implements ILayerPlugin {
|
|||
layer.hooks.init.tap('FeatureScalePlugin', () => {
|
||||
this.scaleOptions = layer.getScaleOptions();
|
||||
const attributes = styleAttributeService.getLayerStyleAttributes();
|
||||
const { dataArray } = layer.getSource().data;
|
||||
if (dataArray.length === 0) {
|
||||
return;
|
||||
}
|
||||
this.caculateScalesForAttributes(attributes || [], dataArray);
|
||||
|
||||
this.getSourceData(layer, ({ dataArray }) => {
|
||||
if (Array.isArray(dataArray) && dataArray.length === 0) {
|
||||
return;
|
||||
} else {
|
||||
this.caculateScalesForAttributes(attributes || [], dataArray);
|
||||
}
|
||||
});
|
||||
// const { dataArray } = layer.getSource().data;
|
||||
// if (dataArray.length === 0) {
|
||||
// return;
|
||||
// }
|
||||
// this.caculateScalesForAttributes(
|
||||
// attributes || [],
|
||||
// dataArray as IParseDataItem[],
|
||||
// );
|
||||
});
|
||||
|
||||
// 检测数据是否需要更新
|
||||
layer.hooks.beforeRenderData.tap('FeatureScalePlugin', () => {
|
||||
this.scaleOptions = layer.getScaleOptions();
|
||||
const attributes = styleAttributeService.getLayerStyleAttributes();
|
||||
const { dataArray } = layer.getSource().data;
|
||||
this.caculateScalesForAttributes(attributes || [], dataArray);
|
||||
layer.layerModelNeedUpdate = true;
|
||||
|
||||
this.getSourceData(layer, ({ dataArray }) => {
|
||||
if (Array.isArray(dataArray) && dataArray.length === 0) {
|
||||
return;
|
||||
}
|
||||
this.caculateScalesForAttributes(attributes || [], dataArray);
|
||||
layer.layerModelNeedUpdate = true;
|
||||
});
|
||||
// const { dataArray } = layer.getSource().data;
|
||||
// if (dataArray.length === 0) {
|
||||
// return;
|
||||
// }
|
||||
// this.caculateScalesForAttributes(
|
||||
// attributes || [],
|
||||
// dataArray
|
||||
// );
|
||||
// layer.layerModelNeedUpdate = true;
|
||||
return true;
|
||||
});
|
||||
|
||||
|
@ -83,16 +120,31 @@ export default class FeatureScalePlugin implements ILayerPlugin {
|
|||
this.scaleOptions = layer.getScaleOptions();
|
||||
const attributes = styleAttributeService.getLayerStyleAttributes();
|
||||
if (attributes) {
|
||||
const { dataArray } = layer.getSource().data;
|
||||
if (dataArray.length === 0) {
|
||||
return;
|
||||
}
|
||||
const attributesToRescale = attributes.filter(
|
||||
(attribute) => attribute.needRescale,
|
||||
);
|
||||
if (attributesToRescale.length) {
|
||||
this.caculateScalesForAttributes(attributesToRescale, dataArray);
|
||||
}
|
||||
this.getSourceData(layer, ({ dataArray }) => {
|
||||
if (dataArray.length === 0) {
|
||||
return;
|
||||
}
|
||||
const attributesToRescale = attributes.filter(
|
||||
(attribute) => attribute.needRescale,
|
||||
);
|
||||
if (attributesToRescale.length) {
|
||||
this.caculateScalesForAttributes(attributesToRescale, dataArray);
|
||||
}
|
||||
});
|
||||
|
||||
// const { dataArray } = layer.getSource().data;
|
||||
// if (dataArray.length === 0) {
|
||||
// return;
|
||||
// }
|
||||
// const attributesToRescale = attributes.filter(
|
||||
// (attribute) => attribute.needRescale,
|
||||
// );
|
||||
// if (attributesToRescale.length) {
|
||||
// this.caculateScalesForAttributes(
|
||||
// attributesToRescale,
|
||||
// dataArray,
|
||||
// );
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -240,6 +240,14 @@ export default class Source extends EventEmitter implements ISource {
|
|||
* 数据解析
|
||||
*/
|
||||
private excuteParser(): void {
|
||||
// 耗时计算测试
|
||||
// let t = new Date().getTime();
|
||||
// let c = 0
|
||||
// while(c < 100000000) {
|
||||
// c++
|
||||
// }
|
||||
// console.log('t', new Date().getTime() - t)
|
||||
|
||||
const parser = this.parser;
|
||||
const type: string = parser.type || 'geojson';
|
||||
const sourceParser = getParser(type);
|
||||
|
|
Loading…
Reference in New Issue