如何获取已选择或取消选择的功能的ID?每次选择或取消选择某个特征时,我都需要调用一个特定的函数来传递一个特征或它的id。有点像:
selectInteraction = new ol.interaction.Select( {
layers: layers
} );
map.getInteractions().extend( [ selectInteraction ] );
selectInteraction.on( "select", function ( evt ) {
if( evt.selected.length > 0 ) {
onFeatureSelect( evt.selected[ 0 ] );
} else {
onFeatureUnselect( evt.deselected[ 0 ] );
}
});

答案 0 :(得分:1)
你快到了:
selectInteraction.on('select', function(evt){
if(evt.selected.length > 0){
console.info('selected: ' + evt.selected[0].getId());
}
});