lets have clone() just take no arguments and return an exact copy. then we can add modify functions that can be used to set the particular things the user wants changed, and s/he can do it him/herself. also a change here is that layer.options will always be initialized, never null.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@882 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+24
-20
@@ -51,10 +51,10 @@ OpenLayers.Layer.prototype = {
|
|||||||
if (arguments.length > 0) {
|
if (arguments.length > 0) {
|
||||||
|
|
||||||
//store a copy of the custom options for later cloning
|
//store a copy of the custom options for later cloning
|
||||||
this.options = options;
|
this.options = (options == null) ? new Object : options;
|
||||||
|
|
||||||
//add options to layer
|
//add options to layer
|
||||||
Object.extend(this, options);
|
Object.extend(this, this.options);
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if (this.div == null) {
|
if (this.div == null) {
|
||||||
@@ -77,30 +77,34 @@ OpenLayers.Layer.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} newName
|
* @returns An exact clone of this OpenLayers.Layer
|
||||||
* @param {Hash} newOptions
|
|
||||||
*
|
|
||||||
* @returns A clone of this OpenLayers.Layer
|
|
||||||
* @type OpenLayers.Layer
|
* @type OpenLayers.Layer
|
||||||
*/
|
*/
|
||||||
clone: function (newName, newOptions) {
|
clone: function () {
|
||||||
|
var clone = new OpenLayers.Layer(this.name,
|
||||||
if (newName == null) {
|
this.options);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
var clone = new OpenLayers.Layer(newName, mergedOptions);
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} newName
|
||||||
|
*/
|
||||||
|
setName: function(newName) {
|
||||||
|
this.name = newName;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Hash} newOptions
|
||||||
|
*/
|
||||||
|
addOptions: function (newOptions) {
|
||||||
|
|
||||||
|
if (newOptions != null) {
|
||||||
|
Object.extend(this.options, newOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @params {OpenLayers.Bounds} bound
|
* @params {OpenLayers.Bounds} bound
|
||||||
|
|||||||
+26
-1
@@ -5,13 +5,37 @@
|
|||||||
var layer;
|
var layer;
|
||||||
|
|
||||||
function test_01_Layer_constructor (t) {
|
function test_01_Layer_constructor (t) {
|
||||||
t.plan( 2 );
|
t.plan( 6 );
|
||||||
|
|
||||||
|
var options = { chicken: 151, foo: "bar" };
|
||||||
|
var layer = new OpenLayers.Layer('Test Layer', options);
|
||||||
|
|
||||||
|
t.ok( layer instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
|
||||||
|
t.eq( layer.name, "Test Layer", "layer.name is correct" );
|
||||||
|
t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly set" );
|
||||||
|
|
||||||
|
|
||||||
layer = new OpenLayers.Layer('Test Layer');
|
layer = new OpenLayers.Layer('Test Layer');
|
||||||
t.ok( layer instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
|
t.ok( layer instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
|
||||||
t.eq( layer.name, "Test Layer", "layer.name is correct" );
|
t.eq( layer.name, "Test Layer", "layer.name is correct" );
|
||||||
|
t.ok( layer.options instanceof Object, "layer.options correctly not set to null" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_02_Layer_clone (t) {
|
||||||
|
t.plan( 3 );
|
||||||
|
|
||||||
|
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" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
function test_02_Layer_clone (t) {
|
function test_02_Layer_clone (t) {
|
||||||
t.plan( 7 );
|
t.plan( 7 );
|
||||||
|
|
||||||
@@ -55,6 +79,7 @@
|
|||||||
(clone.options["clear"] == "skies")), "clone.options correctly merged" );
|
(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 );
|
||||||
|
|||||||
Reference in New Issue
Block a user