OpenLayers OpenLayers

Ticket #987: layer.patch

File layer.patch, 3.8 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(14); 
    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.");      
    209214 
    210215        map.destroy(); 
    211216         
  • 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: false,    
     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. 
    683698        // 
     699 
     700        var useInRange = false; 
    684701        var confProps = {};         
    685702        for(var i=0, len=props.length; i<len; i++) { 
    686703            var property = props[i]; 
     704             
     705            // If the layer had one of these properties set *and* the property 
     706            // is not a non-scale property, then the user intended to use 
     707            // scale-dependant display. 
     708            if (this.options[property] && OpenLayers.Util.indexOf(notScaleProps, property) == -1) { 
     709                useInRange = true; 
     710            } 
     711                    
    687712            confProps[property] = this.options[property] || this.map[property]; 
    688713        } 
     714         
     715        this.alwaysInRange = !useInRange; 
    689716 
    690717        // Do not use the scales/resolutions at the map level if 
    691718        // minScale/minResolution and maxScale/maxResolution are