deckgl-typings icon indicating copy to clipboard operation
deckgl-typings copied to clipboard

`MVTLayer` requires documention

Open ghost opened this issue 4 years ago • 4 comments

It requires template parameters, but it's unclear what should be used. I ended up using as any on the props, too. I think there should be more samples and documentation to make this easier to understand.

ghost avatar Aug 11 '21 14:08 ghost

I am also looking into how to avoid using as any here. For example, when using the default renderSubLayers (which defaults to GeoJsonLayer), my approach for adding GeoJson-specific styling props would be to write

interface DataType {}
new MVTLayer<DataType, MVTLayerProps<DataType> & GeoJsonLayerProps<DataType>>({
   //... add a getLineColor prop here
})

However, that still results in a type error, for example

Object literal may only specify known properties, and 'getLineColor' does not exist in type 'TileLayerProps<any>'

Looking at the type definitions, I am wondering if there is a mistake in https://github.com/danmarshall/deckgl-typings/blob/master/deck.gl__geo-layers/index.d.ts#L247 - shouldn't the constructor arguments read ...props: P[] ? @danmarshall Changing that line locally seems to enable that kind of usage, but I don't know the whole set-up well enough to understand if it will cause any problems.

mz8i avatar Sep 27 '21 14:09 mz8i

On further checking, this doesn't really work as then you can pass anything for the props. Perhaps TileLayerProps needs to have an additional generic parameter for the sub-layer properties?

mz8i avatar Sep 27 '21 15:09 mz8i

Might be helpful if someone can provide sample code of what the desired behavior should be, then we can work backwards to see how to make the typings enable that.

danmarshall avatar Sep 27 '21 17:09 danmarshall

I might jump in to give @danmarshall a usage example. I would like to be able to iterate over different kinds of data and provide one MVTLayer per kind. The properties for how to display a particular kind should be stored in a Map:

const propertyFor = new Map<string, any>([
  [
    "rivers",
    {
      getLineColor: [0, 0, 192],
    },
  ],
  [
    "streets",
    {
      getLineColor: [80, 80, 80],
    },
  ],
]);

and then I like to loop over my kinds and create the layers:

for (const kind of ["rivers", "streets"]) {
  layers.push(new MVTLayer({
    id: kind,
    data: dataFor.get(kind),
    ...propertyFor.get(kind),
  });
}

The value type in the Map should now be something like MVTLayerProps.

kopp avatar Nov 19 '21 15:11 kopp