简体   繁体   中英

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. 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. 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:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM