make sure clone() of a layer does not copy the reference in the 'map' property. that should always be null as a cloned layer will still need to be added to the map via map.addLayer()

git-svn-id: http://svn.openlayers.org/trunk/openlayers@887 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-07-06 01:02:02 +00:00
parent 4182cc1955
commit 5debdb69ec
2 changed files with 13 additions and 2 deletions

View File

@@ -92,6 +92,10 @@ OpenLayers.Layer.prototype = {
// catch any randomly tagged-on properties
obj = OpenLayers.Util.applyDefaults(obj, this);
// a cloned layer should never have its map property set
// because it has not been added to a map yet.
obj.map = null;
return obj;
},

View File

@@ -30,10 +30,14 @@
}
function test_02_Layer_clone (t) {
t.plan( 5 );
t.plan( 6 );
var map = new OpenLayers.Map('map');
var options = { chicken: 151, foo: "bar" };
var layer = new OpenLayers.Layer('Test Layer', options);
map.addLayer(layer);
// randomly assigned property
layer.chocolate = 5;
var clone = layer.clone();
@@ -41,10 +45,13 @@
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" );
t.eq(layer.chocolate, 5, "correctly copied randomly assigned property");
t.eq(clone.chocolate, 5, "correctly copied randomly assigned property");
layer.addOptions({chicken:152});
t.eq(clone.options["chicken"], 151, "made a clean copy of options");
t.ok( clone.map == null, "cloned layer has map property set to null")
}