From 70f42b062934784c1ef8e593cbc7f8b05049f946 Mon Sep 17 00:00:00 2001 From: Xavier Mamano Date: Thu, 12 Jan 2012 08:46:15 +0100 Subject: [PATCH] Stop freehand using "maxVertices" --- lib/OpenLayers/Handler/Path.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Handler/Path.js b/lib/OpenLayers/Handler/Path.js index 9557a7f4c7..57d112b2a0 100644 --- a/lib/OpenLayers/Handler/Path.js +++ b/lib/OpenLayers/Handler/Path.js @@ -30,8 +30,7 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { * APIProperty: maxVertices * {Number} The maximum number of vertices which can be drawn by this * handler. When the number of vertices reaches maxVertices, the - * geometry is automatically finalized. This property doesn't - * apply if freehand is set. Default is null. + * geometry is automatically finalized. Default is null. */ maxVertices: null, @@ -446,7 +445,13 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { if(this.persist) { this.destroyPersistedFeature(); } - this.addPoint(evt.xy); + if(this.maxVertices && this.line && + this.line.geometry.components.length === this.maxVertices) { + this.removePoint() + this.finalize(); + } else { + this.addPoint(evt.xy); + } return false; } if (!this.touch && (!this.mouseDown || this.stoppedDown)) {