fix for #643. layer class can be safely doubled up now

git-svn-id: http://svn.openlayers.org/trunk/openlayers@3035 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-04-09 15:00:10 +00:00
parent 057d574ec1
commit 1603d5a8ba
+21 -8
View File
@@ -148,24 +148,23 @@ OpenLayers.Layer.prototype = {
* @param {Object} options Hashtable of extra options to tag onto the layer * @param {Object} options Hashtable of extra options to tag onto the layer
*/ */
initialize: function(name, options) { initialize: function(name, options) {
//store a copy of the custom options for later cloning
this.options = OpenLayers.Util.extend(new Object(), options);
//add options to layer this.addOptions(options);
OpenLayers.Util.extend(this, this.options);
this.name = name; this.name = name;
if (this.id == null) {
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
if (this.div == null) {
this.div = OpenLayers.Util.createDiv(); this.div = OpenLayers.Util.createDiv();
this.div.style.width = "100%"; this.div.style.width = "100%";
this.div.style.height = "100%"; this.div.style.height = "100%";
this.div.id = this.id; this.div.id = this.id;
}
this.events = new OpenLayers.Events(this, this.div, this.EVENT_TYPES); this.events = new OpenLayers.Events(this, this.div,
this.EVENT_TYPES);
}
}, },
/** /**
@@ -218,9 +217,12 @@ OpenLayers.Layer.prototype = {
* @param {String} newName * @param {String} newName
*/ */
setName: function(newName) { setName: function(newName) {
if (newName != this.name) {
this.name = newName; this.name = newName;
if (this.map != null) if (this.map != null) {
this.map.events.triggerEvent("changelayer"); this.map.events.triggerEvent("changelayer");
}
}
}, },
/** /**
@@ -228,6 +230,10 @@ OpenLayers.Layer.prototype = {
*/ */
addOptions: function (newOptions) { addOptions: function (newOptions) {
if (this.options == null) {
this.options = new Object();
}
// update our copy for clone // update our copy for clone
OpenLayers.Util.extend(this.options, newOptions); OpenLayers.Util.extend(this.options, newOptions);
@@ -266,6 +272,8 @@ OpenLayers.Layer.prototype = {
* @param {OpenLayers.Map} map * @param {OpenLayers.Map} map
*/ */
setMap: function(map) { setMap: function(map) {
if (this.map == null) {
this.map = map; this.map = map;
// grab some essential layer data from the map if it hasn't already // grab some essential layer data from the map if it hasn't already
@@ -282,6 +290,7 @@ OpenLayers.Layer.prototype = {
// deal with gutters // deal with gutters
this.setTileSize(); this.setTileSize();
}
}, },
/** /**
@@ -380,10 +389,12 @@ OpenLayers.Layer.prototype = {
* @param {Boolean} isBaseLayer * @param {Boolean} isBaseLayer
*/ */
setIsBaseLayer: function(isBaseLayer) { setIsBaseLayer: function(isBaseLayer) {
if (isBaseLayer != this.isBaseLayer) {
this.isBaseLayer = isBaseLayer; this.isBaseLayer = isBaseLayer;
if (this.map != null) { if (this.map != null) {
this.map.events.triggerEvent("changelayer"); this.map.events.triggerEvent("changelayer");
} }
}
}, },
/********************************************************/ /********************************************************/
@@ -648,12 +659,14 @@ OpenLayers.Layer.prototype = {
* @param {Float} opacity * @param {Float} opacity
*/ */
setOpacity: function(opacity) { setOpacity: function(opacity) {
if (opacity != this.opacity) {
this.opacity = opacity; this.opacity = opacity;
for(var i=0; i<this.div.childNodes.length; ++i) { for(var i=0; i<this.div.childNodes.length; ++i) {
var element = this.div.childNodes[i].firstChild; var element = this.div.childNodes[i].firstChild;
OpenLayers.Util.modifyDOMElement(element, null, null, null, OpenLayers.Util.modifyDOMElement(element, null, null, null,
null, null, null, opacity); null, null, null, opacity);
} }
}
}, },
/** /**