一种风格功能如何基于属性/属性?目前我正在做以下事情:
olLayer = new ol.layer.Vector( {
source: new ol.source.Vector( {
features: featureArray
} ),
style: ( function() {
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'
} )
} )
} );
return function( feature, resolution ) {
if ( feature.attributes[ "Rank" ] === "3" ) {
return styleR3;
} else {
return styleCatchAll;
}
};
}() )
} );

选择功能确实有效,但styleR3无法应用。
答案 0 :(得分:1)
这是...... http://jsfiddle.net/jonataswalker/g3s96auc/
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];
}
}