OpenLayers OpenLayers

Ticket #987: layer.2.patch

File layer.2.patch, 4.2 kB (added by crschmidt, 4 months ago)
  • tests/Layer.html

    old new  
    145145    } 
    146146 
    147147    function test_Layer_initResolutions(t) { 
    148         t.plan(12); 
     148        t.plan(15); 
    149149        var map = new OpenLayers.Map("map"); 
    150150        var options, layer; 
    151151         
    152         // three tests for minResolution, maxResolution, and numZoomLevels 
     152        // tests for minResolution, maxResolution, and numZoomLevels 
    153153        options = { 
    154154            minResolution: 1.5, 
    155155            maxResolution: 10.5, 
     
    163163        t.eq(layer.maxResolution.toPrecision(6), (10.5).toPrecision(6), 
    164164             "(with numZoomLevels) layer maxResolution preserved"); 
    165165        t.eq(layer.numZoomLevels, 5, "(with numZoomLevels) layer numZoomLevels preserved"); 
    166          
     166        t.eq(layer.alwaysInRange, false, "Always in range is set to false due to passed options.")         
     167 
    167168        // three tests for minResolution, and maxResolution 
    168169        options = { 
    169170            minResolution: 1.5, 
     
    206207        t.eq(layer.maxScale.toPrecision(6), (155).toPrecision(6), 
    207208             "(without numZoomLevels) layer maxScale preserved"); 
    208209        t.eq(layer.numZoomLevels, 4, "(without numZoomLevels) layer numZoomLevels calculated"); 
     210         
     211        layer = new OpenLayers.Layer("test", {'projection': 'EPSG:4326', 'map': map}); 
     212        layer.initResolutions(); 
     213        t.eq(layer.alwaysInRange, true, "always in range true if only get projection.");      
     214         
     215        OpenLayers.Layer.prototype.alwaysInRange = false; 
     216        layer = new OpenLayers.Layer("test", {'projection': 'EPSG:4326', 'map': map}); 
     217        layer.initResolutions(); 
     218        t.eq(layer.alwaysInRange, false, "always in range true if overridden on prototype.");      
     219        OpenLayers.Layer.prototype.alwaysInRange = null; 
    209220 
    210221        map.destroy(); 
    211222         
  • lib/OpenLayers/Layer.js

    old new  
    3838    opacity: null, 
    3939 
    4040    /** 
     41     * APIProperty: alwaysInRange 
     42     * {Boolean} If a layer should not use scale-based display properties, 
     43     *     this should be set to true. This will cause the layer, as an 
     44     *     overlay, to always be 'active'. By default, this is set to 
     45     *     true on overlays which do not pass any explicit scale-based options 
     46     *     in the options of the layer. 
     47     */ 
     48    alwaysInRange: null,    
     49 
     50    /** 
    4151     * Constant: EVENT_TYPES 
    4252     * {Array(String)} Supported application event types.  Register a listener 
    4353     *     for a particular event with the following syntax: 
     
    618628     *     resolution. 
    619629     */ 
    620630    calculateInRange: function() { 
     631        if (this.alwaysInRange) { 
     632            return true; 
     633        } 
    621634        var inRange = false; 
    622635        if (this.map) { 
    623636            var resolution = this.map.getResolution(); 
     
    677690          'numZoomLevels', 'maxZoomLevel' 
    678691        ); 
    679692 
     693        var notScaleProps = ['projection', 'units'];     
     694 
    680695        // First we create a new object where we will store all of the  
    681696        //  resolution-related properties that we find in either the layer's 
    682697        //  'options' array or from the map. 
    683         // 
     698 
     699        var useInRange = false; 
    684700        var confProps = {};         
    685701        for(var i=0, len=props.length; i<len; i++) { 
    686702            var property = props[i]; 
     703             
     704            // If the layer had one of these properties set *and* the property 
     705            // is not a non-scale property, then the user intended to use 
     706            // scale-dependant display. 
     707            if (this.options[property] && OpenLayers.Util.indexOf(notScaleProps, property) == -1) { 
     708                useInRange = true; 
     709            } 
     710                    
    687711            confProps[property] = this.options[property] || this.map[property]; 
    688712        } 
     713         
     714        this.alwaysInRange = (this.alwaysInRange == null) ? !useInRange : this.alwaysInRange; 
    689715 
    690716        // Do not use the scales/resolutions at the map level if 
    691717        // minScale/minResolution and maxScale/maxResolution are