From 693eab5cc9cbe4c34ec11be99ba4f77e27190b76 Mon Sep 17 00:00:00 2001 From: euzuro Date: Sat, 26 Aug 2006 10:26:12 +0000 Subject: [PATCH] added getZoomForResolution() to map & layer. partial fix for #204 -- need to make a getZoomForResolution() for OpenLayers.Layer.FixedZoomLevels git-svn-id: http://svn.openlayers.org/trunk/openlayers@1382 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer.js | 15 ++++++++++++++- lib/OpenLayers/Map.js | 27 +++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 38dcaebeae..bd3ee9d0a9 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -375,9 +375,22 @@ OpenLayers.Layer.prototype = { var viewSize = this.map.getSize(); var idealResolution = Math.max( extent.getWidth() / viewSize.w, extent.getHeight() / viewSize.h ); + + return this.getZoomForResolution(idealResolution); + }, + + /** + * @param {float} resolution + * + * @returns The index of the zoomLevel (entry in the resolutions array) + * that is the smallest resolution that is greater than the + * passed-in resolution. + * @type int + */ + getZoomForResolution: function(resolution) { for(var i=1; i <= this.resolutions.length; i++) { - if ( this.resolutions[i] < idealResolution) { + if ( this.resolutions[i] < resolution) { break; } } diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 041f46c1ab..708d1bd0c8 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -781,12 +781,12 @@ OpenLayers.Map.prototype = { /** - * @param {OpenLayers.Bounds} bounds - * - * @returns A suitable zoom level for the specified bounds. - * If no baselayer is set, returns null. - * @type int - */ + * @param {OpenLayers.Bounds} bounds + * + * @returns A suitable zoom level for the specified bounds. + * If no baselayer is set, returns null. + * @type int + */ getZoomForExtent: function (bounds) { zoom = null; if (this.baseLayer != null) { @@ -795,6 +795,21 @@ OpenLayers.Map.prototype = { return zoom; }, + /** + * @param {float} resolution + * + * @returns A suitable zoom level for the specified resolution. + * If no baselayer is set, returns null. + * @type int + */ + getZoomForResolution: function(resolution) { + zoom = null; + if (this.baseLayer != null) { + zoom = this.baseLayer.getZoomForResolution(resolution); + } + return zoom; + }, + /********************************************************/ /* */ /* Zooming Functions */