Reputation:
I'm currently seeing this example of openlayers ( http://openlayers.org/en/v3.14.2/examples/draw-features.html ) whichs draws lines, circles etc. on the map. I edited the code to be able to select a drawing. I was wondering how can I delete a selected drawing? Here is how i select the drawing:
var select = new ol.interaction.Select();
Any ideas? Thanks!
Upvotes: 1
Views: 2988
Reputation: 156
You can delete the feature by removing it from the layer when it has been selected. Use a 'add' listener on the features selected in the interaction, and delete it from the source of the layer. Use
select = new ol.interaction.Select();
select.getFeatures().on('add', function(feature){
//source is layer.getSource()
source.removeFeature(feature.element);
feature.target.remove(feature.element);
});
map.addInteraction(select);
JSFiddle link (select delete in the dropdown to select and delete a feature): http://jsfiddle.net/anushamc/edms856o/
Upvotes: 1