我在 Openlayers 中有一个图层,它允许用户绘制一条线,其中每个顶点都出现节点。例如:
但是,我希望第一个节点与其余节点不同,以表示行的开头。我正在使用 styleMap 来生成图层样式,但似乎无法覆盖第一个节点的属性。
这是我的样式图代码:
var myDefault = {
strokeColor: "#FF9900",
fillColor: "#FF9900",
strokeOpacity: 1,
strokeWidth: 4,
fillOpacity: .9,
pointRadius: 6
};
var myStyleMap = new OpenLayers.StyleMap({
"default": new OpenLayers.Style(myDefault, {context:context})
});
非常感谢任何帮助!
最佳答案
您可以定义自定义样式函数,而不仅仅是使用未处理的要素属性。为此,您必须在 OpenLayers.Style 中定义“上下文”属性,例如使用标签条件。
var defStyle = new OpenLayers.Style({
strokeColor: "#ee9900",
strokeWidth: 2,
fillColor: "#ee9900",
pointRadius: 5 ,
strokeWidth: 2,
strokeOpacity: 1,
label: '${label}',
fontSize: '11px',
fontColor: '#575555',
fontFamily: 'Verdana',
labelAlign: 'cm',
labelOutlineWidth: 2
},
{
context: {
label:function(feature) {
if(feature.attributes['measure']) {
return feature.attributes.measure+" "+ feature.attributes.units;
} else {
return '';
}
}
}
});
您可以为第一个节点添加任何属性并搜索它,以应用您的自定义样式。
关于javascript - 更改openlayers 2中单线节点的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30599356/