OpenLayers OpenLayers

Changeset 6332

Show
Ignore:
Timestamp:
02/20/08 19:03:11 (11 months ago)
Author:
tschaub
Message:

Respecting minResolution and maxScale if specified in the layer options. r=ahocevar (closes #1321)

Files:

Legend:

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

    r6149 r6332  
    716716 
    717717            // determine numZoomLevels if not already set on the layer 
     718            // this gives numZoomLevels assuming approximately base 2 scaling 
    718719            if (confProps.minResolution != null && 
    719720                this.options.numZoomLevels == undefined) { 
     
    728729            var base = 2; 
    729730            if(typeof confProps.minResolution == "number" && 
    730                this.options.numZoomLevels > 1) { 
     731               confProps.numZoomLevels > 1) { 
    731732                /** 
    732                  * If numZoomLevels is explicitly set in the layer options, 
    733                  * respect it.  If numZoomLevels is not specified, we use 
    734                  * exponential scaling with a base of 2.  If numZoomLevels 
    735                  * is specified, we use exponential scaling and determine the 
    736                  * appropriate base so minResolution is reached. 
     733                 * If maxResolution and minResolution are set (or related 
     734                 * scale properties), we calculate the base for exponential 
     735                 * scaling that starts at maxResolution and ends at 
     736                 * minResolution in numZoomLevels steps. 
    737737                 */ 
    738738                base = Math.pow( 
  • trunk/openlayers/tests/test_Layer.html

    r5982 r6332  
    121121     
    122122    function test_Layer_initResolutions(t) { 
    123         t.plan(3); 
     123        t.plan(12); 
    124124        var map = new OpenLayers.Map("map"); 
    125         var options = { 
    126             minResolution: 1, 
    127             maxResolution: 10, 
    128             numZoomLevels: 5 
    129         }; 
    130         var layer = new OpenLayers.Layer("test", options); 
    131         layer.map = map; 
     125        var options, layer; 
     126         
     127        // three tests for minResolution, maxResolution, and numZoomLevels 
     128        options = { 
     129            minResolution: 1.5, 
     130            maxResolution: 10.5, 
     131            numZoomLevels: 5, 
     132            map: map 
     133        }; 
     134        layer = new OpenLayers.Layer("test", options); 
    132135        layer.initResolutions(); 
    133         t.eq(layer.minResolution.toPrecision(9), (1).toPrecision(9), 
    134              "layer minResolution preserved"); 
    135         t.eq(layer.maxResolution.toPrecision(9), (10).toPrecision(9), 
    136              "layer maxResolution preserved"); 
    137         t.eq(layer.numZoomLevels, 5, "layer numZoomLevels preserved");  
     136        t.eq(layer.minResolution.toPrecision(6), (1.5).toPrecision(6), 
     137             "(with numZoomLevels) layer minResolution preserved"); 
     138        t.eq(layer.maxResolution.toPrecision(6), (10.5).toPrecision(6), 
     139             "(with numZoomLevels) layer maxResolution preserved"); 
     140        t.eq(layer.numZoomLevels, 5, "(with numZoomLevels) layer numZoomLevels preserved"); 
     141         
     142        // three tests for minResolution, and maxResolution 
     143        options = { 
     144            minResolution: 1.5, 
     145            maxResolution: 10.5, 
     146            map: map 
     147        }; 
     148        layer = new OpenLayers.Layer("test", options); 
     149        layer.initResolutions(); 
     150        t.eq(layer.minResolution.toPrecision(6), (1.5).toPrecision(6), 
     151             "(without numZoomLevels) layer minResolution preserved"); 
     152        t.eq(layer.maxResolution.toPrecision(6), (10.5).toPrecision(6), 
     153             "(without numZoomLevels) layer maxResolution preserved"); 
     154        t.eq(layer.numZoomLevels, 3, "(without numZoomLevels) layer numZoomLevels calculated"); 
     155         
     156        // three tests for minScale, maxScale, and numZoomLevels 
     157        options = { 
     158            minScale: 105, 
     159            maxScale: 15, 
     160            numZoomLevels: 10, 
     161            map: map 
     162        }; 
     163        layer = new OpenLayers.Layer("test", options); 
     164        layer.initResolutions(); 
     165        t.eq(layer.minScale.toPrecision(6), (105).toPrecision(6), 
     166             "(with numZoomLevels) layer minScale preserved"); 
     167        t.eq(layer.maxScale.toPrecision(6), (15).toPrecision(6), 
     168             "(with numZoomLevels) layer maxScale preserved"); 
     169        t.eq(layer.numZoomLevels, 10, "(with numZoomLevels) layer numZoomLevels preserved"); 
     170         
     171        // three tests for minScale, and maxScale 
     172        options = { 
     173            minScale: 1555, 
     174            maxScale: 155, 
     175            map: map 
     176        }; 
     177        layer = new OpenLayers.Layer("test", options); 
     178        layer.initResolutions(); 
     179        t.eq(layer.minScale.toPrecision(6), (1555).toPrecision(6), 
     180             "(without numZoomLevels) layer minScale preserved"); 
     181        t.eq(layer.maxScale.toPrecision(6), (155).toPrecision(6), 
     182             "(without numZoomLevels) layer maxScale preserved"); 
     183        t.eq(layer.numZoomLevels, 4, "(without numZoomLevels) layer numZoomLevels calculated"); 
     184 
     185        map.destroy(); 
     186         
     187         
    138188    } 
    139189