Skip to content

Commit

Permalink
Prevent drawing of rectangle whenn the corners have the same position (
Browse files Browse the repository at this point in the history
…#1470) (patch)
  • Loading branch information
Falke-Design committed Mar 24, 2024
1 parent 20df292 commit 7dd940b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cypress/integration/rectangle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,4 +991,18 @@ describe('Draw Rectangle', () => {
cy.get(mapSelector).click(200, 200);
cy.get(mapSelector).click(300, 300);
});

it('prevents drawing rectangle where all corners have the same position', () => {
cy.toolbarButton('rectangle')
.click()
.closest('.button-container')
.should('have.class', 'active');

cy.get(mapSelector).click(200, 200);
cy.get(mapSelector).click(200, 200);

cy.window().then(({ map }) => {
expect(map.pm.getGeomanDrawLayers().length).to.eql(0);
});
});
});
5 changes: 5 additions & 0 deletions src/js/Draw/L.PM.Draw.Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ Draw.Rectangle = Draw.extend({
return;
}

if (A.equals(B)) {
// rectangle has only one point
return;
}

// create the final rectangle layer, based on opposite corners A & B
const rectangleLayer = L.rectangle([A, B], this.options.pathOptions);

Expand Down

0 comments on commit 7dd940b

Please sign in to comment.