EventPane now works -- puts a transparent pane over a layer and passes events through it down to the map.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1193 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Schuyler Erle
2006-08-11 18:00:07 +00:00
parent 1726680b10
commit b6d91edda4
2 changed files with 32 additions and 63 deletions

View File

@@ -6,6 +6,21 @@
*/
OpenLayers.Layer.EventPane = Class.create();
OpenLayers.Layer.EventPane.prototype = Object.extend(new OpenLayers.Layer, {
/** EventPaned layers are always base layers, by necessity.
* @type Boolean
*/
isBaseLayer: true,
/** EventPaned layers are fixed by default.
* @type Boolean
*/
isFixed: true,
/**
* @type HTMLDOMElement
*/
pane: null,
/**
* @constructor
*
@@ -14,46 +29,16 @@ OpenLayers.Layer.EventPane.prototype = Object.extend(new OpenLayers.Layer, {
*/
initialize: function(name, options) {
if (arguments.length > 0) {
//store a copy of the custom options for later cloning
this.options = Object.extend(new Object(), options);
//add options to layer
Object.extend(this, this.options);
this.name = name;
//generate unique id based on name
this.id = OpenLayers.Util.createUniqueID("Layer_");
if (this.div == null) {
this.div = OpenLayers.Util.createDiv();
this.div.style.width = "100%";
this.div.style.height = "100%";
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
if (this.pane == null) {
this.pane = OpenLayers.Util.createDiv();
this.pane.style.width = "100%";
this.pane.style.height = "100%";
this.pane.style.backgroundColor = "transparent";
}
}
},
/**
* @returns An exact clone of this OpenLayers.Layer
* @type OpenLayers.Layer
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer(this.name, this.options);
}
// catch any randomly tagged-on properties
obj = OpenLayers.Util.applyDefaults(obj, this);
// a cloned layer should never have its map property set
// because it has not been added to a map yet.
obj.map = null;
return obj;
},
/** Set the map property for the layer. This is done through an accessor
* so that subclasses can override this and take special action once
* they have their map variable set.
@@ -61,21 +46,15 @@ OpenLayers.Layer.EventPane.prototype = Object.extend(new OpenLayers.Layer, {
* @param {OpenLayers.Map} map
*/
setMap: function(map) {
this.map = map;
var properties = new Array(
'projection', 'minExtent', 'maxExtent',
'minScale', 'maxScale',
'maxResolution', 'minResolution',
'minZoomLevel', 'maxZoomLevel', 'units',
'scales', 'resolutions'
);
for(var i=0; i < properties.length; i++) {
if (this[properties[i]] == null) {
this[properties[i]] = this.map[properties[i]];
}
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
this.pane.style.zIndex = parseInt(this.div.style.zIndex) + 1;
this.pane.style.display = this.div.style.display;
if (this.isFixed) {
this.map.viewPortDiv.appendChild(this.pane);
} else {
this.map.layerContainerDiv.appendChild(this.pane);
}
this.map.events.attachToElement(this.pane);
},
/**
@@ -83,19 +62,8 @@ OpenLayers.Layer.EventPane.prototype = Object.extend(new OpenLayers.Layer, {
* @param {Boolean} noEvent
*/
setVisibility: function(visible, noEvent) {
if (visible != this.getVisibility()) {
this.div.style.display = (visible) ? "block" : "none";
if ((visible) && (this.map != null)) {
var extent = this.map.getExtent();
if (extent != null) {
this.moveTo(this.map.getExtent());
}
}
if ((this.map != null) &&
((noEvent == null) || (noEvent == false))) {
this.map.events.triggerEvent("changelayer");
}
}
OpenLayers.Layer.prototype.setVisibility.apply(this, arguments);
this.pane.style.display = this.div.style.display;
},
/** @final @type String */