diff --git a/cypress/e2e/line.cy.js b/cypress/e2e/line.cy.js index 67afcccc..a6240397 100644 --- a/cypress/e2e/line.cy.js +++ b/cypress/e2e/line.cy.js @@ -373,4 +373,32 @@ describe('Draw & Edit Line', () => { // draw a line cy.get(mapSelector).click(150, 250); }); + + it('prevents removal of the layer if the vertex count is below minimum (removeLayerBelowMinVertexCount)', () => { + cy.window().then(({ map }) => { + map.pm.setGlobalOptions({ removeLayerBelowMinVertexCount: false }); + }); + + // activate polyline drawing + cy.toolbarButton('polyline') + .click() + .closest('.button-container') + .should('have.class', 'active'); + + // draw a polyline + cy.get(mapSelector).click(90, 250).click(150, 50).click(150, 50); + + // enable global edit mode + cy.toolbarButton('edit') + .click() + .closest('.button-container') + .should('have.class', 'active'); + + // let's remove one vertex + cy.get('.marker-icon:not(.marker-icon-middle)') + .last() + .trigger('contextmenu'); + + cy.hasVertexMarkers(2); + }); }); diff --git a/cypress/e2e/polygon.cy.js b/cypress/e2e/polygon.cy.js index c526939d..d6c89a6f 100644 --- a/cypress/e2e/polygon.cy.js +++ b/cypress/e2e/polygon.cy.js @@ -1326,4 +1326,90 @@ describe('Draw & Edit Poly', () => { expect(hintMarker.getLatLng().lng).to.eq(72.22334801861803); }); }); + + it('prevents removal of the layer if the vertex count is below minimum (removeLayerBelowMinVertexCount)', () => { + cy.window().then(({ map }) => { + map.pm.setGlobalOptions({ removeLayerBelowMinVertexCount: false }); + }); + + // activate polygon drawing + cy.toolbarButton('polygon') + .click() + .closest('.button-container') + .should('have.class', 'active'); + + // draw a polygon + cy.get(mapSelector) + .click(90, 250) + .click(150, 50) + .click(500, 50) + .click(90, 250); + + cy.hasLayers(3); + + // enable global edit mode + cy.toolbarButton('edit') + .click() + .closest('.button-container') + .should('have.class', 'active'); + + // let's remove one vertex + cy.get('.marker-icon:not(.marker-icon-middle)') + .last() + .trigger('contextmenu'); + + cy.hasVertexMarkers(3); + }); + + it('allows to remove the hole when removeLayerBelowMinVertexCount is false', () => { + cy.window().then(({ map }) => { + map.pm.setGlobalOptions({ removeLayerBelowMinVertexCount: false }); + }); + + // activate polygon drawing + cy.toolbarButton('polygon') + .click() + .closest('.button-container') + .should('have.class', 'active'); + + // draw a polygon + cy.get(mapSelector) + .click(90, 250) + .click(150, 50) + .click(500, 50) + .click(90, 250); + + // activate cutting drawing + cy.toolbarButton('cut') + .click() + .closest('.button-container') + .should('have.class', 'active'); + + // draw a polygon to cut + cy.get(mapSelector) + .click(170, 80) + .click(320, 80) + .click(170, 170) + .click(170, 80); + + cy.hasLayers(3); + + // enable global edit mode + cy.toolbarButton('edit') + .click() + .closest('.button-container') + .should('have.class', 'active'); + + cy.hasVertexMarkers(6); + + // let's remove a vertex of the hole + cy.get(mapSelector).trigger('contextmenu', 170, 170); + + cy.hasVertexMarkers(3); + + // let's remove a vertex of the hole + cy.get(mapSelector).trigger('contextmenu', 90, 250); + + cy.hasVertexMarkers(3); + }); }); diff --git a/src/js/Edit/L.PM.Edit.Line.js b/src/js/Edit/L.PM.Edit.Line.js index ae72ed2e..e69d8a48 100644 --- a/src/js/Edit/L.PM.Edit.Line.js +++ b/src/js/Edit/L.PM.Edit.Line.js @@ -473,8 +473,12 @@ Edit.Line = Edit.extend({ let markerArr = indexPath.length > 1 ? get(this._markers, parentPath) : this._markers; - // prevent removal of the layer if the vertex count is below minimum - if (!this.options.removeLayerBelowMinVertexCount) { + // define whether marker is part of hole + const isHole = + parentPath[parentPath.length - 1] > 0 && this._layer instanceof L.Polygon; + + // prevent removal of the layer if the vertex count is below minimum when not a hole + if (!this.options.removeLayerBelowMinVertexCount && !isHole) { // if on a line only 2 vertices left or on a polygon 3 vertices left, don't allow to delete if ( coordsRing.length <= 2 ||