OpenLayers 3 - Modify Feature - Delete vertex on keypress

المشرف العام

Administrator
طاقم الإدارة
I'm trying to create functionality in OpenLayers 3 that allows me to delete a vertex from a feature that is currently selected using the modify interaction.

I've managed to see that there is a 'deleteCondition' parameter set on the modify interaction when it is created, and that this needs to return an ol.events.condition object. At present I can see from this example (http://openlayers.org/en/master/examples/draw-and-modify-features.html) that is it possible to delete a vertex by pressing ALT and mouse click at the same time, however this then creates a new point which seems counter-intuitive to me. If you are deleting a vertex why would you want to create a new vertex in exactly the same place? I may have missed something here though.

So the question is how can I use these ol.events.condition objects to make it so that if the user clicks a specific key on the keyboard the highlighted vertex is deleted?

My initial thoughts were to have something like this:

var modifyInteraction = new ol.interaction.Modify({ features: selectInteraction.getFeatures(), deleteCondition: function(event) { var key = event.originalEvent.keycode || event.originalEvent.charCode; if(key == 46) { return ol.events.condition.always(event); } else { return ol.events.condition.never(event); } }});But this produces some very strange results...



أكثر...
 
أعلى