Merge pull request #1662 from tschaub/drawing-rings
Add `minPointsPerRing` option to the draw interaction. By default, polygon drawing cannot be finished until three points have been added. To allow polygon drawing to finish after only two points have been added, set `minPointsPerRing: 2`.
This commit is contained in:
@@ -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.style.Style>|ol.feature.StyleFunction|undefined} style
|
||||
* Style for sketch features.
|
||||
* @todo stability experimental
|
||||
|
||||
@@ -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]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user