openlayers3所选功能的样式是否相同(只有一个更改的属性)? [英] openlayers3 same style for selected features (only one changed property)?
本文介绍了openlayers3所选功能的样式是否相同(只有一个更改的属性)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有样式定义的ol3层.我想对选择交互使用相同的样式:
I have an ol3 layer with a style definition. I would like to use the same style for the select interaction:
style = function(feature, resolution) {
var iconFont = 'FontAwesome';
var iconFontText = '\uf1f8'; // fa-trash
var iconSize = 24;
var col = 'black';
var styles = [];
var styleIcon = new ol.style.Style({
text: new ol.style.Text({
font: 'Normal ' + iconSize + 'px ' + iconFont,
text: iconFontText,
fill: new ol.style.Fill({color: col})
})
});
styles.push(styleIcon);
}
return styles;
};
new ol.layer.Vector({
source: that.source,
style: style
});
new ol.interaction.Select({
features: that.selectedFeatures,
style: style
})
我只想更改样式的一个属性(iconSize)以突出显示所选功能.有可能吗?我不想定义两个单独的样式,但是如果可以的话,可以以编程方式复制样式并替换iconsize值.
I only want to change one property (iconSize) of the style to highlight the selected features. Is that somehow possible? I do not want to define two seperate styles, but I would be ok if it was somwhow possible to programmatically copy the style and replace the iconsize value.
推荐答案
现在我找到了可行的解决方案:
Now I found a working solution:
您可以在样式函数中添加一个附加参数(例如,突出显示[bool]):
You can add an additional argument (e.g. highlight [bool]) to the style function:
style = function(feature, resolution, highlight) {
...
}
,而不是
new ol.interaction.Select({
features: that.selectedFeatures,
style: style
})
您可以使用
new ol.interaction.Select({
features: that.selectedFeatures,
style: function(feature,resolution){
return style(feature,resolution,true);
}
})
这篇关于openlayers3所选功能的样式是否相同(只有一个更改的属性)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文