dev-docs/RFCs/v5.3/constant-accessor-rfc.md
Overview:
Many layers use accessors that return constants, for example:
new ScatterplotLayer({
radiusScale: 100,
getPosition: d => d.position,
getRadius: d => 1,
getColor: d => [255, 200, 0]
});
The curent implementation to handle this use case has several problems:
position (Number[3]) - corresponds to getPositionradius (Number) - corresponds to getRadiuscolor (Number[4]) - corresponds to getColorradius is provided, getRadius is ignored. This is so that layers are backward compatible.The above example now becomes:
new ScatterplotLayer({
radiusScale: 100,
getPosition: d => d.position,
radius: 1,
color: [255, 200, 0]
});
Core changes:
LayerManager checks for value overrides of the specified accessors. The values are automatically applied as generic attributes if provided.getPosition (Function | Number[3])getRadius (Function | Number)getColor (Function | Number[4])The above example now becomes:
new ScatterplotLayer({
radiusScale: 100,
getPosition: d => d.position,
getRadius: 1,
getColor: [255, 200, 0]
});
Core changes:
LayerManager checks accessor types. The value is automatically applied as generic attributes, instead of calling the updater, if the accessor is not a function.// TextLayer
return new MultiIconLayer({
...
getSize: d => getSize(d.object)
});
Now becomes
// TextLayer
return new MultiIconLayer({
...
getSize: (typeof getSize === 'function')? d => getSize(d.object) : getSize
});