From 02c662b21099f3e09cef2e2efcb01b2439d7046a Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 16 Apr 2015 08:55:31 +0200 Subject: [PATCH] Do not finish polygon if not enough vertices (cf #18) --- package.json | 2 +- src/Leaflet.Editable.js | 2 +- test/PolygonEditor.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6ea5ac0..ad269f4 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/Leaflet.Editable.js b/src/Leaflet.Editable.js index ca47ccc..94a096d 100644 --- a/src/Leaflet.Editable.js +++ b/src/Leaflet.Editable.js @@ -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(); diff --git a/test/PolygonEditor.js b/test/PolygonEditor.js index ebcc248..52a7b41 100644 --- a/test/PolygonEditor.js +++ b/test/PolygonEditor.js @@ -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);