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)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7948 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2008-09-04 18:35:40 +00:00
parent 19bffb0092
commit d19ec0da99

View File

@@ -90,18 +90,80 @@ OpenLayers.Layer.FixedZoomLevels = OpenLayers.Class({
this.minZoomLevel = this.MIN_ZOOM_LEVEL;
}
//
// At this point, we know what the minimum desired zoom level is, and
// we must calculate the total number of zoom levels.
//
// Because we allow for the setting of either the 'numZoomLevels'
// or the 'maxZoomLevel' properties... on either the layer or the
// map, we have to define some rules to see which we take into
// account first in this calculation.
//
// The following is the precedence list for these properties:
//
// (1) numZoomLevels set on layer
// (2) maxZoomLevel set on layer
// (3) numZoomLevels set on map
// (4) maxZoomLevel set on map*
// (5) none of the above*
//
// *Note that options (4) and (5) are only possible if the user
// _explicitly_ sets the 'numZoomLevels' property on the map to
// null, since it is set by default to 16.
//
//
// Note to future: In 3.0, I think we should remove the default
// value of 16 for map.numZoomLevels. Rather, I think that value
// should be set as a default on the Layer.WMS class. If someone
// creates a 3rd party layer and does not specify any 'minZoomLevel',
// 'maxZoomLevel', or 'numZoomLevels', and has not explicitly
// specified any of those on the map object either.. then I think
// it is fair to say that s/he wants all the zoom levels available.
//
// By making map.numZoomLevels *null* by default, that will be the
// case. As it is, I don't feel comfortable changing that right now
// as it would be a glaring API change and actually would probably
// break many peoples' codes.
//
//the number of zoom levels we'd like to have.
var desiredZoomLevels;
//this is the maximum number of zoom levels the layer will allow,
// given the specified starting minimum zoom level.
var limitZoomLevels = this.MAX_ZOOM_LEVEL - this.minZoomLevel + 1;
if (this.numZoomLevels != null) {
this.numZoomLevels = Math.min(this.numZoomLevels, limitZoomLevels);
if ( ((this.options.numZoomLevels == null) &&
(this.options.maxZoomLevel != null)) // (2)
||
((this.numZoomLevels == null) &&
(this.maxZoomLevel != null)) // (4)
) {
//calculate based on specified maxZoomLevel (on layer or map)
desiredZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1;
} else {
if (this.maxZoomLevel != null) {
var zoomDiff = this.maxZoomLevel - this.minZoomLevel + 1;
this.numZoomLevels = Math.min(zoomDiff, limitZoomLevels);
} else {
this.numZoomLevels = limitZoomLevels;
}
//calculate based on specified numZoomLevels (on layer or map)
// this covers cases (1) and (3)
desiredZoomLevels = this.numZoomLevels;
}
if (desiredZoomLevels != null) {
//Now that we know what we would *like* the number of zoom levels
// to be, based on layer or map options, we have to make sure that
// it does not conflict with the actual limit, as specified by
// the constants on the layer itself (and calculated into the
// 'limitZoomLevels' variable).
this.numZoomLevels = Math.min(desiredZoomLevels, limitZoomLevels);
} else {
// case (5) -- neither 'numZoomLevels' not 'maxZoomLevel' was
// set on either the layer or the map. So we just use the
// maximum limit as calculated by the layer's constants.
this.numZoomLevels = limitZoomLevels
}
//now that the 'numZoomLevels' is appropriately, safely set,
// we go back and re-calculate the 'maxZoomLevel'.
this.maxZoomLevel = this.minZoomLevel + this.numZoomLevels - 1;
if (this.RESOLUTIONS != null) {