CartoDB / carto-react-template

CARTO for React. The best way to develop Location Intelligence (LI) Apps usign CARTO platform and React
https://sample-app-react.carto.com
MIT License
39 stars 26 forks source link

highlightColor defined as a function on CartoLayer doesnt seem to work #274

Open plgagnon2 opened 3 years ago

plgagnon2 commented 3 years ago

This doesnt seem to work. But CartoLayer inherit from MVTLayer which inherit from Layer in the end (I think) https://deck.gl/docs/api-reference/core/layer#highlightcolor

return new CartoLayer({
  ...cartoLayerProps,
  id: id,
  pickable: true,
  autoHighlight: true,
  highlightColor: (info) => {
    console.log('test')
  },
});
AdriSolid commented 3 years ago

Indeed, CartoLayer inherits from MVTLayer.

Did you try to specify uniqueIdProperty? Needed for highlighting a feature split across two or more tiles if no feature id is provided. More info here.

You have to options:

  1. Set it as a CartoLayer prop:
new CartoLayer({
  ...
  uniqueIdProperty: 'your_unique_id_prop',
  autoHighlight: true,
  highlightColor: [0, 0, 255],
});
  1. Set it in your useCartoLayerProps hook like:
const uniqueIdProperty = 'your_unique_id_prop';
const cartoLayerProps = useCartoLayerProps({ source, uniqueIdProperty });

Check CARTO docs for more info here.