Merge pull request #672 from yu-tou/master

fix: cluster 模式下,point 后续 setData,不会立即生效
This commit is contained in:
@thinkinggis 2021-04-20 19:53:32 +08:00 committed by GitHub
commit e14838449e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 5 deletions

View File

@ -13,12 +13,12 @@ export default class DataSourcePlugin implements ILayerPlugin {
this.updateClusterData(layer);
});
// 检测数据否需要更新
// 检测数据否需要更新
layer.hooks.beforeRenderData.tap('DataSourcePlugin', () => {
const neeUpdate1 = this.updateClusterData(layer);
const neeUpdate2 = layer.dataState.dataSourceNeedUpdate;
const neeUpdateCluster = this.updateClusterData(layer);
const dataSourceNeedUpdate = layer.dataState.dataSourceNeedUpdate;
layer.dataState.dataSourceNeedUpdate = false;
return neeUpdate1 || neeUpdate2;
return neeUpdateCluster || dataSourceNeedUpdate;
});
}
@ -27,7 +27,13 @@ export default class DataSourcePlugin implements ILayerPlugin {
const cluster = source.cluster;
const { zoom = 0, maxZoom = 16 } = source.clusterOptions;
const newZoom = this.mapService.getZoom() - 1;
if (cluster && Math.abs(zoom - newZoom) > 1 && maxZoom > zoom) {
const dataSourceNeedUpdate = layer.dataState.dataSourceNeedUpdate;
// 如果 dataSource 有更新,跳过 zoom 的判断,直接更新一次
if (
cluster &&
(dataSourceNeedUpdate || Math.abs(zoom - newZoom) > 1) &&
maxZoom > zoom
) {
source.updateClusterData(Math.floor(newZoom));
return true;
}