Select 个在 Openlayers 3 中单击和双击的功能
Select features with click AND double-click in Openlayers 3
我想在openlayers 3中同时点击和双击select特征。创建ol.interaction.Select时的条件选项只需要一个功能,因此需要一种解决方法
我尝试编写自己的自定义条件函数来调用适当的函数,我在想类似...
this.selectType = (feature) => {
if (feature){
if(feature.onclick){
return ol.events.condition.singleClick
} else {
return ol.events.condition.doubleClick
}
}
}
this.selectInteraction = new ol.interaction.Select({
condition: this.selectType(),
toggleCondition: ol.events.condition.shiftKeyOnly,
layers: this.layerFilter,
features: this.features,
style: this.selectStyle,
});
...但没有成功。
我意识到,我可以为 selecting 功能创建两个单独的交互,但我宁愿不这样做,因为这将涉及根据 Select 交互复制大量代码。
有谁知道这在 openlayers 中是否可行以及如何处理这种情况?
非常感谢
条件是一个接受地图浏览器事件和 returns 布尔值的函数。基于 OpenLayers 示例中的 Alt+Cick https://openlayers.org/en/v4.6.5/examples/select-features.html 到 select 单击或双击,您将需要类似
的东西
this.selectType = (mapBrowserEvent) => {
return ol.events.condition.singleClick(mapBrowserEvent) ||
ol.events.condition.doubleClick(mapBrowserEvent);
}
this.selectInteraction = new ol.interaction.Select({
condition: this.selectType, // pass the function, don't call it!
toggleCondition: ol.events.condition.shiftKeyOnly,
layers: this.layerFilter,
features: this.features,
style: this.selectStyle,
});
我想在openlayers 3中同时点击和双击select特征。创建ol.interaction.Select时的条件选项只需要一个功能,因此需要一种解决方法
我尝试编写自己的自定义条件函数来调用适当的函数,我在想类似...
this.selectType = (feature) => {
if (feature){
if(feature.onclick){
return ol.events.condition.singleClick
} else {
return ol.events.condition.doubleClick
}
}
}
this.selectInteraction = new ol.interaction.Select({
condition: this.selectType(),
toggleCondition: ol.events.condition.shiftKeyOnly,
layers: this.layerFilter,
features: this.features,
style: this.selectStyle,
});
...但没有成功。
我意识到,我可以为 selecting 功能创建两个单独的交互,但我宁愿不这样做,因为这将涉及根据 Select 交互复制大量代码。
有谁知道这在 openlayers 中是否可行以及如何处理这种情况?
非常感谢
条件是一个接受地图浏览器事件和 returns 布尔值的函数。基于 OpenLayers 示例中的 Alt+Cick https://openlayers.org/en/v4.6.5/examples/select-features.html 到 select 单击或双击,您将需要类似
的东西this.selectType = (mapBrowserEvent) => {
return ol.events.condition.singleClick(mapBrowserEvent) ||
ol.events.condition.doubleClick(mapBrowserEvent);
}
this.selectInteraction = new ol.interaction.Select({
condition: this.selectType, // pass the function, don't call it!
toggleCondition: ol.events.condition.shiftKeyOnly,
layers: this.layerFilter,
features: this.features,
style: this.selectStyle,
});