我正在尝试在OL3中设置矢量要素的填充不透明度,并且如果我有十六进制值,则无法弄清楚如何执行此操作...我已经看到了rgba的示例.有什么建议?
这就是我所拥有的:
style : function(feature, resolution) {
return [new ol.style.Style(
{
stroke : new ol.style.Stroke(
{
color : feature.get('color'),
width : 2
}),
fill : new ol.style.Fill(
{
color : feature.get('color'), //'#FF0000'
opacity : 0.2 // I thought this would work, but it's not an option
})
})]
}
Run Code Online (Sandbox Code Playgroud)
won*_*dim 12
这很晚,但可能对某人有帮助.使用rgba属性也是可能的.
fill: new ol.style.Fill({color: 'rgba(255, 255, 0, 0.63)'}),
Run Code Online (Sandbox Code Playgroud)
eri*_*lem 11
你可以使用这个ol.color.asArray功能.该函数将颜色字符串转换为颜色数组.
这就是你可以使用的:
var hexColor = feature.get('color');
var color = ol.color.asArray(hexColor);
color = color.slice();
color[3] = 0.2; // change the alpha of the color
Run Code Online (Sandbox Code Playgroud)
slice()用于创建新的颜色数组.这是为了避免破坏ol.color.asArray函数维护的"颜色字符串到颜色数组"缓存.
请参阅http://openlayers.org/en/master/apidoc/ol.color.html?unstable=true#asArray.
| 归档时间: |
|
| 查看次数: |
10419 次 |
| 最近记录: |