Skip to content

Allow removal of holes in polygons while maintaining the minimum vertex count of the geometry #1475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cypress/e2e/line.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
86 changes: 86 additions & 0 deletions cypress/e2e/polygon.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
8 changes: 6 additions & 2 deletions src/js/Edit/L.PM.Edit.Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
Loading