Skip to content

Commit 8ccb79d

Browse files
committed
more fixes for aggregation layers
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
1 parent 0e35da0 commit 8ccb79d

File tree

8 files changed

+37
-160
lines changed

8 files changed

+37
-160
lines changed

src/deckgl-layers/src/cluster-layer/cluster-layer.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// @ts-nocheck
12
// SPDX-License-Identifier: MIT
23
// Copyright contributors to the kepler.gl project
34

5+
import {CompositeLayer} from '@deck.gl/core';
46
import {ScatterplotLayer} from '@deck.gl/layers';
5-
import {_AggregationLayer as AggregationLayer} from '@deck.gl/aggregation-layers';
67

78
import geoViewport from '@mapbox/geo-viewport';
89
import CPUAggregator, {
@@ -154,7 +155,7 @@ const defaultProps = {
154155
getRadiusValue: {type: 'accessor', value: defaultGetRadiusValue}
155156
};
156157

157-
export default class ClusterLayer extends AggregationLayer<any, any> {
158+
export default class ClusterLayer extends CompositeLayer {
158159
initializeState() {
159160
const cpuAggregator = new CPUAggregator({
160161
aggregation: clusterAggregation,
@@ -165,20 +166,14 @@ export default class ClusterLayer extends AggregationLayer<any, any> {
165166
cpuAggregator,
166167
aggregatorState: cpuAggregator.state
167168
};
168-
const attributeManager = this.getAttributeManager();
169-
attributeManager.add({
170-
positions: {size: 3, accessor: 'getPosition'}
171-
});
172169
}
173170

174171
updateState({oldProps, props, changeFlags}) {
175172
this.setState({
176-
// make a copy of the internal state of cpuAggregator for testing
177173
aggregatorState: this.state.cpuAggregator.updateState(
178174
{oldProps, props, changeFlags},
179175
{
180176
viewport: this.context.viewport,
181-
attributes: this.getAttributes(),
182177
numInstances: this.getNumInstances(props)
183178
}
184179
)

src/deckgl-layers/src/grid-layer/enhanced-cpu-grid-layer.ts

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,17 @@
22
// Copyright contributors to the kepler.gl project
33

44
import {GridLayer} from '@deck.gl/aggregation-layers';
5-
import CPUAggregator, {AggregationType, getAggregatedData} from '../layer-utils/cpu-aggregator';
6-
7-
export const gridAggregation: AggregationType = {
8-
key: 'position',
9-
updateSteps: [
10-
{
11-
key: 'aggregate',
12-
triggers: {
13-
cellSize: {
14-
prop: 'cellSize'
15-
},
16-
position: {
17-
prop: 'getPosition',
18-
updateTrigger: 'getPosition'
19-
},
20-
aggregator: {
21-
prop: 'gridAggregator'
22-
}
23-
},
24-
updater: getAggregatedData
25-
}
26-
]
27-
};
285

6+
/**
7+
* In deck.gl 9, GridLayer natively supports CPU aggregation via gpuAggregation: false,
8+
* custom getColorValue/getElevationValue accessors, percentile filtering, and scale types.
9+
* The custom CPUAggregator override from deck.gl 8 is no longer needed.
10+
*/
2911
export default class ScaleEnhancedGridLayer extends GridLayer<any> {
3012
static defaultProps = {
3113
...GridLayer.defaultProps,
3214
gpuAggregation: false
3315
};
34-
35-
initializeState() {
36-
const cpuAggregator = new CPUAggregator({
37-
aggregation: gridAggregation
38-
});
39-
40-
this.state = {
41-
cpuAggregator,
42-
aggregatorState: cpuAggregator.state
43-
};
44-
const attributeManager = this.getAttributeManager();
45-
attributeManager.add({
46-
positions: {size: 3, accessor: 'getPosition'}
47-
});
48-
}
4916
}
5017

5118
ScaleEnhancedGridLayer.layerName = 'ScaleEnhancedGridLayer';

src/deckgl-layers/src/hexagon-layer/enhanced-hexagon-layer.ts

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,17 @@
22
// Copyright contributors to the kepler.gl project
33

44
import {HexagonLayer} from '@deck.gl/aggregation-layers';
5-
import CPUAggregator, {AggregationType, getAggregatedData} from '../layer-utils/cpu-aggregator';
6-
7-
export const hexagonAggregation: AggregationType = {
8-
key: 'position',
9-
updateSteps: [
10-
{
11-
key: 'aggregate',
12-
triggers: {
13-
cellSize: {
14-
prop: 'radius'
15-
},
16-
position: {
17-
prop: 'getPosition',
18-
updateTrigger: 'getPosition'
19-
},
20-
aggregator: {
21-
prop: 'hexagonAggregator'
22-
}
23-
},
24-
updater: getAggregatedData
25-
}
26-
]
27-
};
285

6+
/**
7+
* In deck.gl 9, HexagonLayer natively supports CPU aggregation via gpuAggregation: false,
8+
* custom getColorValue/getElevationValue accessors, percentile filtering, and scale types.
9+
* The custom CPUAggregator override from deck.gl 8 is no longer needed.
10+
*/
2911
export default class ScaleEnhancedHexagonLayer extends HexagonLayer<any> {
30-
initializeState() {
31-
const cpuAggregator = new CPUAggregator({
32-
aggregation: hexagonAggregation
33-
});
34-
35-
this.state = {
36-
cpuAggregator,
37-
aggregatorState: cpuAggregator.state
38-
};
39-
const attributeManager = this.getAttributeManager();
40-
attributeManager.add({
41-
positions: {size: 3, accessor: 'getPosition'}
42-
});
43-
}
12+
static defaultProps = {
13+
...HexagonLayer.defaultProps,
14+
gpuAggregation: false
15+
};
4416
}
4517

4618
ScaleEnhancedHexagonLayer.layerName = 'ScaleEnhancedHexagonLayer';

src/layers/src/aggregation-layer.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ export default class AggregationLayer extends Layer {
8282
pointPosAccessor(this.config.columns)(dataContainer);
8383
this.getColorRange = memoize(getLayerColorRange);
8484

85-
// Access data of a point from aggregated bins, depends on how BinSorter works
86-
// Deck.gl's BinSorter puts data in point.source
87-
this.getPointData = pt => pt.source;
85+
// Access data of a point from aggregated bins
86+
// In deck.gl 9, aggregation layers pass original data items directly to getColorValue/getElevationValue
87+
this.getPointData = pt => pt;
8888

8989
this.gpuFilterGetIndex = pt => this.getPointData(pt).index;
9090
this.gpuFilterGetData = (dataContainer, data, fieldIndex) =>
@@ -308,7 +308,7 @@ export default class AggregationLayer extends Layer {
308308
if (this.config.dataId === null) {
309309
return {};
310310
}
311-
const {gpuFilter, dataContainer} = datasets[this.config.dataId];
311+
const {dataContainer} = datasets[this.config.dataId];
312312
const getPosition = this.getPositionAccessor(dataContainer);
313313

314314
const aggregatePoints = getValueAggrFunc(this.getPointData);
@@ -321,24 +321,12 @@ export default class AggregationLayer extends Layer {
321321
this.config.sizeField,
322322
this.config.visConfig.sizeAggregation
323323
);
324-
const hasFilter = Object.values(gpuFilter.filterRange).some((arr: any) =>
325-
arr.some(v => v !== 0)
326-
);
327-
328-
const getFilterValue = gpuFilter.filterValueAccessor(dataContainer)(
329-
this.gpuFilterGetIndex,
330-
this.gpuFilterGetData
331-
);
332-
const filterData = hasFilter
333-
? getFilterDataFunc(gpuFilter.filterRange, getFilterValue)
334-
: undefined;
335324

336325
const {data} = this.updateData(datasets, oldLayerData);
337326

338327
return {
339328
data,
340329
getPosition,
341-
_filterData: filterData,
342330
// @ts-expect-error
343331
...(getColorValue ? {getColorValue} : {}),
344332
// @ts-expect-error
@@ -353,12 +341,12 @@ export default class AggregationLayer extends Layer {
353341
highlightColor: HIGHLIGH_COLOR_3D,
354342
// gpu data filtering is not supported in aggregation layer
355343
extensions: [],
356-
autoHighlight: this.config.visConfig.enable3d
344+
autoHighlight: true
357345
};
358346
}
359347

360348
getDefaultAggregationLayerProp(opts) {
361-
const {gpuFilter, mapState, layerCallbacks = {}} = opts;
349+
const {mapState, layerCallbacks = {}} = opts;
362350
const {visConfig} = this.config;
363351
const eleZoomFactor = this.getElevationZoomFactor(mapState);
364352

@@ -372,10 +360,6 @@ export default class AggregationLayer extends Layer {
372360
getElevationValue: {
373361
sizeField: this.config.sizeField,
374362
sizeAggregation: this.config.visConfig.sizeAggregation
375-
},
376-
_filterData: {
377-
filterRange: gpuFilter.filterRange,
378-
...gpuFilter.filterValueUpdateTriggers
379363
}
380364
};
381365

src/layers/src/grid-layer/grid-layer.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright contributors to the kepler.gl project
33

4-
import {GeoJsonLayer} from '@deck.gl/layers';
54
import {EnhancedGridLayer} from '@kepler.gl/deckgl-layers';
65
import AggregationLayer, {AggregationLayerConfig} from '../aggregation-layer';
7-
import {pointToPolygonGeo} from './grid-utils';
86
import GridLayerIcon from './grid-layer-icon';
97
import {
108
ColorRange,
@@ -99,42 +97,19 @@ export default class GridLayer extends AggregationLayer {
9997
}
10098

10199
renderLayer(opts) {
102-
const {data, objectHovered, mapState} = opts;
100+
const {data} = opts;
103101

104102
const defaultAggregationLayerProps = this.getDefaultAggregationLayerProp(opts);
105-
const zoomFactor = this.getZoomFactor(mapState);
106103
const {visConfig} = this.config;
107104
const cellSize = visConfig.worldUnitSize * 1000;
108-
const hoveredObject = this.hasHoveredObject(objectHovered);
109105

110106
return [
111107
new EnhancedGridLayer({
112108
...defaultAggregationLayerProps,
113109
...data,
114110
wrapLongitude: false,
115111
cellSize
116-
}),
117-
118-
// render an outline of each cell if not extruded
119-
...(hoveredObject && !visConfig.enable3d
120-
? [
121-
new GeoJsonLayer({
122-
...this.getDefaultHoverLayerProps(),
123-
visible: defaultAggregationLayerProps.visible,
124-
wrapLongitude: false,
125-
data: [
126-
pointToPolygonGeo({
127-
object: hoveredObject,
128-
cellSize,
129-
coverage: visConfig.coverage,
130-
mapState
131-
})
132-
],
133-
getLineColor: this.config.highlightColor,
134-
lineWidthScale: 8 * zoomFactor
135-
})
136-
]
137-
: [])
112+
})
138113
];
139114
}
140115
}

src/layers/src/grid-layer/grid-utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {MapState} from '@kepler.gl/types';
1212
* @param coverage
1313
* @param properties
1414
* @param mapState
15+
* @param coordinate - fallback position from picking info (deck.gl 9 no longer provides object.position)
1516
* @returns - geojson feature
1617
*/
1718

@@ -21,15 +22,17 @@ export function pointToPolygonGeo({
2122
cellSize,
2223
coverage,
2324
properties,
24-
mapState
25+
mapState,
26+
coordinate
2527
}: {
2628
object: any;
2729
cellSize: number;
2830
coverage: number;
2931
properties?: any;
3032
mapState: MapState;
33+
coordinate?: number[];
3134
}) {
32-
const {position} = object;
35+
const position = object.position || coordinate;
3336
const viewport = new WebMercatorViewport(mapState);
3437

3538
if (!position) {

src/layers/src/hexagon-layer/hexagon-layer.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright contributors to the kepler.gl project
33

4-
import {GeoJsonLayer} from '@deck.gl/layers';
54
import AggregationLayer, {AggregationLayerConfig} from '../aggregation-layer';
65
import {EnhancedHexagonLayer} from '@kepler.gl/deckgl-layers';
7-
import {hexagonToPolygonGeo} from './hexagon-utils';
86
import HexagonLayerIcon from './hexagon-layer-icon';
97
import {
108
ColorRange,
@@ -107,37 +105,19 @@ export default class HexagonLayer extends AggregationLayer {
107105
}
108106

109107
renderLayer(opts) {
110-
const {data, objectHovered, mapState} = opts;
108+
const {data} = opts;
111109

112110
const defaultAggregationLayerProps = this.getDefaultAggregationLayerProp(opts);
113-
const zoomFactor = this.getZoomFactor(mapState);
114111
const {visConfig} = this.config;
115112
const radius = visConfig.worldUnitSize * 1000;
116-
const hoveredObject = this.hasHoveredObject(objectHovered);
117113

118114
return [
119115
new EnhancedHexagonLayer({
120116
...defaultAggregationLayerProps,
121117
...data,
122118
wrapLongitude: false,
123119
radius
124-
}),
125-
126-
// render an outline of each hexagon if not extruded
127-
...(hoveredObject && !visConfig.enable3d
128-
? [
129-
new GeoJsonLayer({
130-
...this.getDefaultHoverLayerProps(),
131-
visible: defaultAggregationLayerProps.visible,
132-
wrapLongitude: false,
133-
data: [
134-
hexagonToPolygonGeo(hoveredObject, {}, radius * visConfig.coverage, mapState)
135-
].filter(d => d),
136-
getLineColor: this.config.highlightColor,
137-
lineWidthScale: 8 * zoomFactor
138-
})
139-
]
140-
: [])
120+
})
141121
];
142122
}
143123
}

src/layers/src/hexagon-layer/hexagon-utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import {WebMercatorViewport} from '@deck.gl/core';
55
import Console from 'global/console';
66
import type {Centroid} from '@kepler.gl/common-utils';
77

8-
export function hexagonToPolygonGeo(object, properties, radius, mapState) {
8+
export function hexagonToPolygonGeo(object, properties, radius, mapState, coordinate?) {
99
const viewport = new WebMercatorViewport(mapState);
10-
if (!Array.isArray(object.position)) {
10+
const position = object.position || coordinate;
11+
if (!Array.isArray(position)) {
1112
return null;
1213
}
1314

14-
const screenCenter = viewport.projectFlat(object.position);
15-
const {unitsPerMeter} = viewport.getDistanceScales(object.position);
15+
const screenCenter = viewport.projectFlat(position);
16+
const {unitsPerMeter} = viewport.getDistanceScales(position);
1617

1718
if (!Array.isArray(unitsPerMeter)) {
1819
Console.warn(`unitsPerMeter is undefined`);

0 commit comments

Comments
 (0)