add clone() method to Layer class, add test.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@879 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -75,6 +75,30 @@ OpenLayers.Layer.prototype = {
|
|||||||
}
|
}
|
||||||
this.map = null;
|
this.map = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} newName
|
||||||
|
* @param {Hash} newOptions
|
||||||
|
*
|
||||||
|
* @returns A clone of this OpenLayers.Layer
|
||||||
|
* @type OpenLayers.Layer
|
||||||
|
*/
|
||||||
|
clone: function (newName, newOptions) {
|
||||||
|
|
||||||
|
if (newName == null) {
|
||||||
|
newName = this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
var mergedOptions = null;
|
||||||
|
if ( (this.options != null) || (newOptions != null) ) {
|
||||||
|
// only merge options if there were or will be
|
||||||
|
mergedOptions = Object.extend( {}, this.options);
|
||||||
|
Object.extend(mergedOptions, newOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OpenLayers.Layer(newName, mergedOptions);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @params {OpenLayers.Bounds} bound
|
* @params {OpenLayers.Bounds} bound
|
||||||
|
|||||||
@@ -12,6 +12,50 @@
|
|||||||
t.eq( layer.name, "Test Layer", "layer.name is correct" );
|
t.eq( layer.name, "Test Layer", "layer.name is correct" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_02_Layer_clone (t) {
|
||||||
|
t.plan( 7 );
|
||||||
|
|
||||||
|
var options = { chicken: 151, foo: "bar" };
|
||||||
|
var layer = new OpenLayers.Layer('Test Layer', options);
|
||||||
|
var clone = layer.clone();
|
||||||
|
|
||||||
|
t.ok( clone instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
|
||||||
|
t.eq( clone.name, "Test Layer", "default clone.name is correct" );
|
||||||
|
t.ok( ((clone.options["chicken"] == 151) && (clone.options["foo"] == "bar")), "clone.options correctly set" );
|
||||||
|
|
||||||
|
|
||||||
|
var layer = new OpenLayers.Layer('Test Layer');
|
||||||
|
var clone = layer.clone();
|
||||||
|
|
||||||
|
t.ok( clone.options == null, "clone.options correctly left at null" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var layer = new OpenLayers.Layer('Test Layer', options);
|
||||||
|
var clone = layer.clone("Special Bonus");
|
||||||
|
|
||||||
|
t.eq( clone.name, "Special Bonus", "clone.name is correct" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var newOptions = { foo: "stoo", clear: "skies" };
|
||||||
|
var layer = new OpenLayers.Layer('Test Layer', options);
|
||||||
|
var clone = layer.clone("Special Bonus", newOptions);
|
||||||
|
|
||||||
|
t.ok( ((clone.options["chicken"] == 151) &&
|
||||||
|
(clone.options["foo"] == "stoo") &&
|
||||||
|
(clone.options["clear"] == "skies")), "clone.options correctly merged" );
|
||||||
|
|
||||||
|
|
||||||
|
var newOptions = { chicken: 151, foo: "stoo", clear: "skies" };
|
||||||
|
var layer = new OpenLayers.Layer('Test Layer');
|
||||||
|
var clone = layer.clone("Special Bonus", newOptions);
|
||||||
|
|
||||||
|
t.ok( ((clone.options["foo"] == "stoo") &&
|
||||||
|
(clone.options["clear"] == "skies")), "clone.options correctly merged" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function test_99_Layer_destroy (t) {
|
function test_99_Layer_destroy (t) {
|
||||||
t.plan( 1 );
|
t.plan( 1 );
|
||||||
layer = new OpenLayers.Layer('Test Layer');
|
layer = new OpenLayers.Layer('Test Layer');
|
||||||
|
|||||||
Reference in New Issue
Block a user