无论我尝试什么,我都无法在OpenLayers 3中使用Stroke不透明度.我试图实现的是用0.5不透明度绘制一条到OSM瓦片地图的线.
这是示例代码:
var lineString = new ol.geom.LineString([
[4.9020, 52.3667],
[4.9030, 52.3667],
[4.9040, 52.3667],
[4.9050, 52.3667]
]);
lineString.transform('EPSG:4326', 'EPSG:3857');
var lineLayer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: lineString,
name: 'Line'
})]
}),
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'yellow',
opacity: 0.5,
width: 15
})
})
});
var view = new ol.View({
center: ol.proj.transform([4.9020, 52.3667], 'EPSG:4326','EPSG:3857'),
zoom: 18
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
lineLayer
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
view: view
});
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到它:http: //jsfiddle.net/abgcvqw3/1/
eri*_*lem 15
不透明度通过color选项设置,作为颜色值的第四个元素(对于RGBA中的"Alpha",A).
例如,您可以使用半透明黄色:
color: [255, 255, 0, 0.5]
Run Code Online (Sandbox Code Playgroud)
这是另一种表示法:
color: 'rgba(255,255,0,0.5)'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8362 次 |
| 最近记录: |