give Style a unique id and a clone method. r=elemoine (closes #2605)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10315 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-05-12 20:41:30 +00:00
parent f95532ab6f
commit c4e779b992
2 changed files with 68 additions and 0 deletions

View File

@@ -15,6 +15,12 @@
*/
OpenLayers.Style = OpenLayers.Class({
/**
* Property: id
* {String} A unique id for this session.
*/
id: null,
/**
* APIProperty: name
* {String}
@@ -119,6 +125,7 @@ OpenLayers.Style = OpenLayers.Class({
this.setDefaultStyle(style ||
OpenLayers.Feature.Vector.style["default"]);
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
},
/**
@@ -369,6 +376,29 @@ OpenLayers.Style = OpenLayers.Class({
}
},
/**
* APIMethod: clone
* Clones this style.
*
* Returns:
* {<OpenLayers.Style>} Clone of this style.
*/
clone: function() {
var options = OpenLayers.Util.extend({}, this);
// clone rules
if(this.rules) {
options.rules = [];
for(var i=0, len=this.rules.length; i<len; ++i) {
options.rules.push(this.rules[i].clone());
}
}
// clone context
options.context = this.context && OpenLayers.Util.extend({}, this.context);
//clone default style
var defaultStyle = OpenLayers.Util.extend({}, this.defaultStyle);
return new OpenLayers.Style(defaultStyle, options);
},
CLASS_NAME: "OpenLayers.Style"
});