New behavior for layer.getZoomForResolution. This method now returns the index of the resolution closest to the passed in resolution - making for fewer unwanted resolution changes, and a generally happier populace (see #990).

git-svn-id: http://svn.openlayers.org/trunk/openlayers@4381 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-09-19 00:23:26 +00:00
parent a2fabd7d17
commit 1f745b4be9
8 changed files with 112 additions and 39 deletions

View File

@@ -736,8 +736,7 @@ OpenLayers.Layer = OpenLayers.Class({
* {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 smallest resolution that is greater than this
* ideal resolution.
* and then find the closest resolution to this ideal resolution.
*/
getZoomForExtent: function(extent) {
var viewSize = this.map.getSize();
@@ -761,23 +760,28 @@ OpenLayers.Layer = OpenLayers.Class({
/**
* APIMethod: getZoomForResolution
* Get the index for the closest resolution in the layers resolutions array.
*
* Parameters:
* resolution - {Float}
* resolution - {Float} Map units per pixel.
*
* Returns:
* {Integer} The index of the zoomLevel (entry in the resolutions array)
* that is the smallest resolution that is greater than the passed-in
* resolution.
* that is the closest to the passed-in resolution.
*/
getZoomForResolution: function(resolution) {
for(var i=1; i < this.resolutions.length; i++) {
if ( this.resolutions[i] < resolution) {
var zoom, 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;
minDiff = diff;
} else if(diff > minDiff) {
break;
}
}
return (i - 1);
return zoom;
},
/**