diff --git a/lib/OpenLayers/Control/LayerSwitcher.js b/lib/OpenLayers/Control/LayerSwitcher.js index 703674faaf..20a3b8f2ad 100644 --- a/lib/OpenLayers/Control/LayerSwitcher.js +++ b/lib/OpenLayers/Control/LayerSwitcher.js @@ -129,11 +129,17 @@ OpenLayers.Control.LayerSwitcher.prototype = inputElem.defaultChecked = checked; inputElem.layer = layer; inputElem.control = this; + if (!layer.inRange()) { + inputElem.disabled = true; + } Event.observe(inputElem, "mouseup", this.onInputClick.bindAsEventListener(inputElem)); // create span var labelSpan = document.createElement("span"); + if (!layer.inRange()) { + labelSpan.style.color = "grey"; + } labelSpan.innerHTML = layer.name; labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : "baseline"; Event.observe(labelSpan, "click", @@ -169,13 +175,15 @@ OpenLayers.Control.LayerSwitcher.prototype = */ onInputClick: function(e) { - if (this.type == "radio") { - this.checked = true; - this.layer.map.setBaseLayer(this.layer, true); - this.layer.map.events.triggerEvent("changebaselayer"); - } else { - this.checked = !this.checked; - this.control.updateMap(); + if (!this.disabled) { + if (this.type == "radio") { + this.checked = true; + this.layer.map.setBaseLayer(this.layer, true); + this.layer.map.events.triggerEvent("changebaselayer"); + } else { + this.checked = !this.checked; + this.control.updateMap(); + } } Event.stop(e); }, diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 4c52dc43d1..89650b670f 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -41,6 +41,12 @@ OpenLayers.Layer.prototype = { * @type boolean */ displayInLayerSwitcher: true, + /** Whether or not the layer should be displayed in the map + * + * @type Boolean + */ + visibility: true, + // OPTIONS /** @type Array */ @@ -180,7 +186,10 @@ OpenLayers.Layer.prototype = { * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { - //this function can be implemented by subclasses. + if (zoomChanged) { + this.display(this.visibility && this.inRange()); + this.map.events.triggerEvent("changelayer"); + } }, /** Set the map property for the layer. This is done through an accessor @@ -211,27 +220,26 @@ OpenLayers.Layer.prototype = { this[properties[i]] = this.map[properties[i]]; } } - if (this.isBaseLayer) { - this.initResolutions(); - } + this.initResolutions(); }, /** - * @returns Whether or not the layer is visible + * @returns Whether or not the layer should be displayed (if in range) * @type Boolean */ getVisibility: function() { - return (this.div.style.display != "none"); + return this.visibility; }, /** - * @param {Boolean} visible + * @param {Boolean} visible Whether or not to display the layer + * (if in range) * @param {Boolean} noEvent */ - setVisibility: function(visible, noEvent) { - if (visible != this.getVisibility()) { - this.div.style.display = (visible) ? "block" : "none"; - if ((visible) && (this.map != null)) { + setVisibility: function(visibility, noEvent) { + if (visibility != this.visibility) { + this.visibility = visibility; + if (this.map != null) { var extent = this.map.getExtent(); if (extent != null) { this.moveTo(this.map.getExtent(), true); @@ -243,7 +251,31 @@ OpenLayers.Layer.prototype = { } } }, - + + /** + * @param {Boolean} display + */ + display: function(display) { + if (display != (this.div.style.display != "none")) { + this.div.style.display = (display) ? "block" : "none"; + } + }, + + /** + * @returns Whether or not the layer is displayable at the current map's + * current resolution + * @type Boolean + */ + inRange: function() { + var inRange = false; + if (this.map) { + var resolution = this.map.getResolution(); + inRange = ( (resolution >= this.minResolution) && + (resolution <= this.maxResolution) ); + } + return inRange; + }, + /** * @param {Boolean} isBaseLayer */ @@ -334,6 +366,16 @@ OpenLayers.Layer.prototype = { this.resolutions.sort( function(a,b) { return(b-a); }); + + this.minResolution = this.resolutions[this.resolutions.length - 1]; + this.maxResolution = this.resolutions[0]; + + this.minScale = + OpenLayers.Util.getScaleFromResolution(this.maxResolution, + this.units); + this.maxScale = + OpenLayers.Util.getScaleFromResolution(this.minResolution, + this.units); }, /** diff --git a/lib/OpenLayers/Layer/Canvas.js b/lib/OpenLayers/Layer/Canvas.js index 75a5a83a14..b65605f8c4 100644 --- a/lib/OpenLayers/Layer/Canvas.js +++ b/lib/OpenLayers/Layer/Canvas.js @@ -49,7 +49,9 @@ OpenLayers.Layer.Canvas.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { - this.redraw(); + OpenLayers.Layer.prototype.moveTo.apply(this, arguments); + + this.redraw(); }, setStrokeColor: function(color) { diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 9e939004b4..f5df94ea8e 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -76,6 +76,7 @@ OpenLayers.Layer.Google.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { + OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); if ((this.gmap != null) && (!this.dragging)) { diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index a0e064a8bf..3ca1574fb3 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -96,6 +96,8 @@ OpenLayers.Layer.Grid.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { + OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments); + if (bounds == null) { bounds = this.map.getExtent(); } diff --git a/lib/OpenLayers/Layer/Markers.js b/lib/OpenLayers/Layer/Markers.js index 6839fc0f60..ce7a0c25cb 100644 --- a/lib/OpenLayers/Layer/Markers.js +++ b/lib/OpenLayers/Layer/Markers.js @@ -48,6 +48,8 @@ OpenLayers.Layer.Markers.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { + OpenLayers.Layer.prototype.moveTo.apply(this, arguments); + if (zoomChanged) { this.redraw(); } diff --git a/lib/OpenLayers/Layer/MultiMap.js b/lib/OpenLayers/Layer/MultiMap.js index 084df8ea1e..b5f5714a59 100644 --- a/lib/OpenLayers/Layer/MultiMap.js +++ b/lib/OpenLayers/Layer/MultiMap.js @@ -47,6 +47,7 @@ OpenLayers.Layer.MultiMap.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { + OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); if (this.multimap != null) { var olCenter = this.map.getCenter(); diff --git a/lib/OpenLayers/Layer/VirtualEarth.js b/lib/OpenLayers/Layer/VirtualEarth.js index eb91961a20..270be22190 100644 --- a/lib/OpenLayers/Layer/VirtualEarth.js +++ b/lib/OpenLayers/Layer/VirtualEarth.js @@ -50,6 +50,7 @@ OpenLayers.Layer.VirtualEarth.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { + OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); if (this.vemap != null) { diff --git a/lib/OpenLayers/Layer/Yahoo.js b/lib/OpenLayers/Layer/Yahoo.js index 331cc2883e..84121a5c1e 100644 --- a/lib/OpenLayers/Layer/Yahoo.js +++ b/lib/OpenLayers/Layer/Yahoo.js @@ -47,6 +47,7 @@ OpenLayers.Layer.Yahoo.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { + OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); if (this.yahoomap != null) { var olCenter = this.map.getCenter(); diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index f6368b5327..3b12280895 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -620,7 +620,7 @@ OpenLayers.Map.prototype = { var bounds = this.getExtent(); for (var i = 0; i < this.layers.length; i++) { var layer = this.layers[i]; - if (layer.getVisibility()) { + if (zoomChanged || (layer.display && layer.inRange())) { layer.moveTo(bounds, zoomChanged, dragging); } }