Select 当功能有自己的风格时不使用交互风格

Select interaction style not used when feature has its own style

我的问题如下: OpenLayers 3 select style

当要素有自己的样式(而不是使用其层的样式)时,不使用 ol.interaction.Select "style" 属性,或者如果 "style" 属性是一个函数,没有调用函数。

这个 http://jsfiddle.net/y13xLmx6/13/OpenLayers 3 select style 问题的答案中提供的 jfiddle 相同,但增加了应用于线要素的样式:

featureLine.setStyle(new ol.style.Style({
  stroke: new ol.style.Stroke({
    color: 'rgba(24, 24, 24, 0.8)', 
    width: 8
  })
}))

当线特征被 select 编辑时,黄色 select 交互风格不被应用,console.log() 语句 executed.The featurePoint 也没有被应用,它没有分配给它的样式,确实获得了交互样式并执行了 console.log() 语句。

那么如何将交互风格应用于定义了自己的风格的功能?

不确定为什么 select 行 selected 时没有记录交互,但您可以在 select 事件上设置不同的样式:

select.on('select', function(evt){
  evt.selected.forEach(function(each) {
    each.setStyle(styles[each.get('type')]);
  });
  evt.deselected.forEach(function(each) {
    each.setStyle(null); // more likely you want to restore the original style
  });
});