diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index de33a663ce..5b459c726e 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -82,7 +82,19 @@ OpenLayers.Layer = OpenLayers.Class({ */ EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged", "move", "moveend"], - + + /** + * Constant: RESOLUTION_PROPERTIES + * {Array} The properties that are used for calculating resolutions + * information. + */ + RESOLUTION_PROPERTIES: [ + 'scales', 'resolutions', + 'maxScale', 'minScale', + 'maxResolution', 'minResolution', + 'numZoomLevels', 'maxZoomLevel' + ], + /** * APIProperty: events * {} @@ -529,6 +541,7 @@ OpenLayers.Layer = OpenLayers.Class({ // grab some essential layer data from the map if it hasn't already // been set this.maxExtent = this.maxExtent || this.map.maxExtent; + this.minExtent = this.minExtent || this.map.minExtent; this.projection = this.projection || this.map.projection; if (this.projection && typeof this.projection == "string") { @@ -734,184 +747,242 @@ OpenLayers.Layer = OpenLayers.Class({ */ initResolutions: function() { - // These are the relevant options which are used for calculating - // resolutions information. + // ok we want resolutions, here's our strategy: // - var props = new Array( - 'projection', 'units', - 'scales', 'resolutions', - 'maxScale', 'minScale', - 'maxResolution', 'minResolution', - 'minExtent', 'maxExtent', - 'numZoomLevels', 'maxZoomLevel' - ); + // 1. if resolutions are defined in the layer config, use them + // 2. else, if scales are defined in the layer config then derive + // resolutions from these scales + // 3. else, attempt to calculate resolutions from maxResolution, + // minResolution, numZoomLevels, maxZoomLevel set in the + // layer config + // 4. if we still don't have resolutions, and if resolutions + // are defined in the same, use them + // 5. else, if scales are defined in the map then derive + // resolutions from these scales + // 6. else, attempt to calculate resolutions from maxResolution, + // minResolution, numZoomLevels, maxZoomLevel set in the + // map + // 7. hope for the best! - //these are the properties which do *not* imply that user wishes - // this layer to be scale-dependant - var notScaleProps = ['projection', 'units']; + var i, len; + var props = {}, alwaysInRange = true; - //should the layer be scale-dependant? default is false -- this will - // only be set true if we find that the user has specified a property - // from the 'props' array that is not in 'notScaleProps' - var useInRange = false; - - // First we create a new object where we will store all of the - // resolution-related properties that we find in either the layer's - // 'options' array or from the map. - // - var confProps = {}; - for(var i=0, len=props.length; i 1) { - /** - * If maxResolution and minResolution are set (or related - * scale properties), we calculate the base for exponential - * scaling that starts at maxResolution and ends at - * minResolution in numZoomLevels steps. - */ - base = Math.pow( - (confProps.maxResolution / confProps.minResolution), - (1 / (confProps.numZoomLevels - 1)) - ); - } - for (var i=0; i < confProps.numZoomLevels; i++) { - var res = confProps.maxResolution / Math.pow(base, i); - confProps.resolutions[i] = res; + for(i=0; i