Skip to content

Commit

Permalink
Fix duplicate point creation in polygon draw and add tests (#621)
Browse files Browse the repository at this point in the history
Co-authored-by: Sumit Kumar <sk@outlook.com>
  • Loading branch information
Matt Hogg and codeofsumit committed Jul 4, 2020
1 parent 8880b1f commit 7f4a6a5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cypress/integration/polygon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,43 @@ describe('Draw & Edit Poly', () => {
cy.hasVertexMarkers(4);
});

it('doesnt allow duplicate points in polygon', () => {
cy.toolbarButton('polygon').click();

cy.get(mapSelector)
.click(90, 250)
.click(100, 50)
.click(150, 50)
.dblclick(150, 150)
.click(90, 250);

cy.toolbarButton('edit').click();

cy.hasVertexMarkers(4);

cy.toolbarButton('edit').click();
});

it('doesnt break on dblclick while self intersection disabled', () => {
cy.window().then(({ map }) => {
map.pm.enableDraw('Polygon', {
allowSelfIntersection: false,
});
});

cy.get(mapSelector)
.click(90, 250)
.click(100, 50)
.click(150, 50)
.dblclick(150, 150)
.click(90, 250);

cy.toolbarButton('edit').click();

cy.hasVertexMarkers(4);

cy.toolbarButton('edit').click();
});

it('prevent creation while self intersection', () => {

Expand Down
5 changes: 5 additions & 0 deletions src/js/Draw/L.PM.Draw.Polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ Draw.Polygon = Draw.Line.extend({
if (this.options.snappable) {
this._cleanupSnapping();
}
} else {
// add a click event w/ no handler to the marker
// event won't bubble so prevents creation of identical markers in same polygon
// fixes issue where double click during poly creation when allowSelfIntersection: false caused it to break
marker.on('click', () => (1));
}

// handle tooltip text
Expand Down

0 comments on commit 7f4a6a5

Please sign in to comment.