OpenLayers OpenLayers

Changeset 7948

Show
Ignore:
Timestamp:
09/04/08 14:35:40 (3 months ago)
Author:
euzuro
Message:

fix a somewhat broken FixedZoomLevels.js functionality -- the 'maxZoomLevels' property if set on a layer was not getting processed correctly. This patch fixes that issue, as well as adding a cole-slaw-sized blerb of comments explaining the rules of precedence wrt resolution setting for 3rd party layers (those who subclass FixedZoomLevels). Thanks to tschaub for poking me to clarify this previously messy territory, and for cr5 for kindly taking the time to review my patch. (Closes #1182)

Files:

Legend:

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

    r7627 r7948  
    9191        }         
    9292 
     93        // 
     94        // At this point, we know what the minimum desired zoom level is, and 
     95        //  we must calculate the total number of zoom levels.  
     96        //   
     97        //  Because we allow for the setting of either the 'numZoomLevels' 
     98        //   or the 'maxZoomLevel' properties... on either the layer or the   
     99        //   map, we have to define some rules to see which we take into 
     100        //   account first in this calculation.  
     101        // 
     102        // The following is the precedence list for these properties: 
     103        //  
     104        // (1) numZoomLevels set on layer 
     105        // (2) maxZoomLevel set on layer 
     106        // (3) numZoomLevels set on map 
     107        // (4) maxZoomLevel set on map* 
     108        // (5) none of the above* 
     109        // 
     110        // *Note that options (4) and (5) are only possible if the user  
     111        //  _explicitly_ sets the 'numZoomLevels' property on the map to  
     112        //  null, since it is set by default to 16.  
     113        // 
     114 
     115        // 
     116        // Note to future: In 3.0, I think we should remove the default  
     117        // value of 16 for map.numZoomLevels. Rather, I think that value  
     118        // should be set as a default on the Layer.WMS class. If someone 
     119        // creates a 3rd party layer and does not specify any 'minZoomLevel',  
     120        // 'maxZoomLevel', or 'numZoomLevels', and has not explicitly  
     121        // specified any of those on the map object either.. then I think 
     122        // it is fair to say that s/he wants all the zoom levels available. 
     123        //  
     124        // By making map.numZoomLevels *null* by default, that will be the  
     125        // case. As it is, I don't feel comfortable changing that right now 
     126        // as it would be a glaring API change and actually would probably 
     127        // break many peoples' codes.  
     128        // 
     129 
     130        //the number of zoom levels we'd like to have. 
     131        var desiredZoomLevels; 
     132 
     133        //this is the maximum number of zoom levels the layer will allow,  
     134        // given the specified starting minimum zoom level. 
    93135        var limitZoomLevels = this.MAX_ZOOM_LEVEL - this.minZoomLevel + 1; 
    94         if (this.numZoomLevels != null) { 
    95             this.numZoomLevels = Math.min(this.numZoomLevels, limitZoomLevels); 
     136 
     137        if ( ((this.options.numZoomLevels == null) &&  
     138              (this.options.maxZoomLevel != null)) // (2) 
     139              || 
     140             ((this.numZoomLevels == null) && 
     141              (this.maxZoomLevel != null)) // (4) 
     142           ) { 
     143            //calculate based on specified maxZoomLevel (on layer or map) 
     144            desiredZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1; 
    96145        } else { 
    97             if (this.maxZoomLevel != null) { 
    98                 var zoomDiff = this.maxZoomLevel - this.minZoomLevel + 1; 
    99                 this.numZoomLevels = Math.min(zoomDiff, limitZoomLevels); 
    100             } else { 
    101                 this.numZoomLevels = limitZoomLevels; 
    102             } 
    103         } 
    104  
     146            //calculate based on specified numZoomLevels (on layer or map) 
     147            // this covers cases (1) and (3) 
     148            desiredZoomLevels = this.numZoomLevels; 
     149        } 
     150 
     151        if (desiredZoomLevels != null) { 
     152            //Now that we know what we would *like* the number of zoom levels 
     153            // to be, based on layer or map options, we have to make sure that 
     154            // it does not conflict with the actual limit, as specified by  
     155            // the constants on the layer itself (and calculated into the 
     156            // 'limitZoomLevels' variable).  
     157            this.numZoomLevels = Math.min(desiredZoomLevels, limitZoomLevels); 
     158        } else { 
     159            // case (5) -- neither 'numZoomLevels' not 'maxZoomLevel' was  
     160            // set on either the layer or the map. So we just use the  
     161            // maximum limit as calculated by the layer's constants. 
     162            this.numZoomLevels = limitZoomLevels 
     163        } 
     164 
     165        //now that the 'numZoomLevels' is appropriately, safely set,  
     166        // we go back and re-calculate the 'maxZoomLevel'. 
    105167        this.maxZoomLevel = this.minZoomLevel + this.numZoomLevels - 1; 
    106168