mirror of https://gitee.com/antv-l7/antv-l7
parent
6ff115ddb5
commit
710679041c
|
@ -62,7 +62,7 @@ export interface ISource {
|
|||
cluster: boolean;
|
||||
clusterOptions: Partial<IClusterOptions>;
|
||||
setData(data: any): void;
|
||||
updateClusterData(zoom: number): void;
|
||||
updateClusterData(bbox: [[number, number], [number, number]], zoom: number): void;
|
||||
getFeatureById(id: number): unknown;
|
||||
getFeatureId(field: string, value: any): number | undefined;
|
||||
getClusters(zoom: number): any;
|
||||
|
|
|
@ -746,8 +746,9 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
|||
public setSource(source: Source) {
|
||||
this.layerSource = source;
|
||||
const zoom = this.mapService.getZoom();
|
||||
const viewBounds = this.mapService.getBounds();
|
||||
if (this.layerSource.cluster) {
|
||||
this.layerSource.updateClusterData(zoom);
|
||||
this.layerSource.updateClusterData(viewBounds, zoom);
|
||||
}
|
||||
// source 可能会复用,会在其它layer被修改
|
||||
this.layerSource.on('update', this.sourceEvent);
|
||||
|
|
|
@ -27,8 +27,9 @@ export default class DataSourcePlugin implements ILayerPlugin {
|
|||
const cluster = source.cluster;
|
||||
const { zoom = 0, maxZoom = 16 } = source.clusterOptions;
|
||||
const newZoom = this.mapService.getZoom() - 1;
|
||||
const viewBounds = this.mapService.getBounds();
|
||||
if (cluster && Math.abs(zoom - newZoom) > 1 && maxZoom > zoom) {
|
||||
source.updateClusterData(Math.floor(newZoom));
|
||||
source.updateClusterData(viewBounds, Math.floor(newZoom));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Source from '../src/source';
|
||||
import Point from './data/point';
|
||||
import Polygon from './data/polygon';
|
||||
import { bBoxToBounds } from '@antv/l7-utils';
|
||||
|
||||
describe('source constructor', () => {
|
||||
it('source.constructor', () => {
|
||||
|
@ -20,6 +21,6 @@ describe('source constructor', () => {
|
|||
field: 'mag',
|
||||
},
|
||||
});
|
||||
source.updateClusterData(2);
|
||||
source.updateClusterData(bBoxToBounds(source.extent), 2);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
lazyInject,
|
||||
TYPES,
|
||||
} from '@antv/l7-core';
|
||||
import { extent } from '@antv/l7-utils';
|
||||
import { extent, boundsContains, bBoxToBounds } from '@antv/l7-utils';
|
||||
import {
|
||||
BBox,
|
||||
Feature,
|
||||
|
@ -85,9 +85,12 @@ export default class Source extends EventEmitter {
|
|||
public getClustersLeaves(id: number): any {
|
||||
return this.clusterIndex.getLeaves(id, Infinity);
|
||||
}
|
||||
public updateClusterData(zoom: number): void {
|
||||
public updateClusterData(bbox: [[number,number],[number,number]],zoom: number): void {
|
||||
const { method = 'sum', field } = this.clusterOptions;
|
||||
let data = this.clusterIndex.getClusters(this.extent, Math.floor(zoom));
|
||||
if (!boundsContains(bbox, bBoxToBounds(this.extent))) {
|
||||
return;
|
||||
}
|
||||
let data = this.clusterIndex.getClusters(bbox[0].concat(bbox[1]), Math.floor(zoom));
|
||||
this.clusterOptions.zoom = zoom;
|
||||
data.forEach((p: any) => {
|
||||
if (!p.id) {
|
||||
|
|
|
@ -239,3 +239,11 @@ export function boundsContains(b1: IBounds, b2: IBounds): boolean {
|
|||
b1[1][1] >= b2[1][1]
|
||||
);
|
||||
}
|
||||
/**
|
||||
* bbox 转换为Bounds
|
||||
* @param b1 bbox
|
||||
*
|
||||
*/
|
||||
export function bBoxToBounds(b1: BBox): IBounds {
|
||||
return [[b1[0], b1[1]], [b1[2], b1[3]]];
|
||||
}
|
Loading…
Reference in New Issue