OpenLayers 3 交互风格与 ol.feature.setStyle 冲突
OpenLayers 3 Interaction Style Conflict with ol.feature.setStyle
在 OpenLayers 3 中,如果我使用 setStyle(...insert style...)
设置特征样式,则不再显示 ol.interaction.select
的默认交互样式。如果我尝试像这样定义样式或样式函数:
var select = new ol.interaction.Select({
style: ...insert style here...
});
map.addInteraction(select);
不行。如果我用 ol.feature.setStyle(...insert style...)
删除我的自定义样式集,它工作正常。这有意义吗?我想知道使用 setStyle()
设置功能样式是否会以某种方式覆盖默认交互样式...
有什么线索吗?
实例化 ol.interaction.select
时,我没有使用样式或样式函数,而是使用 select
事件来处理选定和取消选定的样式。
var select = ol.interaction.select();
select.on('select', function (e) {
if(e.selected.length > 0) {
e.selected[0].setStyle(...insert selected style here...);
}
if(e.deselected.length > 0) {
e.deselected[0].setStyle(..insert original style here...);
}
});
由于某些原因,当最初使用 setStyle
定义功能的样式时,您不能在创建交互时使用构造函数样式或样式函数。上面这个工作正常,但它有一点额外的代码。
在 OpenLayers 3 中,如果我使用 setStyle(...insert style...)
设置特征样式,则不再显示 ol.interaction.select
的默认交互样式。如果我尝试像这样定义样式或样式函数:
var select = new ol.interaction.Select({
style: ...insert style here...
});
map.addInteraction(select);
不行。如果我用 ol.feature.setStyle(...insert style...)
删除我的自定义样式集,它工作正常。这有意义吗?我想知道使用 setStyle()
设置功能样式是否会以某种方式覆盖默认交互样式...
有什么线索吗?
实例化 ol.interaction.select
时,我没有使用样式或样式函数,而是使用 select
事件来处理选定和取消选定的样式。
var select = ol.interaction.select();
select.on('select', function (e) {
if(e.selected.length > 0) {
e.selected[0].setStyle(...insert selected style here...);
}
if(e.deselected.length > 0) {
e.deselected[0].setStyle(..insert original style here...);
}
});
由于某些原因,当最初使用 setStyle
定义功能的样式时,您不能在创建交互时使用构造函数样式或样式函数。上面这个工作正常,但它有一点额外的代码。