You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api-reference/core/composite-layer.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,81 @@ The default implementation of `renderLayers` returns `null`.
116
116
`renderLayers` can return a nested arrays with `null` values. deck.gl will automatically flatten and filter the array. See usage above.
117
117
118
118
119
+
##### `filterSubLayer`
120
+
121
+
Allows a layer to dynamically show/hide sub layers based on the render context.
122
+
123
+
Receives arguments:
124
+
125
+
-`layer` (Layer) - the sub layer to be drawn
126
+
-`viewport` (Viewport) - the current viewport
127
+
-`isPicking` (Boolean) - whether this is a picking pass
128
+
-`renderPass` (String) - the name of the current render pass. See [layerFilter](/docs/api-reference/core/deck.md#layerfilter) for possible values.
129
+
130
+
Returns:
131
+
132
+
`true` if the layer should be drawn.
133
+
134
+
This method achieves the same result as toggling sub layers' `visible` prop in `renderLayers`. The difference is that, `renderLayers` is only called when the layer is updated due to props or state change, and will recursively create new instances of all decendant layers, therefore is more expensive to invoke. `filterSubLayer` is evaluated before every redraw, and is intended to be a more performant solution to setting `visible` props dynamically during continuous viewport updates. Generally speaking, `filterSubLayer` is favorable if the visibilities of sub layers change frequently, and the logic to determine visibility is very cheap to compute.
135
+
136
+
An example of leveraging this method is to switch sub layers on viewport change:
137
+
138
+
```js
139
+
/*
140
+
* A layer that renders different dataset based on zoom level
141
+
*/
142
+
// Implementation A
143
+
classLODLayerextendsCompositeLayer {
144
+
145
+
// Force update layer and re-render sub layers when viewport changes
146
+
shouldUpdateState({changeFlags}) {
147
+
returnchangeFlags.somethingChanged;
148
+
}
149
+
150
+
renderSubLayers() {
151
+
const {lowResData, hiResData} =this.props;
152
+
const {zoom} =this.context.viewport;
153
+
return [
154
+
newScatterplotLayer({
155
+
id:'points-low-zoom',
156
+
data: lowResData,
157
+
visible: zoom <8
158
+
}),
159
+
newScatterplotLayer({
160
+
id:'points-high-zoom',
161
+
data: highResData,
162
+
visible: zoom >=8
163
+
})
164
+
]
165
+
}
166
+
}
167
+
168
+
// Implementation B
169
+
classLODLayerextendsCompositeLayer {
170
+
renderSubLayers() {
171
+
const {lowResData, hiResData} =this.props;
172
+
return [
173
+
newScatterplotLayer({
174
+
id:'points-low-zoom'
175
+
data: lowResData,
176
+
}),
177
+
newScatterplotLayer({
178
+
id:'points-high-zoom',
179
+
data: highResData
180
+
})
181
+
]
182
+
}
183
+
184
+
filterSubLayer({layer, viewport}) {
185
+
if (viewport.zoom<8) {
186
+
returnlayer.id==='points-low-zoom';
187
+
} else {
188
+
returnlayer.id==='points-high-zoom';
189
+
}
190
+
}
191
+
}
192
+
```
193
+
119
194
##### `getPickingInfo`
120
195
121
196
Called when a sublayer is being hovered or clicked, after the `getPickingInfo`
0 commit comments