Pullup fix for zooms to branch. (Closes #1043) 4791:4792

git-svn-id: http://svn.openlayers.org/branches/openlayers/2.5@4795 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-10-03 20:42:35 +00:00
parent 6ecd34eaf0
commit c505d23c7b
9 changed files with 85 additions and 121 deletions

View File

@@ -731,19 +731,24 @@ OpenLayers.Layer = OpenLayers.Class({
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* closest - {Boolean} Find the zoom level that most closely fits the
* specified bounds. Note that this may result in a zoom that does
* not exactly contain the entire extent.
* Default is false.
*
* Returns:
* {Integer} The index of the zoomLevel (entry in the resolutions array)
* that still contains the passed-in extent. We do this by calculating
* the ideal resolution for the given exteng (based on the map size)
* and then find the closest resolution to this ideal resolution.
* for the passed-in extent. We do this by calculating the ideal
* resolution for the given extent (based on the map size) and then
* calling getZoomForResolution(), passing along the 'closest'
* parameter.
*/
getZoomForExtent: function(extent) {
getZoomForExtent: function(extent, closest) {
var viewSize = this.map.getSize();
var idealResolution = Math.max( extent.getWidth() / viewSize.w,
extent.getHeight() / viewSize.h );
return this.getZoomForResolution(idealResolution);
return this.getZoomForResolution(idealResolution, closest);
},
/**
@@ -760,28 +765,39 @@ OpenLayers.Layer = OpenLayers.Class({
/**
* APIMethod: getZoomForResolution
* Get the index for the closest resolution in the layers resolutions array.
*
* Parameters:
* resolution - {Float} Map units per pixel.
* resolution - {Float}
* closest - {Boolean} Find the zoom level that corresponds to the absolute
* closest resolution, which may result in a zoom whose corresponding
* resolution is actually smaller than we would have desired (if this
* is being called from a getZoomForExtent() call, then this means that
* the returned zoom index might not actually contain the entire
* extent specified... but it'll be close).
* Default is false.
*
* Returns:
* {Integer} The index of the zoomLevel (entry in the resolutions array)
* that is the closest to the passed-in resolution.
* that corresponds to the best fit resolution given the passed in
* value and the 'closest' specification.
*/
getZoomForResolution: function(resolution) {
var zoom, diff;
getZoomForResolution: function(resolution, closest) {
var diff;
var minDiff = Number.POSITIVE_INFINITY;
for(var i=0; i < this.resolutions.length; i++) {
diff = Math.abs(this.resolutions[i] - resolution);
if(diff < minDiff) {
zoom = i;
for(var i=0; i < this.resolutions.length; i++) {
if (closest) {
diff = Math.abs(this.resolutions[i] - resolution);
if (diff > minDiff) {
break;
}
minDiff = diff;
} else if(diff > minDiff) {
break;
} else {
if (this.resolutions[i] < resolution) {
break;
}
}
}
return zoom;
return Math.max(0, i-1);
},
/**