我试图将不同的 rgba 颜色传递给 Mapbox 中的不同点。我向每个点添加了一个 realiveOpacity
属性,并希望从其数据生成正确的颜色字符串。我尝试了两种表达方式,但我猜语法有些错误。怎样才能正确进行呢?
'circle-color': ["string", "rgba(255, 0, 0, ['get', 'realiveOpacity'])"]
["string", "rgba(255, 0, 0,"+ ['get', 'realiveOpacity'] + ")"]
该构造函数的工作原理:
["字符串", "rgba(255, 0, 0,0.5"]
非常感谢!
最佳答案
使用 rgba 函数:
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"]]
关于javascript - Mapbox表达式字符串生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52859122/