diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 68467cfd2b..7b61f19054 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -380,8 +380,8 @@ OpenLayers.Layer = OpenLayers.Class({ clone: function (obj) { if (obj == null) { - obj = new OpenLayers.Layer(this.name, this.options); - } + obj = new OpenLayers.Layer(this.name, this.getOptions()); + } // catch any randomly tagged-on properties OpenLayers.Util.applyDefaults(obj, this); @@ -393,6 +393,23 @@ OpenLayers.Layer = OpenLayers.Class({ return obj; }, + /** + * Method: getOptions + * Extracts an object from the layer with the properties that were set as + * options, but updates them with the values currently set on the + * instance. + * + * Returns: + * {Object} the of the layer, representing the current state. + */ + getOptions: function() { + var options = {}; + for(var o in this.options) { + options[o] = this[o]; + } + return options; + }, + /** * APIMethod: setName * Sets the new layer name for this layer. Can trigger a changelayer event diff --git a/lib/OpenLayers/Layer/ArcGIS93Rest.js b/lib/OpenLayers/Layer/ArcGIS93Rest.js index e181068a6b..3fbefea414 100644 --- a/lib/OpenLayers/Layer/ArcGIS93Rest.js +++ b/lib/OpenLayers/Layer/ArcGIS93Rest.js @@ -113,7 +113,7 @@ OpenLayers.Layer.ArcGIS93Rest = OpenLayers.Class(OpenLayers.Layer.Grid, { obj = new OpenLayers.Layer.ArcGIS93Rest(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 71c1786e31..ce73ee4021 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -130,7 +130,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { obj = new OpenLayers.Layer.Grid(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/HTTPRequest.js b/lib/OpenLayers/Layer/HTTPRequest.js index 6846c91924..0a17013427 100644 --- a/lib/OpenLayers/Layer/HTTPRequest.js +++ b/lib/OpenLayers/Layer/HTTPRequest.js @@ -89,7 +89,7 @@ OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { obj = new OpenLayers.Layer.HTTPRequest(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/Image.js b/lib/OpenLayers/Layer/Image.js index 4f3fa9a726..2ba2a7a8fa 100644 --- a/lib/OpenLayers/Layer/Image.js +++ b/lib/OpenLayers/Layer/Image.js @@ -108,7 +108,7 @@ OpenLayers.Layer.Image = OpenLayers.Class(OpenLayers.Layer, { this.url, this.extent, this.size, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/KaMap.js b/lib/OpenLayers/Layer/KaMap.js index ff10292d40..e9fcb371a6 100644 --- a/lib/OpenLayers/Layer/KaMap.js +++ b/lib/OpenLayers/Layer/KaMap.js @@ -162,7 +162,7 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, { obj = new OpenLayers.Layer.KaMap(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/MapGuide.js b/lib/OpenLayers/Layer/MapGuide.js index bbc38120e0..68994193cb 100644 --- a/lib/OpenLayers/Layer/MapGuide.js +++ b/lib/OpenLayers/Layer/MapGuide.js @@ -224,7 +224,7 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, { obj = new OpenLayers.Layer.MapGuide(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); diff --git a/lib/OpenLayers/Layer/MapServer.js b/lib/OpenLayers/Layer/MapServer.js index f80a69e4ba..e8af105379 100644 --- a/lib/OpenLayers/Layer/MapServer.js +++ b/lib/OpenLayers/Layer/MapServer.js @@ -66,7 +66,7 @@ OpenLayers.Layer.MapServer = OpenLayers.Class(OpenLayers.Layer.Grid, { obj = new OpenLayers.Layer.MapServer(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); diff --git a/lib/OpenLayers/Layer/MapServer/Untiled.js b/lib/OpenLayers/Layer/MapServer/Untiled.js index cb23f5a35a..d8b2cc0f1a 100644 --- a/lib/OpenLayers/Layer/MapServer/Untiled.js +++ b/lib/OpenLayers/Layer/MapServer/Untiled.js @@ -56,14 +56,14 @@ OpenLayers.Layer.MapServer.Untiled = OpenLayers.Class(OpenLayers.Layer.MapServer obj = new OpenLayers.Layer.MapServer.Untiled(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses obj = OpenLayers.Layer.MapServer.prototype.clone.apply(this, [obj]); // copy/set any non-init, non-simple values here - + return obj; }, diff --git a/lib/OpenLayers/Layer/TMS.js b/lib/OpenLayers/Layer/TMS.js index 6a916e54e1..6d4d14884e 100644 --- a/lib/OpenLayers/Layer/TMS.js +++ b/lib/OpenLayers/Layer/TMS.js @@ -78,7 +78,7 @@ OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, { if (obj == null) { obj = new OpenLayers.Layer.TMS(this.name, this.url, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/TileCache.js b/lib/OpenLayers/Layer/TileCache.js index ddf6a7c714..f4aa80bfa5 100644 --- a/lib/OpenLayers/Layer/TileCache.js +++ b/lib/OpenLayers/Layer/TileCache.js @@ -78,7 +78,7 @@ OpenLayers.Layer.TileCache = OpenLayers.Class(OpenLayers.Layer.Grid, { obj = new OpenLayers.Layer.TileCache(this.name, this.url, this.layername, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index ec8cbaa876..9d865f2470 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -314,7 +314,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { clone: function (obj) { if (obj == null) { - obj = new OpenLayers.Layer.Vector(this.name, this.options); + obj = new OpenLayers.Layer.Vector(this.name, this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index bbf4b916a7..b30ba55efb 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -442,7 +442,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class( obj = new OpenLayers.Layer.WFS(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index 9daaa966c5..80ce2223b1 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -145,7 +145,7 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { obj = new OpenLayers.Layer.WMS(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/WMS/Untiled.js b/lib/OpenLayers/Layer/WMS/Untiled.js index 6c5fe93a0b..f5c858e6ec 100644 --- a/lib/OpenLayers/Layer/WMS/Untiled.js +++ b/lib/OpenLayers/Layer/WMS/Untiled.js @@ -56,7 +56,7 @@ OpenLayers.Layer.WMS.Untiled = OpenLayers.Class(OpenLayers.Layer.WMS, { obj = new OpenLayers.Layer.WMS.Untiled(this.name, this.url, this.params, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/lib/OpenLayers/Layer/XYZ.js b/lib/OpenLayers/Layer/XYZ.js index def9dba45b..9ea185b071 100644 --- a/lib/OpenLayers/Layer/XYZ.js +++ b/lib/OpenLayers/Layer/XYZ.js @@ -72,7 +72,7 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, { if (obj == null) { obj = new OpenLayers.Layer.XYZ(this.name, this.url, - this.options); + this.getOptions()); } //get all additions from superclasses diff --git a/tests/Layer.html b/tests/Layer.html index 8aa09a92fc..334af74dbc 100644 --- a/tests/Layer.html +++ b/tests/Layer.html @@ -36,12 +36,13 @@ } function test_Layer_clone (t) { - t.plan( 8 ); + t.plan( 9 ); var mapone = new OpenLayers.Map('map'); - var options = { chicken: 151, foo: "bar", maxResolution: "auto" }; + var options = { chicken: 151, foo: "bar", maxResolution: "auto", visibility: false }; var layer = new OpenLayers.Layer('Test Layer', options); mapone.addLayer(layer); + layer.setVisibility(true); // randomly assigned property layer.chocolate = 5; @@ -58,6 +59,8 @@ t.ok( ((clone.options["chicken"] == 151) && (clone.options["foo"] == "bar")), "clone.options correctly set" ); t.eq(clone.chocolate, 5, "correctly copied randomly assigned property"); + t.eq(clone.visibility, true, "visibility correctly cloned"); + layer.addOptions({chicken:152}); t.eq(clone.options["chicken"], 151, "made a clean copy of options"); diff --git a/tests/Layer/HTTPRequest.html b/tests/Layer/HTTPRequest.html index d37f6ffac1..5c82f452c0 100644 --- a/tests/Layer/HTTPRequest.html +++ b/tests/Layer/HTTPRequest.html @@ -45,7 +45,7 @@ // correct bubbling up to Layer.initialize() t.eq( layer.name, name, "layer.name is correct" ); - t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly set" ); + t.eq( layer.options, options, "layer.options correctly set" ); // HTTPRequest-specific properties t.eq( layer.url, url, "layer.name is correct" );