From 227415448153ffaae67ba033f37fea2040c144c4 Mon Sep 17 00:00:00 2001 From: yy <582443115@qq.com> Date: Tue, 23 Mar 2021 15:26:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(cluster):=20pointLayer=E7=9B=B8?= =?UTF-8?q?=E5=90=8C=E7=BB=8F=E7=BA=AC=E5=BA=A6=E7=82=B9=E4=B8=8D=E8=81=9A?= =?UTF-8?q?=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #633 --- packages/source/src/source.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/source/src/source.ts b/packages/source/src/source.ts index ab2bc5cd06..ed6bc75f62 100644 --- a/packages/source/src/source.ts +++ b/packages/source/src/source.ts @@ -11,7 +11,12 @@ import { lazyInject, TYPES, } from '@antv/l7-core'; -import { bBoxToBounds, extent, padBounds } from '@antv/l7-utils'; +import { + bBoxToBounds, + extent, + lnglatDistance, + padBounds, +} from '@antv/l7-utils'; import { BBox, Feature, @@ -54,6 +59,8 @@ export default class Source extends EventEmitter { zoom: -99, method: 'count', }; + // 数据范围框的对角线长度 + private extentDiagonalLength: number; // 原始数据 private originData: any; @@ -89,16 +96,15 @@ export default class Source extends EventEmitter { this.emit('update'); } public getClusters(zoom: number): any { - return this.clusterIndex.getClusters(this.extent, zoom); + return this.clusterIndex.getClusters(this.caculClusterExtent(2), zoom); } public getClustersLeaves(id: number): any { return this.clusterIndex.getLeaves(id, Infinity); } public updateClusterData(zoom: number): void { const { method = 'sum', field } = this.clusterOptions; - const newBounds = padBounds(bBoxToBounds(this.extent), 2); let data = this.clusterIndex.getClusters( - newBounds[0].concat(newBounds[1]), + this.caculClusterExtent(2), Math.floor(zoom), ); this.clusterOptions.zoom = zoom; @@ -169,6 +175,17 @@ export default class Source extends EventEmitter { this.data = null; } + private caculClusterExtent(bufferRatio: number): any { + let newBounds = [ + [-Infinity, -Infinity], + [Infinity, Infinity], + ]; + if (this.extentDiagonalLength > 0) { + newBounds = padBounds(bBoxToBounds(this.extent), bufferRatio); + } + return newBounds[0].concat(newBounds[1]); + } + private initCfg(option?: ISourceCFG) { this.cfg = mergeWith(this.cfg, option, mergeCustomizer); const cfg = this.cfg; @@ -196,6 +213,10 @@ export default class Source extends EventEmitter { this.data = sourceParser(this.originData, parser); // 计算范围 this.extent = extent(this.data.dataArray); + this.extentDiagonalLength = lnglatDistance( + [this.extent[0], this.extent[1]], + [this.extent[2], this.extent[3]], + ); } /** * 数据统计 From 4d401bb45a8b983f5db36c511a513054a95aec0a Mon Sep 17 00:00:00 2001 From: yanyu510 <582443115@qq.com> Date: Mon, 29 Mar 2021 16:28:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(source):=20pointLayer=E7=9B=B8=E5=90=8C?= =?UTF-8?q?=E7=BB=8F=E7=BA=AC=E5=BA=A6=E7=82=B9=E6=88=96extent=E5=9C=A8?= =?UTF-8?q?=E4=B8=80=E6=9D=A1=E7=BA=BF=E4=B8=8A=E6=97=B6=E4=B8=8D=E8=81=9A?= =?UTF-8?q?=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #633 --- packages/source/src/source.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/source/src/source.ts b/packages/source/src/source.ts index ed6bc75f62..c334c94cee 100644 --- a/packages/source/src/source.ts +++ b/packages/source/src/source.ts @@ -14,7 +14,6 @@ import { import { bBoxToBounds, extent, - lnglatDistance, padBounds, } from '@antv/l7-utils'; import { @@ -59,8 +58,8 @@ export default class Source extends EventEmitter { zoom: -99, method: 'count', }; - // 数据范围框的对角线长度 - private extentDiagonalLength: number; + // 是否有效范围 + private invalidExtent: boolean = false; // 原始数据 private originData: any; @@ -180,7 +179,9 @@ export default class Source extends EventEmitter { [-Infinity, -Infinity], [Infinity, Infinity], ]; - if (this.extentDiagonalLength > 0) { + + if (!this.invalidExtent) { + newBounds = padBounds(bBoxToBounds(this.extent), bufferRatio); } return newBounds[0].concat(newBounds[1]); @@ -213,10 +214,8 @@ export default class Source extends EventEmitter { this.data = sourceParser(this.originData, parser); // 计算范围 this.extent = extent(this.data.dataArray); - this.extentDiagonalLength = lnglatDistance( - [this.extent[0], this.extent[1]], - [this.extent[2], this.extent[3]], - ); + this.invalidExtent = this.extent[0]===this.extent[2] || this.extent[1]===this.extent[3] + } /** * 数据统计