Adding support for cloning rules and filters. r=ahocevar (closes #1919)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9071 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-03-17 16:08:12 +00:00
parent 7fa74f1b0b
commit 576e931dac
11 changed files with 241 additions and 3 deletions

View File

@@ -101,10 +101,9 @@ OpenLayers.Rule = OpenLayers.Class({
* {<OpenLayers.Rule>}
*/
initialize: function(options) {
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
this.symbolizer = {};
OpenLayers.Util.extend(this, options);
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
},
/**
@@ -178,6 +177,33 @@ OpenLayers.Rule = OpenLayers.Class({
}
return context;
},
/**
* APIMethod: clone
* Clones this rule.
*
* Returns:
* {<OpenLayers.Rule>} Clone of this rule.
*/
clone: function() {
var options = OpenLayers.Util.extend({}, this);
// clone symbolizer
options.symbolizer = {};
for(var key in this.symbolizer) {
value = this.symbolizer[key];
type = typeof value;
if(type === "object") {
options.symbolizer[key] = OpenLayers.Util.extend({}, value);
} else if(type === "string") {
options.symbolizer[key] = value;
}
}
// clone filter
options.filter = this.filter && this.filter.clone();
// clone context
options.context = this.context && OpenLayers.Util.extend({}, this.context);
return new OpenLayers.Rule(options);
},
CLASS_NAME: "OpenLayers.Rule"
});