【发布时间】:2016-08-12 15:15:56
【问题描述】:
我正在尝试为 selectInteraction 触发 select 事件。这是我到目前为止的代码:
// create and instance of the selectInteraction
var selectInteraction = new ol.interaction.Select( {
layers: myLayers
} );
// add select event handler
// NOT BEING CALLED WHEN FEATURES ARE PUSHED TO SELECTED ARRAY
selectInteraction.on( "select", function ( evt ) {
var selected = evt.selected;
var deselected = evt.deselected;
selected.forEach( function( feature ) {
feature.setStyle( myCustomStyleFunction );
} );
deselected.forEach( function( feature ) {
feature.setStyle( null );
} );
}, selectInteraction );
// add the interaction to the map
myMap.getInteractions().extend( [ selectInteraction ] );
// function called with feature to be selected
function programmaticallySelectFeature( feature ) {
// get the selectInteraction for the map
myMap.getInteractions().forEach( function ( interaction ) {
if ( interaction instanceof ol.interaction.Select ) {
selectInteraction = interaction;
}
});
// push the feature to the selectInteraction
selectInteraction.getFeatures().push( feature );
}
我了解当功能被推送到所选数组时,选择事件不会触发。否则它会按预期工作。那么如何才能让它发挥作用呢?我可以监听另一个事件吗?
【问题讨论】:
标签: openlayers-3