I am using Mapbox GL in a React project and would like to set the circle color of the data points based on a property from the source geoJSON. My goal is to color the circle green for low values and red for high values. Anything in between will be a color gradient. So for example, if my data points range in value from 0 to 100. 0 should be green, 100 would be red and 50 would be amber.
Here is what I have tried:
paint: {
'circle-radius': 10,
'circle-color': [
'let',
'maxVal',
['max', ['get', 'P1_H']],
[
'interpolate',
['linear'],
['get', 'P1_H'],
0,
'green',
['var', 'maxVal'],
'red'
]
]
}
But this gives me the error:
Input/output pairs for "interpolate" expressions must be defined using literal numeric values (not computed expressions) for the input values.
The biggest problem for me is that I don't know ahead of time what the max value will be in the source data. It might be 20 or it might be 80, I just don't know. So hard coding a number doesn't work for me. The minimum value may change as well, but for now I'm focused on the max value. So my question is, how can I interpolate the circle color based on the feature that has the highest value in the chosen property?