Skip to content

Commit

Permalink
explicitly create AttributeManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed May 12, 2024
1 parent 134a139 commit af9e3ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
LayerContext,
UpdateParameters,
CompositeLayerProps,
Attribute
Attribute,
AttributeManager
} from '@deck.gl/core';
import {Aggregator} from './aggregator';

Expand All @@ -28,7 +29,7 @@ export default abstract class AggregationLayer<
cpuAggregator: CPUAggregator | null;
};

/** Allow this layer to have an AttributeManager and participates in the draw cycle */
/** Allow this layer to participates in the draw cycle */
get isDrawable() {
return true;
}
Expand Down Expand Up @@ -89,6 +90,14 @@ export default abstract class AggregationLayer<
return this.state.gpuAggregator || this.state.cpuAggregator;
}

// override CompositeLayer._getAttributeManager to create AttributeManager instance
_getAttributeManager() {
return new AttributeManager(this.context.device, {
id: this.props.id,
stats: this.context.stats
});
}

// Override CompositeLayer._postUpdate to update attributes and the CPUAggregator
protected _postUpdate(updateParams: UpdateParameters<this>, forceUpdate: boolean) {
this._updateAttributes();
Expand Down
6 changes: 6 additions & 0 deletions modules/core/src/lib/composite-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Layer, {UpdateParameters} from './layer';
import debug from '../debug/index';
import {flatten} from '../utils/flatten';

import type AttributeManager from './attribute/attribute-manager';
import type {PickingInfo, GetPickingInfoParams} from './picking/pick-info';
import type {FilterContext} from '../passes/layers-pass';
import type {LayersList, LayerContext} from './layer-manager';
Expand Down Expand Up @@ -257,6 +258,11 @@ export default abstract class CompositeLayer<PropsT extends {} = {}> extends Lay
}
}

/** Override base Layer method */
protected _getAttributeManager(): AttributeManager | null {
return null;
}

/** (Internal) Called after an update to rerender sub layers */
protected _postUpdate(updateParams: UpdateParameters<this>, forceUpdate: boolean) {
// @ts-ignore (TS2531) this method is only called internally when internalState is defined
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/lib/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ export default abstract class Layer<PropsT extends {} = {}> extends Component<

debug(TRACE_INITIALIZE, this);

const attributeManager = this.isDrawable ? this._getAttributeManager() : null;
const attributeManager = this._getAttributeManager();

if (attributeManager) {
// All instanced layers get instancePickingColors attribute by default
Expand Down

0 comments on commit af9e3ff

Please sign in to comment.