Is there a way to trigger openlayers event from console. In this case: ol.interaction.Select event which listens 'select' (ol.SelectEvent.select). It triggers when feature is selected or deselected by mouse click.
1 Answer
In the mean time I have found the answer. There is OpenLayers built in function for dispatchingEvents :
ol.events.EventTarget.prototype.dispatchEvent.call(this,event);
this references the object on which we add event listener
In my case:
var fakeOnSelectEvent = new ol.interaction.Select.Event(ol.interaction.Select.EventType.SELECT, [], [], false);
var selectInteraction = new ol.interaction.Select({...});
ol.events.EventTarget.prototype.dispatchEvent.call(selectInteraction,fakeOnSelectEvent);
-
-
@Mike in my case I only wanted my event listener select.on('select',... to be triggered because my logic is implemented that way. To select the feature this way I think you can manualy add features in first empty array parm of fakeOnSelectEvent and then when listening you can add them from that array like select.getFeatures().push(e.selected). That is the way I would do it.– GoranNov 12, 2019 at 22:19