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) {
//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
Object.extend(this, this.options);
@@ -83,11 +83,16 @@ OpenLayers.Layer.prototype = {
* @returns An exact clone of this OpenLayers.Layer
* @type OpenLayers.Layer
*/
clone: function () {
var clone = new OpenLayers.Layer(this.name,
this.options);
return clone;
clone: function (obj) {
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;
},
/**
@@ -101,11 +106,12 @@ OpenLayers.Layer.prototype = {
* @param {Hash} newOptions
*/
addOptions: function (newOptions) {
// update our copy for clone
Object.extend(this.options, newOptions);
if (newOptions != null) {
Object.extend(this.options, newOptions);
}
// add new options to this
Object.extend(this, this.options);
},