From a18593ee10a49bd0f83199ebd80d91d062b8ee6b Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 5 Mar 2014 12:58:03 -0700 Subject: [PATCH] Support minPointsPerRing and default to 3 --- src/objectliterals.jsdoc | 2 ++ src/ol/interaction/drawinteraction.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 19ef7ded72..68f2782c36 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -415,6 +415,8 @@ * drawing finish (default is 12). * @property {ol.geom.GeometryType} type Drawing type ('Point', 'LineString', * 'Polygon', 'MultiPoint', 'MultiLineString', or 'MultiPolygon'). + * @property {number|undefined} minPointsPerRing The number of points that must + * be drawn before a polygon ring can be finished (default is 3). * @property {ol.style.Style|Array.|ol.feature.StyleFunction|undefined} style * Style for sketch features. * @todo stability experimental diff --git a/src/ol/interaction/drawinteraction.js b/src/ol/interaction/drawinteraction.js index 7c357ad51f..5c972ac8ae 100644 --- a/src/ol/interaction/drawinteraction.js +++ b/src/ol/interaction/drawinteraction.js @@ -89,6 +89,15 @@ ol.interaction.Draw = function(options) { this.snapTolerance_ = goog.isDef(options.snapTolerance) ? options.snapTolerance : 12; + /** + * The number of points that must be drawn before a polygon ring can be + * finished. The default is 3. + * @type {number} + * @private + */ + this.minPointsPerRing_ = goog.isDef(options.minPointsPerRing) ? + options.minPointsPerRing : 3; + /** * Geometry type. * @type {ol.geom.GeometryType} @@ -314,7 +323,8 @@ ol.interaction.Draw.prototype.atFinish_ = function(event) { potentiallyDone = geometry.getCoordinates().length > 2; } else if (this.mode_ === ol.interaction.DrawMode.POLYGON) { goog.asserts.assertInstanceof(geometry, ol.geom.Polygon); - potentiallyDone = geometry.getCoordinates()[0].length > 2; + potentiallyDone = geometry.getCoordinates()[0].length > + this.minPointsPerRing_; potentiallyFinishCoordinates = [this.sketchRawPolygon_[0][0], this.sketchRawPolygon_[0][this.sketchRawPolygon_[0].length - 2]]; }