danmarshall/deckgl-typings

objectInfo in Text & Icon layer accessors

Closed this issue · 2 comments

Why is objectInfo only in the accessors for Text & Icon layers? And/or why is it added to those when we're not required to supply them to accessor functions if we're using the layers as-is?

Text layer and icon layer docs

TextLayerProps typing here, added in #142.

I'm writing a wrapper for the Text layer with a custom getPosition function. This typing is forcing me to add a an objectInfo argument where it wouldn't be necessary if I were using TextLayer without a wrapper.

Simplified version of the wrapper:

interface WithLatLng { 
    latKey: string;
    lngKey: string;
}
export class CustomTextLayer<D> extends CompositeLayer<D, WithLatLng extends TextLayerProps<D>> {
    renderLayers(): unknown[] {
        const { latKey, lngKey, ...otherProps } = this.props;
        const props: TextLayerProps<D> = {
            ...otherProps,
            getPosition: (dataPoint: D): Position2D => { // typescript complains here: Expected 2 arguments, but got 1.
                if (latKey in dataPoint && lngKey in dataPoint)
                    return [dataPoint[lngKey], dataPoint[latKey]] as Position2D;
                return defaults.layer.position as Position2D;
            }
        }
        // other logic
        return [new TextLayer<D>(props)];
    }
}

Is there a way around that? And/or what's the proper way to write such a custom accessor?

Can you send a PR where objectInfo is optional?

Yep, will do!