[英]How do I manually cause a 'select' event on an Openlayers 3 ol.interaction.Select?
I'd like to cause an ol.interaction.Select obj to 'select' a feature when the user clicks on a button which is related to that feature. 我想使ol.interaction.Select obj在用户单击与该功能相关的按钮时“选择”该功能。 I'd like to be able to reuse the event handling code I already use for when a user clicks on a feature.
我希望能够重用用户单击功能时已经使用的事件处理代码。
Is there a way to do this with the Select interaction? 有没有办法通过选择交互来做到这一点?
<!-- UPDATE -->
Maybe when this PR get merged we can dispatch select
event. 也许当此PR合并时,我们可以调度
select
事件。 About reusing code, I guess you can solve this wrapping it on a function, and when push a feature to the collection, call your function with that feature. 关于重用代码,我想您可以解决将其包装在函数上的问题,将功能推入集合时,请使用该功能调用函数。
<!-- End of update -->
Get the ol.interaction.Select
collection and push
or pop
as you want: 获取
ol.interaction.Select
集合,然后根据需要push
或pop
:
var select = new ol.interaction.Select({
//some options
});
map.addInteraction(select);
var collection = select.getFeatures();
collection.push(some_feature);
//or push an array of features
collection.extend(some_array_features);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.