Reputation: 653
I'm trying to pass different rgba colors to different points in mapbox. I added a realiveOpacity
property to each dot and would like to generate the correct color string from its data. I tried both expression but I guess the syntax is somehow wrong. How would it go correctly?
'circle-color': ["string", "rgba(255, 0, 0, ['get', 'realiveOpacity'])"]
["string", "rgba(255, 0, 0,"+ ['get', 'realiveOpacity'] + " )"]
This Constructor works:
["string", "rgba(255, 0, 0,0.5"]
Thanks a lot!
Upvotes: 0
Views: 1013
Reputation: 29172
Use the rgba-function:
Creates a color value from red, green, blue components, which must range between 0 and 255, and an alpha component which must range between 0 and 1. If any component is out of range, the expression is an error.
["rgba", number, number, number, number]: color
https://www.mapbox.com/mapbox-gl-js/style-spec#expressions-rgba
"circle-color": ["rgba", 255, 0, 0, ["get", "realiveOpacity"]]
[ https://jsfiddle.net/tjh4u0f6/ ]
Upvotes: 1