From 3de62b703a5232dcbfda44c1b5ece7759fafaf0d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 23 Mar 2010 17:49:13 +0000 Subject: [PATCH] Adding multi property to the DrawFeature control. If true, geometries will be cast to multi-part counterparts before features are added to the target layer. r=ahocevar (closes #2542) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10142 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/wfs-protocol-transactions.js | 2 +- lib/OpenLayers/Control/DrawFeature.js | 12 +++++++++++- lib/OpenLayers/Handler/Point.js | 2 +- tests/Control/DrawFeature.html | 28 +++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/examples/wfs-protocol-transactions.js b/examples/wfs-protocol-transactions.js index 1e1464effa..a5a6a7cc37 100644 --- a/examples/wfs-protocol-transactions.js +++ b/examples/wfs-protocol-transactions.js @@ -77,7 +77,7 @@ function init() { { title: "Draw Feature", displayClass: "olControlDrawFeaturePolygon", - handlerOptions: {multi: true} + multi: true } ); diff --git a/lib/OpenLayers/Control/DrawFeature.js b/lib/OpenLayers/Control/DrawFeature.js index 6056fda869..bd09506892 100644 --- a/lib/OpenLayers/Control/DrawFeature.js +++ b/lib/OpenLayers/Control/DrawFeature.js @@ -38,6 +38,13 @@ OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, { */ EVENT_TYPES: ["featureadded"], + /** + * APIProperty: multi + * {Boolean} Cast features to multi-part geometries before passing to the + * layer. Default is false. + */ + multi: false, + /** * APIProperty: featureAdded * {Function} Called after each feature is added @@ -84,9 +91,12 @@ OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, { this.callbacks ); this.layer = layer; + this.handlerOptions = this.handlerOptions || {}; + if (!("multi" in this.handlerOptions)) { + this.handlerOptions.multi = this.multi; + } var sketchStyle = this.layer.styleMap && this.layer.styleMap.styles.temporary; if(sketchStyle) { - this.handlerOptions = this.handlerOptions || {}; this.handlerOptions.layerOptions = OpenLayers.Util.applyDefaults( this.handlerOptions.layerOptions, {styleMap: new OpenLayers.StyleMap({"default": sketchStyle})} diff --git a/lib/OpenLayers/Handler/Point.js b/lib/OpenLayers/Handler/Point.js index 1efce7bd96..d7f2ee6364 100644 --- a/lib/OpenLayers/Handler/Point.js +++ b/lib/OpenLayers/Handler/Point.js @@ -35,7 +35,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { layer: null, /** - * Property: multi + * APIProperty: multi * {Boolean} Cast features to multi-part geometries before passing to the * layer. Default is false. */ diff --git a/tests/Control/DrawFeature.html b/tests/Control/DrawFeature.html index eefdea5ce3..63cff1e7db 100644 --- a/tests/Control/DrawFeature.html +++ b/tests/Control/DrawFeature.html @@ -12,6 +12,34 @@ "featureadded event in EVENT_TYPES"); } + function test_multi(t) { + t.plan(4); + + var layer = new OpenLayers.Layer.Vector(); + var control; + + // multi false by default + control = new OpenLayers.Control.DrawFeature( + layer, OpenLayers.Handler.Polygon + ); + t.ok(!control.multi, "control.multi false by default"); + t.ok(!control.handler.multi, "handler.multi false by default"); + + // set on handler + control = new OpenLayers.Control.DrawFeature( + layer, OpenLayers.Handler.Polygon, {multi: true} + ); + t.ok(control.handler.multi, "handler.multi set from control options"); + + // respect handlerOptions + control = new OpenLayers.Control.DrawFeature( + layer, OpenLayers.Handler.Polygon, + {multi: true, handlerOptions: {multi: false}} + ); + t.ok(!control.handler.multi, "handlerOptions.multi respected"); + + } + function test_drawFeature(t) { t.plan(3); var layer = new OpenLayers.Layer.Vector();