Changing our layers' clone methods so they create a clone of the layer state at the time of clone creation, not at the time the original was created. r=tschaub (closes #2477)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10045 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -380,7 +380,7 @@ 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
|
||||
@@ -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 <options> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -56,7 +56,7 @@ 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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" );
|
||||
|
||||
Reference in New Issue
Block a user