OpenLayers OpenLayers

Changeset 1577

Show
Ignore:
Timestamp:
10/05/06 00:20:16 (2 years ago)
Author:
euzuro
Message:

add a new property to layer.js called 'visibility' which we now need to store instead of reading directly from the visiblity of the div itself, since the div might be hidden, but only because it is out of range. we thus add a new method on layer called inRange() which returns whether or not the layer's max/min resolution settings allow it to be displayed at the current map's resolution. to make sure that min/max resolution, scale, etc are set for *all* layers, we remove the if statement limiting the running of initResolution() to only baselayers, and we add code at the end of that function that, once the resolutions array has been calculated, then goes back and sets min/max scale and resolution. now what we have to do is every time moveTo() is called on a layer, if the zoom has changed, then we must check if the layer is inRange() and update the display accordingly. on that same note, the layerswitcher must now be attentive to these changes, so we set it to redraw every time the zoom changes. in the layerswitcher code, we now add special code to disable a layer if it is out of range. must add the superclass call to moveTo() for all of the layers to ensure this code is executed for all. update test.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Control/LayerSwitcher.js

    r1539 r1577  
    130130                inputElem.layer = layer; 
    131131                inputElem.control = this; 
     132                if (!layer.inRange()) { 
     133                    inputElem.disabled = true; 
     134                } 
    132135                Event.observe(inputElem, "mouseup",  
    133136                              this.onInputClick.bindAsEventListener(inputElem)); 
     
    135138                // create span 
    136139                var labelSpan = document.createElement("span"); 
     140                if (!layer.inRange()) { 
     141                    labelSpan.style.color = "grey"; 
     142                } 
    137143                labelSpan.innerHTML = layer.name; 
    138144                labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : "baseline"; 
     
    170176 
    171177    onInputClick: function(e) { 
    172         if (this.type == "radio") { 
    173             this.checked = true; 
    174             this.layer.map.setBaseLayer(this.layer, true); 
    175             this.layer.map.events.triggerEvent("changebaselayer"); 
    176         } else { 
    177             this.checked = !this.checked; 
    178             this.control.updateMap(); 
     178        if (!this.disabled) { 
     179            if (this.type == "radio") { 
     180                this.checked = true; 
     181                this.layer.map.setBaseLayer(this.layer, true); 
     182                this.layer.map.events.triggerEvent("changebaselayer"); 
     183            } else { 
     184                this.checked = !this.checked; 
     185                this.control.updateMap(); 
     186            } 
    179187        } 
    180188        Event.stop(e); 
  • trunk/openlayers/lib/OpenLayers/Layer.js

    r1576 r1577  
    4141     * @type boolean */ 
    4242    displayInLayerSwitcher: true, 
     43 
     44    /** Whether or not the layer should be displayed in the map 
     45     *  
     46     * @type Boolean 
     47     */ 
     48    visibility: true, 
    4349 
    4450  // OPTIONS 
     
    181187     */ 
    182188    moveTo:function(bounds, zoomChanged, dragging) { 
    183         //this function can be implemented by subclasses. 
     189        if (zoomChanged) { 
     190            this.display(this.visibility && this.inRange()); 
     191            this.map.events.triggerEvent("changelayer"); 
     192        } 
    184193    }, 
    185194 
     
    212221            }     
    213222        } 
    214         if (this.isBaseLayer) { 
    215             this.initResolutions(); 
    216         }     
     223        this.initResolutions(); 
    217224    }, 
    218225   
    219226    /** 
    220     * @returns Whether or not the layer is visible 
     227    * @returns Whether or not the layer should be displayed (if in range) 
    221228    * @type Boolean 
    222229    */ 
    223230    getVisibility: function() { 
    224         return (this.div.style.display != "none")
     231        return this.visibility
    225232    }, 
    226233 
    227234    /**  
    228      * @param {Boolean} visible 
     235     * @param {Boolean} visible Whether or not to display the layer  
     236     *                          (if in range) 
    229237     * @param {Boolean} noEvent 
    230238     */ 
    231     setVisibility: function(visible, noEvent) { 
    232         if (visible != this.getVisibility()) { 
    233             this.div.style.display = (visible) ? "block" : "none"
    234             if ((visible) && (this.map != null)) { 
     239    setVisibility: function(visibility, noEvent) { 
     240        if (visibility != this.visibility) { 
     241            this.visibility = visibility
     242            if (this.map != null) { 
    235243                var extent = this.map.getExtent(); 
    236244                if (extent != null) { 
     
    244252        } 
    245253    }, 
    246      
     254 
     255    /**  
     256     * @param {Boolean} display 
     257     */ 
     258    display: function(display) { 
     259        if (display != (this.div.style.display != "none")) { 
     260            this.div.style.display = (display) ? "block" : "none"; 
     261        } 
     262    }, 
     263 
     264    /** 
     265     * @returns Whether or not the layer is displayable at the current map's 
     266     *          current resolution 
     267     * @type Boolean 
     268     */ 
     269    inRange: function() { 
     270        var inRange = false; 
     271        if (this.map) { 
     272            var resolution = this.map.getResolution(); 
     273            inRange = ( (resolution >= this.minResolution) && 
     274                        (resolution <= this.maxResolution) ); 
     275        } 
     276        return inRange; 
     277    }, 
     278 
    247279    /**  
    248280     * @param {Boolean} isBaseLayer  
     
    335367                                   return(b-a); 
    336368                               }); 
     369 
     370        this.minResolution = this.resolutions[this.resolutions.length - 1]; 
     371        this.maxResolution = this.resolutions[0]; 
     372         
     373        this.minScale =  
     374            OpenLayers.Util.getScaleFromResolution(this.maxResolution,  
     375                                                   this.units); 
     376        this.maxScale =  
     377            OpenLayers.Util.getScaleFromResolution(this.minResolution,  
     378                                                   this.units); 
    337379    }, 
    338380 
  • trunk/openlayers/lib/OpenLayers/Layer/Canvas.js

    r1538 r1577  
    5050     */ 
    5151    moveTo:function(bounds, zoomChanged, dragging) { 
    52             this.redraw(); 
     52        OpenLayers.Layer.prototype.moveTo.apply(this, arguments); 
     53 
     54        this.redraw(); 
    5355    }, 
    5456 
  • trunk/openlayers/lib/OpenLayers/Layer/Google.js

    r1538 r1577  
    7777     */ 
    7878    moveTo:function(bounds, zoomChanged, dragging) { 
     79        OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); 
    7980 
    8081        if ((this.gmap != null) && (!this.dragging)) { 
  • trunk/openlayers/lib/OpenLayers/Layer/Grid.js

    r1437 r1577  
    9797     */ 
    9898    moveTo:function(bounds, zoomChanged, dragging) { 
     99        OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments); 
     100         
    99101        if (bounds == null) { 
    100102            bounds = this.map.getExtent(); 
  • trunk/openlayers/lib/OpenLayers/Layer/Markers.js

    r1538 r1577  
    4949     */ 
    5050    moveTo:function(bounds, zoomChanged, dragging) { 
     51        OpenLayers.Layer.prototype.moveTo.apply(this, arguments); 
     52 
    5153        if (zoomChanged) { 
    5254            this.redraw(); 
  • trunk/openlayers/lib/OpenLayers/Layer/MultiMap.js

    r1538 r1577  
    4848     */ 
    4949    moveTo:function(bounds, zoomChanged, dragging) { 
     50        OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); 
    5051 
    5152        if (this.multimap != null) { 
  • trunk/openlayers/lib/OpenLayers/Layer/VirtualEarth.js

    r1538 r1577  
    5151     */ 
    5252    moveTo:function(bounds, zoomChanged, dragging) { 
     53        OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); 
    5354 
    5455        if (this.vemap != null) { 
  • trunk/openlayers/lib/OpenLayers/Layer/Yahoo.js

    r1538 r1577  
    4848     */ 
    4949    moveTo:function(bounds, zoomChanged, dragging) { 
     50        OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); 
    5051 
    5152        if (this.yahoomap != null) { 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r1538 r1577  
    621621            for (var i = 0; i < this.layers.length; i++) { 
    622622                var layer = this.layers[i]; 
    623                 if (layer.getVisibility()) { 
     623                if (zoomChanged || (layer.display && layer.inRange())) { 
    624624                    layer.moveTo(bounds, zoomChanged, dragging); 
    625625                }