lets have clone() just take no arguments and return an exact copy. then we can add modify functions that can be used to set the particular things the user wants changed, and s/he can do it him/herself. also a change here is that layer.options will always be initialized, never null.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@882 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -51,10 +51,10 @@ OpenLayers.Layer.prototype = {
|
||||
if (arguments.length > 0) {
|
||||
|
||||
//store a copy of the custom options for later cloning
|
||||
this.options = options;
|
||||
this.options = (options == null) ? new Object : options;
|
||||
|
||||
//add options to layer
|
||||
Object.extend(this, options);
|
||||
Object.extend(this, this.options);
|
||||
|
||||
this.name = name;
|
||||
if (this.div == null) {
|
||||
@@ -77,30 +77,34 @@ OpenLayers.Layer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} newName
|
||||
* @param {Hash} newOptions
|
||||
*
|
||||
* @returns A clone of this OpenLayers.Layer
|
||||
* @returns An exact clone of this OpenLayers.Layer
|
||||
* @type OpenLayers.Layer
|
||||
*/
|
||||
clone: function (newName, newOptions) {
|
||||
|
||||
if (newName == null) {
|
||||
newName = this.name;
|
||||
}
|
||||
|
||||
var mergedOptions = null;
|
||||
if ( (this.options != null) || (newOptions != null) ) {
|
||||
// only merge options if there were or will be
|
||||
mergedOptions = Object.extend( {}, this.options);
|
||||
Object.extend(mergedOptions, newOptions);
|
||||
}
|
||||
|
||||
var clone = new OpenLayers.Layer(newName, mergedOptions);
|
||||
clone: function () {
|
||||
var clone = new OpenLayers.Layer(this.name,
|
||||
this.options);
|
||||
|
||||
return clone;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} newName
|
||||
*/
|
||||
setName: function(newName) {
|
||||
this.name = newName;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Hash} newOptions
|
||||
*/
|
||||
addOptions: function (newOptions) {
|
||||
|
||||
if (newOptions != null) {
|
||||
Object.extend(this.options, newOptions);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @params {OpenLayers.Bounds} bound
|
||||
|
||||
Reference in New Issue
Block a user