Skip to content

Commit

Permalink
Do not finish polygon if not enough vertices (cf #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanboniface committed Apr 16, 2015
1 parent 7179cd3 commit 02c662b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "leaflet-editable",
"version": "0.6.1",
"version": "0.6.2",
"description": "Make geometries editable in Leaflet",
"main": "src/Leaflet.Editable.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/Leaflet.Editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ L.Editable.PathEditor = L.Editable.BaseEditor.extend({
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) {
this.commitDrawing();
} else if (index === 0 && this.drawing === L.Editable.BACKWARD && this._drawnLatLngs.length >= this.MIN_VERTEX) {
this.commitDrawing();
Expand Down
9 changes: 9 additions & 0 deletions test/PolygonEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ 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);
Expand Down

0 comments on commit 02c662b

Please sign in to comment.