Skip to content

Commit

Permalink
Do not finish polygon if not enough vertices (fix #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanboniface committed Apr 16, 2015
1 parent 77f6911 commit 5355447
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Leaflet.Editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@
this.onVertexMarkerAltClick(e);
} else if (e.originalEvent.shiftKey) {
this.onVertexMarkerShiftClick(e);
} else if (index >= 1 && index === e.vertex.getLastIndex() && this.drawing === L.Editable.FORWARD) {
} else if (index >= this.MIN_VERTEX - 1 && index === e.vertex.getLastIndex() && this.drawing === L.Editable.FORWARD) {
commit = true;
} else if (index === 0 && this.drawing === L.Editable.BACKWARD && this._drawnLatLngs.length >= this.MIN_VERTEX) {
commit = true;
Expand Down
12 changes: 9 additions & 3 deletions test/PolygonEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ describe('L.PolygonEditor', function() {
happen.at('mousemove', 200, 350);
happen.at('click', 200, 350);
assert.equal(polygon._latlngs.length, 2);
});

it('should not finish shape if not enough vertices', function () {
happen.at('click', 200, 350);
assert.equal(polygon._latlngs.length, 2);
assert.ok(polygon.editor.drawing);
});

it('should finish shape on last point click', function () {
happen.at('mousemove', 300, 250);
happen.at('click', 300, 250);
assert.equal(polygon._latlngs.length, 3);
happen.at('mousemove', 300, 150);
happen.at('click', 300, 150);
assert.equal(polygon._latlngs.length, 4);
});

it('should finish shape on last point click', function () {
happen.at('click', 300, 150);
assert.equal(polygon._latlngs.length, 4);
});
Expand Down

0 comments on commit 5355447

Please sign in to comment.