Skip to content

Commit fbedc0d

Browse files
committed
restore filters for aggregation layers
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
1 parent ec45a94 commit fbedc0d

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

src/layers/src/aggregation-layer.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,21 @@ export default class AggregationLayer extends Layer {
308308
if (this.config.dataId === null) {
309309
return {};
310310
}
311-
const {dataContainer} = datasets[this.config.dataId];
311+
const {gpuFilter, dataContainer} = datasets[this.config.dataId];
312312
const getPosition = this.getPositionAccessor(dataContainer);
313313

314+
const hasFilter = Object.values(gpuFilter.filterRange).some((arr: any) =>
315+
arr.some(v => v !== 0)
316+
);
317+
318+
const getFilterValue = gpuFilter.filterValueAccessor(dataContainer)(
319+
this.gpuFilterGetIndex,
320+
this.gpuFilterGetData
321+
);
322+
const filterData = hasFilter
323+
? getFilterDataFunc(gpuFilter.filterRange, getFilterValue)
324+
: undefined;
325+
314326
const aggregatePoints = getValueAggrFunc(this.getPointData);
315327
const getColorValue = aggregatePoints(
316328
this.config.colorField,
@@ -322,15 +334,27 @@ export default class AggregationLayer extends Layer {
322334
this.config.visConfig.sizeAggregation
323335
);
324336

337+
// Wrap accessors to filter points within each bin before aggregating.
338+
// deck.gl 9's native aggregation doesn't support per-bin filtering, so we
339+
// apply gpuFilter at the accessor level to keep bin values in sync with
340+
// active cross-filters / time-filters.
341+
const getFilteredColorValue =
342+
filterData && getColorValue
343+
? points => getColorValue(points.filter(filterData))
344+
: getColorValue;
345+
const getFilteredElevationValue =
346+
filterData && getElevationValue
347+
? points => getElevationValue(points.filter(filterData))
348+
: getElevationValue;
349+
325350
const {data} = this.updateData(datasets, oldLayerData);
326351

327352
return {
328353
data,
329354
getPosition,
330-
// @ts-expect-error
331-
...(getColorValue ? {getColorValue} : {}),
332-
// @ts-expect-error
333-
...(getElevationValue ? {getElevationValue} : {})
355+
_filterData: filterData,
356+
...(getFilteredColorValue ? {getColorValue: getFilteredColorValue} : {}),
357+
...(getFilteredElevationValue ? {getElevationValue: getFilteredElevationValue} : {})
334358
};
335359
}
336360

@@ -346,7 +370,7 @@ export default class AggregationLayer extends Layer {
346370
}
347371

348372
getDefaultAggregationLayerProp(opts) {
349-
const {mapState, layerCallbacks = {}} = opts;
373+
const {gpuFilter, mapState, layerCallbacks = {}} = opts;
350374
const {visConfig} = this.config;
351375
const eleZoomFactor = this.getElevationZoomFactor(mapState);
352376

@@ -355,11 +379,19 @@ export default class AggregationLayer extends Layer {
355379
colorField: this.config.colorField,
356380
colorAggregation: this.config.visConfig.colorAggregation,
357381
colorRange: visConfig.colorRange,
358-
colorMap: visConfig.colorRange.colorMap
382+
colorMap: visConfig.colorRange.colorMap,
383+
_filterData: {
384+
filterRange: gpuFilter.filterRange,
385+
...gpuFilter.filterValueUpdateTriggers
386+
}
359387
},
360388
getElevationValue: {
361389
sizeField: this.config.sizeField,
362-
sizeAggregation: this.config.visConfig.sizeAggregation
390+
sizeAggregation: this.config.visConfig.sizeAggregation,
391+
_filterData: {
392+
filterRange: gpuFilter.filterRange,
393+
...gpuFilter.filterValueUpdateTriggers
394+
}
363395
}
364396
};
365397

0 commit comments

Comments
 (0)