diff --git a/lib/OpenLayers/Layer/HTTPRequest.js b/lib/OpenLayers/Layer/HTTPRequest.js index b6ba775398..6d48a4d29d 100644 --- a/lib/OpenLayers/Layer/HTTPRequest.js +++ b/lib/OpenLayers/Layer/HTTPRequest.js @@ -36,10 +36,17 @@ OpenLayers.Layer.HTTPRequest.prototype = this.params = Object.extend( new Object(), params); }, + /** When the layer is added to the map, once it has taken all the + * relevant properties from the map (in Layer.setMap()), we will + * make the call to initialize the layer's resolutions array. + * + * @param {OpenLayers.Map} map + */ setMap: function(map) { OpenLayers.Layer.prototype.setMap.apply(this, arguments); this.initResolutions(); }, + /** * */ @@ -131,31 +138,55 @@ OpenLayers.Layer.HTTPRequest.prototype = return requestString; }, + /** @private + * + */ initResolutions: function() { - if (this.scales != null) { - this.resolutions = new Array(); - for(var i = 0; i < this.scales.length; i++) - this.resolutions[i] = OpenLayers.Util.getResolutionFromScale(this.scales[i], this.units); - this.maxZoomLevel = this.resolutions.length; - } else if (this.resolutions != null) { + + if ((this.scales != null) || (this.resolutions != null)) { + if (this.scales != null) { + //convert the scales into resolutions. + this.resolutions = new Array(); + for(var i = 0; i < this.scales.length; i++) { + this.resolutions[i] = + OpenLayers.Util.getResolutionFromScale(this.scales[i], + this.units); + } + } this.maxZoomLevel = this.resolutions.length; } else { this.resolutions = new Array(); - if (this.minScale) - this.maxResolution = OpenLayers.Util.getResolutionFromScale(this.minScale, this.units); + + if (this.minScale) { + this.maxResolution = + OpenLayers.Util.getResolutionFromScale(this.minScale, + this.units); + } + var maxRes = this.getMaxResolution(); + if (this.maxScale) { - /* This will cause this.map.getMaxZoomLevel() to be set the next time - * it is called, which means that the next portion here will succeed. */ - var minRes = OpenLayers.Util.getResolutionFromScale(this.maxScale); - this.maxZoomLevel = Math.floor(Math.log(maxRes/minRes) / Math.log(2)); + var minRes = + OpenLayers.Util.getResolutionFromScale(this.maxScale); + this.maxZoomLevel = Math.floor(Math.log(maxRes/minRes) / + Math.log(2)); } - for (var i=this.getMinZoomLevel(); i <= this.getMaxZoomLevel(); i++) { + + //at this point, min and max zoom levels are correctly set, so + // iterate and add them to the resolutions array. + var minZoomLevel = this.getMinZoomLevel() + var maxZoomLevel = this.getMaxZoomLevel() + for (var i = minZoomLevel; i <= maxZoomLevel; i++) { this.resolutions.push(maxRes / Math.pow(2, i)); } } }, + /** + * @returns The currently selected resolution of the map, taken from the + * resolutions array, indexed by current zoom level. + * @type float + */ getResolution: function() { var zoom = this.map.getZoom(); diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 8e7606c086..1e8684642f 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -706,11 +706,6 @@ OpenLayers.Map.prototype = { if (this.baseLayer != null) { maxResolution = this.baseLayer.getMaxResolution(); } - - if (maxResolution == null) { - maxResolution = this.maxResolution; - } - return maxResolution; },