javascript - Mapbox表达式字符串生成

标签 javascript expression mapbox mapbox-gl-js

我试图将不同的 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"]]

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

关于javascript - Mapbox表达式字符串生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52859122/

相关文章:

javascript - Mapbox 3D 线解决方法

ios - 如何在 Mapbox 中禁用用户位置注释的标注?

mapbox - 如何在 Mapbox 中旋转由 geoJSON 指定的图标?

javascript - 下拉更多错误

javascript - 不会为 p :remoteCommand 调用 Action 和 ActionListener

c# - 动态属性选择器 lambda 函数

c++ - 从 C++ 中的后缀表达式字符串打印单个操作

每隔 30 分钟执行一次 Spring cron 表达式

javascript - jQuery - 正则表达式工作异常

javascript - 按钮 onclick 和 href 之间的区别