Merge branch 'feat_source_hooks' of https://github.com/antvis/L7 into feat_source_hooks

This commit is contained in:
shihui 2022-10-18 23:36:54 +08:00
commit d42cb18bb9
10 changed files with 47 additions and 31 deletions

View File

@ -12,7 +12,6 @@ import React, { useEffect } from 'react';
export default () => {
useEffect(() => {
const SOC = 'CHN';
const colors = {};
const GDPSpeed = {
'520000': 10, //贵州

View File

@ -112,10 +112,10 @@ export default () => {
scene.addLayer(layer);
layer.on('click', (e) => {
console.log('layer click');
console.log(e);
});
// layer.on('click', (e) => {
// console.log('layer click');
// console.log(e);
// });
// setTimeout(() => {
// layer.style({

View File

@ -24,7 +24,7 @@
"author": "xiaoiver",
"license": "ISC",
"dependencies": {
"@antv/async-hook": "^2.2.4",
"@antv/async-hook": "^2.2.5",
"@antv/l7-utils": "2.9.36",
"@babel/runtime": "^7.7.7",
"@turf/helpers": "^6.1.4",

View File

@ -141,7 +141,7 @@ export default class LayerService implements ILayerService {
this.alreadyInRendering = true;
this.clear();
for (const layer of this.layerList) {
layer.hooks.beforeRenderData.promise();
await layer.hooks.beforeRenderData.promise();
layer.hooks.beforeRender.call();
if (layer.masks.length > 0) {

View File

@ -26,7 +26,7 @@
"author": "xiaoiver",
"license": "ISC",
"dependencies": {
"@antv/async-hook": "^2.2.4",
"@antv/async-hook": "^2.2.5",
"@antv/l7-core": "2.9.36",
"@antv/l7-maps": "2.9.36",
"@antv/l7-source": "2.9.36",

View File

@ -36,12 +36,18 @@ export default class DataMappingPlugin implements ILayerPlugin {
this.generateMaping(layer, { styleAttributeService });
});
layer.hooks.beforeRenderData.tapPromise('DataMappingPlugin', async () => {
layer.dataState.dataMappingNeedUpdate = false;
this.generateMaping(layer, { styleAttributeService });
layer.hooks.beforeRenderData.tapPromise(
'DataMappingPlugin',
async (flag: boolean) => {
if (!flag) {
return flag;
}
layer.dataState.dataMappingNeedUpdate = false;
this.generateMaping(layer, { styleAttributeService });
return true;
});
return true;
},
);
// remapping before render
layer.hooks.beforeRender.tap('DataMappingPlugin', () => {

View File

@ -71,19 +71,25 @@ export default class FeatureScalePlugin implements ILayerPlugin {
});
// 检测数据是否需要更新
layer.hooks.beforeRenderData.tapPromise('FeatureScalePlugin', async () => {
this.scaleOptions = layer.getScaleOptions();
const attributes = styleAttributeService.getLayerStyleAttributes();
const dataArray = layer.getSource().data.dataArray;
layer.hooks.beforeRenderData.tapPromise(
'FeatureScalePlugin',
async (flag: boolean) => {
if (!flag) {
return flag;
}
this.scaleOptions = layer.getScaleOptions();
const attributes = styleAttributeService.getLayerStyleAttributes();
const dataArray = layer.getSource().data.dataArray;
if (Array.isArray(dataArray) && dataArray.length === 0) {
return;
}
this.caculateScalesForAttributes(attributes || [], dataArray);
layer.layerModelNeedUpdate = true;
if (Array.isArray(dataArray) && dataArray.length === 0) {
return;
}
this.caculateScalesForAttributes(attributes || [], dataArray);
layer.layerModelNeedUpdate = true;
return true;
});
return true;
},
);
layer.hooks.beforeRender.tap('FeatureScalePlugin', () => {
const { usage } = layer.getLayerConfig();

View File

@ -28,9 +28,15 @@ export default class LayerModelPlugin implements ILayerPlugin {
await this.initLayerModel(layer);
});
layer.hooks.beforeRenderData.tapPromise('DataSourcePlugin', async () => {
await this.prepareLayerModel(layer);
return false;
});
layer.hooks.beforeRenderData.tapPromise(
'DataSourcePlugin',
async (flag: boolean) => {
if (!flag) {
return flag;
}
await this.prepareLayerModel(layer);
return false;
},
);
}
}

View File

@ -83,8 +83,7 @@ export class TileLayerService {
this._tiles.map((tile: Tile) => {
const layers = tile.getLayers();
layers.forEach(async (layer: ILayer) => {
layer.hooks.beforeRenderData.promise();
await layer.hooks.beforeRenderData.promise();
layer.hooks.beforeRender.call();
if (layer.masks.length > 0) {

View File

@ -24,7 +24,7 @@
"author": "lzxue",
"license": "ISC",
"dependencies": {
"@antv/async-hook": "^2.2.4",
"@antv/async-hook": "^2.2.5",
"@antv/l7-core": "2.9.36",
"@antv/l7-utils": "2.9.36",
"@babel/runtime": "^7.7.7",