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
This commit is contained in:
@@ -77,7 +77,7 @@ function init() {
|
||||
{
|
||||
title: "Draw Feature",
|
||||
displayClass: "olControlDrawFeaturePolygon",
|
||||
handlerOptions: {multi: true}
|
||||
multi: true
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -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})}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user