When polygon has 3 vertices left I am unable to delete any of those vertices:

var modifyInteraction = new ol.interaction.Modify({
   features: selectCtrl.getFeatures(),
   deleteCondition: function(event) {  
       return keys['46']; // 46 = delete key
  • 1
    Why is this surprising? Polygons require three discrete vertices. – Vince Dec 2 at 22:31
  • I would expect that deleting 3rd vertice of a polygon would remove entire polygon. That is what I want - a polygon to be deleted when attempt to delete 3rd vertice of the polygon is made. This is not built-in? – user435421 Dec 2 at 22:47
  • Because it seems to me it worked this way on OpenLayers2 – user435421 Dec 2 at 22:53
  • In the current version there must be at least 4 coordinates (including one to close the ring) before you can delete github.com/openlayers/openlayers/blob/master/src/ol/interaction/… – Mike Dec 3 at 10:22

Ended up modifying ol.interaction.Modify.removeVertex_ to track which features were being attempted to be modified. By that I mean when the flow would go to else block https://github.com/openlayers/openlayers/blob/master/src/ol/interaction/Modify.js#L1143 I would register segmentData.feature as a feature that was supposed to be deleted and handle the "delete feature" logic in overridden version of ol.interaction.Modify.removePoint where the deletion would happen after calling the original ol.interaction.Modify.removePoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.