Give Layer.Vector a proper clone() method. r=crschmidt (closes #2391)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9942 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-01-09 12:01:45 +00:00
parent 44ba385429
commit 88b05f55a1
2 changed files with 42 additions and 0 deletions

View File

@@ -302,6 +302,36 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
OpenLayers.Layer.prototype.destroy.apply(this, arguments);
},
/**
* Method: clone
* Create a clone of this layer.
*
* Note: Features of the layer are also cloned.
*
* Returns:
* {<OpenLayers.Layer.Vector>} An exact clone of this layer
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer.Vector(this.name, this.options);
}
//get all additions from superclasses
obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]);
// copy/set any non-init, non-simple values here
var features = this.features;
var len = features.length;
var clonedFeatures = new Array(len);
for(var i=0; i<len; ++i) {
clonedFeatures[i] = features[i].clone();
}
obj.features = clonedFeatures;
return obj;
},
/**
* Method: refresh
* Ask the layer to request features again and redraw them. Triggers