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

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); this.addOptions(options);
//add options to layer
OpenLayers.Util.extend(this, this.options);
this.name = name; this.name = name;
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); if (this.id == null) {
if (this.div == null) { this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
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);
}
}, },
/** /**
@@ -187,7 +186,7 @@ OpenLayers.Layer.prototype = {
this.name = null; this.name = null;
this.div = null; this.div = null;
this.options = null; this.options = null;
if (this.events) { if (this.events) {
this.events.destroy(); this.events.destroy();
} }
@@ -218,9 +217,12 @@ OpenLayers.Layer.prototype = {
* @param {String} newName * @param {String} newName
*/ */
setName: function(newName) { setName: function(newName) {
this.name = newName; if (newName != this.name) {
if (this.map != null) this.name = newName;
this.map.events.triggerEvent("changelayer"); if (this.map != null) {
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,22 +272,25 @@ OpenLayers.Layer.prototype = {
* @param {OpenLayers.Map} map * @param {OpenLayers.Map} map
*/ */
setMap: function(map) { setMap: function(map) {
this.map = map; if (this.map == null) {
// grab some essential layer data from the map if it hasn't already this.map = map;
// been set
this.maxExtent = this.maxExtent || this.map.maxExtent; // grab some essential layer data from the map if it hasn't already
this.projection = this.projection || this.map.projection; // been set
this.units = this.units || this.map.units; this.maxExtent = this.maxExtent || this.map.maxExtent;
this.projection = this.projection || this.map.projection;
this.initResolutions(); this.units = this.units || this.map.units;
if (!this.isBaseLayer) { this.initResolutions();
this.inRange = this.calculateInRange();
if (!this.isBaseLayer) {
this.inRange = this.calculateInRange();
}
// deal with gutters
this.setTileSize();
} }
// deal with gutters
this.setTileSize();
}, },
/** /**
@@ -380,9 +389,11 @@ OpenLayers.Layer.prototype = {
* @param {Boolean} isBaseLayer * @param {Boolean} isBaseLayer
*/ */
setIsBaseLayer: function(isBaseLayer) { setIsBaseLayer: function(isBaseLayer) {
this.isBaseLayer = isBaseLayer; if (isBaseLayer != this.isBaseLayer) {
if (this.map != null) { this.isBaseLayer = isBaseLayer;
this.map.events.triggerEvent("changelayer"); if (this.map != null) {
this.map.events.triggerEvent("changelayer");
}
} }
}, },
@@ -648,11 +659,13 @@ OpenLayers.Layer.prototype = {
* @param {Float} opacity * @param {Float} opacity
*/ */
setOpacity: function(opacity) { setOpacity: function(opacity) {
this.opacity = opacity; if (opacity != this.opacity) {
for(var i=0; i<this.div.childNodes.length; ++i) { this.opacity = opacity;
var element = this.div.childNodes[i].firstChild; for(var i=0; i<this.div.childNodes.length; ++i) {
OpenLayers.Util.modifyDOMElement(element, null, null, null, var element = this.div.childNodes[i].firstChild;
null, null, null, opacity); OpenLayers.Util.modifyDOMElement(element, null, null, null,
null, null, null, opacity);
}
} }
}, },