Openlayers 3 基于属性值设置要素的样式

Openlayers 3 基于属性值设置要素的样式,openlayers-3,Openlayers 3,一种样式如何基于属性/特性进行功能设置?目前我正在做以下工作: olLayer=新的olLayer.Vector({ 来源:新ol.source.Vector({ 特征:featureArray } ), 样式:(函数(){ var styleR3=新的ol.style.style({ 图片:新ol.style.Circle({ 半径:10, 填充:新的ol.style.fill({ 颜色:“蓝色” } ) } ) } ); var styleCatchAll=新的ol.style.style

一种样式如何基于属性/特性进行功能设置?目前我正在做以下工作:

olLayer=新的olLayer.Vector({
来源:新ol.source.Vector({
特征:featureArray
} ),
样式:(函数(){
var styleR3=新的ol.style.style({
图片:新ol.style.Circle({
半径:10,
填充:新的ol.style.fill({
颜色:“蓝色”
} )
} )
} );
var styleCatchAll=新的ol.style.style({
图片:新ol.style.Circle({
半径:5,
填充:新的ol.style.fill({
颜色:“红色”
} )
} )
} );
返回函数(特性、分辨率){
如果(要素属性[“排名”]=“3”){
返回样式3;
}否则{
全部返回;
}
};
}() )
} );在这里

style
函数在返回时需要一个
array
,而您使用的是自执行函数,我不知道这是否有效,无论如何,
style
函数变成:

style: function(feature, resolution){
    var styleR3 = new ol.style.Style( {
        image: new ol.style.Circle( {
            radius: 10,
            fill: new ol.style.Fill( {
                color: 'blue'
            } )
        } )
    } );

    var styleCatchAll = new ol.style.Style( {
        image: new ol.style.Circle( {
            radius: 5,
            fill: new ol.style.Fill( {
                color: 'red'
            } )
        } )
    } );

    if ( feature.get('rank') == 3) {
        return [styleR3];
    } else {
        return [styleCatchAll];
    }
}

您是否尝试了
feature.attributes[“Rank”]=“3”
而不是triple?或者更好<代码>功能。获取('Rank')==3
谢谢Jonatas。它确实找到了使用该语法的特性。你知道为什么styleR3没有被应用吗?我已经独立地尝试了这些样式,它们很有效。我会做一把小提琴来测试你的代码。