diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index da59c77b0d..b4f4eb2457 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -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); },