Openlayers 4.11:以编程方式选择特征时未应用任何样式 [英] Openlayers 4.11 : no style applied when programatically selecting a feature
很明显,只要选择中涉及的功能已经应用了非默认样式,这就是Openlayers中的正常行为. /p>
因此,如果要解决此问题,则需要使用select/unselect
事件来应用所需的样式,并根据需要将其删除.
I'm using the accepted answer from here to programatically select a feature on my map.
All ok, except that my custom select style is not applied (the element looks just like before).
I'm using this code to setup my Select
interaction:
var selectSingleOrDoubleClick = new ol.interaction.Select({
style: this.selectCustomStyle,
condition: function(mapBrowserEvent) {
return ol.events.condition.singleClick(mapBrowserEvent) || ol.events.condition.doubleClick(mapBrowserEvent);
},
filter: function(feature, layer) {
...
}
});
I'm doing this in order to programmatically select my feature:
selectSingleOrDoubleClick.getFeatures().clear();
selectSingleOrDoubleClick.getFeatures().push(featureToSelect);
selectControl.dispatchEvent({
type: 'select',
selected: [featureToSelect],
deselected: []
});
I should not that my feature IS considered
selected (for example if I select another feature via user interaction, my previously-selected feature becomes unselected, etc.
Apparently, this is normal behavior in Openlayers, whenever the Features involved in your selection already have a non-default style applied.
So if you want to fix this, then you need to use select/unselect
events to apply whatever style you need to have applied, and remove it as necessary.
这篇关于Openlayers 4.11:以编程方式选择特征时未应用任何样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!