refactor range checking into map and store a state variable in layer so that we dont fire changelayer every time user zooms

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1606 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-10-05 19:32:07 +00:00
parent 3cf66a5779
commit 2b7c6cc844
3 changed files with 20 additions and 8 deletions

View File

@@ -130,7 +130,7 @@ OpenLayers.Control.LayerSwitcher.prototype =
inputElem.layer = layer;
inputElem.control = this;
if (!baseLayer && !layer.inRange()) {
if (!baseLayer && !layer.inRange) {
inputElem.disabled = true;
}
OpenLayers.Event.observe(inputElem, "mouseup",
@@ -138,7 +138,7 @@ OpenLayers.Control.LayerSwitcher.prototype =
// create span
var labelSpan = document.createElement("span");
if (!baseLayer && !layer.inRange()) {
if (!baseLayer && !layer.inRange) {
labelSpan.style.color = "grey";
}
labelSpan.innerHTML = layer.name;

View File

@@ -47,6 +47,14 @@ OpenLayers.Layer.prototype = {
*/
visibility: true,
/** Whether or not the map's current resolution is within this layer's
* min/max range -- this is set in map's setCenter() whenever zoom
* changes
*
* @type Boolean
*/
inRange: false,
// OPTIONS
/** @type Array */
@@ -186,10 +194,7 @@ OpenLayers.Layer.prototype = {
* @param {Boolean} dragging
*/
moveTo:function(bounds, zoomChanged, dragging) {
if (zoomChanged) {
this.display(this.visibility && this.inRange());
this.map.events.triggerEvent("changelayer");
}
this.display(this.visibility && this.inRange);
},
/** Set the map property for the layer. This is done through an accessor
@@ -266,7 +271,7 @@ OpenLayers.Layer.prototype = {
* current resolution
* @type Boolean
*/
inRange: function() {
calculateInRange: function() {
var inRange = false;
if (this.map) {
var resolution = this.map.getResolution();

View File

@@ -691,7 +691,14 @@ OpenLayers.Map.prototype = {
var bounds = this.getExtent();
for (var i = 0; i < this.layers.length; i++) {
var layer = this.layers[i];
if (zoomChanged || (layer.display && layer.inRange())) {
var inRange = layer.calculateInRange();
if (layer.inRange != inRange) {
layer.inRange = inRange;
this.events.triggerEvent("changelayer");
}
if (zoomChanged || (layer.display && layer.inRange)) {
layer.moveTo(bounds, zoomChanged, dragging);
}
}