Deck.gl how to access min and max bound with react hook

Viewed 31

I'm developing application with React Hooks and Deck.gl.

I need to save the min and max value my heatmap layer to display them.
So I created 2 state variables to save them and display them. Unfortunately that doesn't work.
I guess this is because of the getWeight actually being call on the GPU.

So, how could I retrieve the min and max value of my data ? Should I loop through before rendering <DeckGL/> ?

function getWeight(data) {
  const tmp = sumValuesBetween(data.rainByHour, start, end).toFixed(2);
  if (tmp > max) {
    setMax(tmp);
  }
  if (tmp < min) {
    setMin(tmp);
  }
  return tmp;
}

const layers = [
  new HeatmapLayer({
    data,
    getPosition: d => [d.longitude, d.latitude],
    getWeight, //: d => _.sum(Object.values(d.rainByHour)),
  })
]```
0 Answers
Related