Remove or delete selected feature in openlayers

المشرف العام

Administrator
طاقم الإدارة
Using openlayers 3.9.0.I have two vector layers which are both desplayed on the map and can select any feature with a singleclick var select = new ol.interaction.Select();

Now I need to make it possible to remove selected feature with Del key.

I ended up with creating the folloing function and listener

var deleteFeature = function(e){ if(e.keyCode == 46 && (select !== null)){ [layer].getSource().removeFeature(select.getFeatures()); }};document.addEventListener('keydown', deleteFeature, false);but I don't know the layer of the selected feature to call the removeFeture method on.

Any suggestions how to find out the layer of the selected feature or another way of removing selected features?Thanks in advance!



أكثر...
 
أعلى