Add map.getNumLayers(), map.getLayerIndex(), map.setLayerIndex(), map.raiseLayer() to support moving layers up and down in the map stack.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1604 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Schuyler Erle
2006-10-05 19:07:19 +00:00
parent 8782ee3e15
commit fee4d6f973
2 changed files with 108 additions and 4 deletions

View File

@@ -255,14 +255,23 @@ OpenLayers.Map.prototype = {
return foundLayer;
},
/**
* @param {OpenLayers.Layer} layer
* @param {int} zIdx
* @private
*/
setLayerZIndex: function (layer, zIdx) {
layer.div.style.zIndex =
this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay']
+ zIdx * 5;
},
/**
* @param {OpenLayers.Layer} layer
*/
addLayer: function (layer) {
layer.div.style.overflow = "";
layer.div.style.zIndex =
this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay']
+ this.layers.length * 5;
this.setLayerZIndex(layer, this.layers.length);
if (layer.isFixed) {
this.viewPortDiv.appendChild(layer.div);
@@ -346,6 +355,62 @@ OpenLayers.Map.prototype = {
}
this.events.triggerEvent("removelayer");
},
/**
* @returns The number of layers attached to the map.
* @type int
*/
getNumLayers: function () {
return this.layers.length;
},
/**
* @returns The current (zero-based) index of the given layer in the map's
* layer stack. Returns -1 if the layer isn't on the map.
*
* @param {OpenLayers.Layer} layer
* @type int
*/
getLayerIndex: function (layer) {
return OpenLayers.Util.indexOf(this.layers, layer);
},
/** Move the given layer to the specified (zero-based) index in the layer
* list, changing its z-index in the map display. Use
* map.getLayerIndex() to find out the current index of a layer. Note
* that this cannot (or at least should not) be effectively used to
* raise base layers above overlays.
*
* @param {OpenLayers.Layer} layer
* @param {int} idx
*/
setLayerIndex: function (layer, idx) {
var base = this.getLayerIndex(layer);
if (idx < 0)
idx = 0;
else if (idx > this.layers.length)
idx = this.layers.length;
if (base != idx) {
this.layers.splice(base, 1);
this.layers.splice(idx, 0, layer);
for (var i = 0; i < this.layers.length; i++)
this.setLayerZIndex(this.layers[i], i);
this.events.triggerEvent("changelayer");
}
},
/** Change the index of the given layer by delta. If delta is positive,
* the layer is moved up the map's layer stack; if delta is negative,
* the layer is moved down. Again, note that this cannot (or at least
* should not) be effectively used to raise base layers above overlays.
*
* @param {OpenLayers.Layer} layer
* @param {int} idx
*/
raiseLayer: function (layer, delta) {
var idx = this.getLayerIndex(layer) + delta;
this.setLayerIndex(layer, idx);
},
/** Allows user to specify one of the currently-loaded layers as the Map's
* new base layer.