layer2 = {
const {Layer} = deck;
class ScatterplotLayer extends Layer {
// model: getModel(gl)
// });
// }
initializeState() {
const {gl} = this.context;
this.getAttributeManager().addInstanced({
instancePositions: {
size: 3,
type: gl.FLOAT,
accessor: () => [0, 0, 0], // Hardcoded value for testing
defaultValue: [0, 0, 0]
},
instanceRadius: {
size: 1,
accessor: () => 1, // Hardcoded value for testing
defaultValue: 1
},
instanceColors: {
size: 4,
type: gl.UNSIGNED_BYTE,
normalized: true,
accessor: () => [255, 0, 0, 255], // Hardcoded value for testing
defaultValue: [0, 0, 0, 255]
}
});
const model = getModel(gl);
if (model) {
this.setState({model});
} else {
console.error('Model failed to initialize');
}
}
// updateState() {
// // Retrieve the model from layer state
// this.state.model.setUniforms({
// smoothRadius: this.props.smoothRadius
// });
// }
updateState({props, oldProps, changeFlags}) {
if (changeFlags.dataChanged) {
console.log('Data changed, updating attributes');
this.getAttributeManager().invalidateAll();
}
if (this.state.model) {
try {
this.state.model.setUniforms({smoothRadius: this.props.smoothRadius});
} catch (error) {
console.error('Error updating model uniforms:', error);
}
} else {
console.error('Model not initialized');
}
}
}
ScatterplotLayer.layerName = 'ScatterplotLayer';
ScatterplotLayer.defaultProps = defaultProps;
const layer = new ScatterplotLayer({
id: `scatterplot-${Date.now()}`,
data,
getPosition: d => d.position,
getRadius: d => d.size,
getColor: d => d.color
});
deckgl.setProps({layers: [layer]});
return layer;
}