为矢量 openlayers 层中的线条设置不同的样式
set different style for lines in vector openlayers layer
所以,我使用 openlayers 3.9.0,我有一个包含线串、多边形和点的矢量图层。
默认情况下,LineString 看起来像黑线,带有小笔划。我试着让它们更厚一点,并且它们的颜色必须是可见的,所以当渲染许多特征时它们不会融合在一起。
这是我的风格
var stroke = new ol.style.Stroke({
color: 'rgba(0,0,0,0.4)',
lineCap: "butt",
lineJoin: "bevel",
width:1
});
function styleFunction(feature, resolution) {
var color = feature.get('color');
var name = feature.get('name');
var geom = feature.getGeometry().getType();
var fill = new ol.style.Fill({
color: color
});
//this does not work
if (geom == 'LineString') {
stroke.width=42;
}
var circle = new ol.style.Circle({
radius: 6,
fill: fill,
stroke: stroke,
color:color
});
var text= new ol.style.Text({
font: '20px Verdana',
text: name,
fill: new ol.style.Fill({
color: [64, 64, 64, 0.75]
})
})
var cStyle = new ol.style.Style({
fill: fill,
stroke: stroke,
image : circle,
text : text
});
return [cStyle];
}
我无法完成这项工作。有什么建议吗?
谢谢
OpenLayers 3 样式是不可变的,无法更改。
与其尝试修改 Stroke
的宽度,不如创建一个包含所需选项的新宽度。
所以,我使用 openlayers 3.9.0,我有一个包含线串、多边形和点的矢量图层。
默认情况下,LineString 看起来像黑线,带有小笔划。我试着让它们更厚一点,并且它们的颜色必须是可见的,所以当渲染许多特征时它们不会融合在一起。
这是我的风格
var stroke = new ol.style.Stroke({
color: 'rgba(0,0,0,0.4)',
lineCap: "butt",
lineJoin: "bevel",
width:1
});
function styleFunction(feature, resolution) {
var color = feature.get('color');
var name = feature.get('name');
var geom = feature.getGeometry().getType();
var fill = new ol.style.Fill({
color: color
});
//this does not work
if (geom == 'LineString') {
stroke.width=42;
}
var circle = new ol.style.Circle({
radius: 6,
fill: fill,
stroke: stroke,
color:color
});
var text= new ol.style.Text({
font: '20px Verdana',
text: name,
fill: new ol.style.Fill({
color: [64, 64, 64, 0.75]
})
})
var cStyle = new ol.style.Style({
fill: fill,
stroke: stroke,
image : circle,
text : text
});
return [cStyle];
}
我无法完成这项工作。有什么建议吗?
谢谢
OpenLayers 3 样式是不可变的,无法更改。
与其尝试修改 Stroke
的宽度,不如创建一个包含所需选项的新宽度。