一种风格如何基于属性/属性来表现?目前我正在做以下事情:
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;
}
};
}() )
} );Run Code Online (Sandbox Code Playgroud)
选择的功能确实有效,但 styleR3 未应用。
这是...... http://jsfiddle.net/jonataswalker/g3s96auc/
该style函数需要一个arrayon return,而你正在使用一个自执行函数,我不知道这是否有效,无论如何,该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];
}
}
Run Code Online (Sandbox Code Playgroud)