make a safe copy of options on initialization, utilize applyDefaults() on clone to pick up stray addons. dont need the if in addOptions, as extend can safely handle a null source

git-svn-id: http://svn.openlayers.org/trunk/openlayers@884 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-07-05 15:31:08 +00:00
parent 23c2ea1c04
commit 96a32e8fb0

View File

@@ -51,7 +51,7 @@ 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 == null) ? new Object : options; this.options = Object.extend(new Object(), options);
//add options to layer //add options to layer
Object.extend(this, this.options); Object.extend(this, this.options);
@@ -83,11 +83,16 @@ OpenLayers.Layer.prototype = {
* @returns An exact clone of this OpenLayers.Layer * @returns An exact clone of this OpenLayers.Layer
* @type OpenLayers.Layer * @type OpenLayers.Layer
*/ */
clone: function () { clone: function (obj) {
var clone = new OpenLayers.Layer(this.name,
this.options);
return clone; if (obj == null) {
obj = new OpenLayers.Layer(this.name, this.options);
}
// catch any randomly tagged-on properties
obj = OpenLayers.Util.applyDefaults(obj, this);
return obj;
}, },
/** /**
@@ -102,10 +107,11 @@ OpenLayers.Layer.prototype = {
*/ */
addOptions: function (newOptions) { addOptions: function (newOptions) {
if (newOptions != null) { // update our copy for clone
Object.extend(this.options, newOptions); Object.extend(this.options, newOptions);
}
// add new options to this
Object.extend(this, this.options);
}, },