mapbox 表达式字符串生成

mapbox expression string generation

我正在尝试将不同的 rgba 颜色传递到 mapbox 中的不同点。我向每个点添加了一个 realiveOpacity 属性 并希望从其数据生成正确的颜色字符串。我尝试了两个表达式,但我猜语法有问题。它如何正确进行?

'circle-color': ["string", "rgba(255, 0, 0, ['get', 'realiveOpacity'])"]

["string", "rgba(255, 0, 0,"+ ['get', 'realiveOpacity'] + " )"]

这个构造函数工作: ["string", "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"]]

[https://jsfiddle.net/tjh4u0f6/]