更改openlayers 2中单线节点的样式

Change style of single line node in openlayers 2

我在 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 中定义 'context' 属性,例如使用标签条件。

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 '';
            }
        }
}
});

您可以为第一个节点放置任何属性并搜索它,以应用您的自定义样式。