[GIS] How unselect a feature ithat select with OpenLayers-3.8.2’s selectInteraction

ol-interactionopenlayers

I'm using OpenLayers-3.8.2. I want to select a feature and then delete it. my code is as follow:

deleteFeature = function(event){
    var feature = event.selected[0];
    myLayer.getSource().removeFeature(feature);
}

selectInteraction = new ol.interaction.Select({
    condition: ol.events.condition.singleClick,
    toggleCondition: ol.events.condition.shiftKeyOnly,
    layers: [myLayer]
})

map.addInteraction(selectInteraction);

selectInteraction.on("select", deleteFeature, this);

This code delete the feature from source but it still showed in map.

How can I unselect a feature? Or how can I redraw a layer? Or how can I delete a featrue in openlayers-3?

Best Answer

On ol3 3.11.2, the event.selected.clear(); does not exist, so you need to use the selectionInteraction.getFeatures().clear();