Correcting getResolutionForZoom and getZoomForResolution in the fractional zoom case. Thanks Bart for catching the backwards logic, for the careful debugging, and for the great patch with tests. r=me (closes #1863)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@8516 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-12-18 17:03:44 +00:00
parent f4e616342c
commit 10d55cb523
2 changed files with 13 additions and 3 deletions

View File

@@ -952,7 +952,7 @@ OpenLayers.Layer = OpenLayers.Class({
if(this.map.fractionalZoom) {
var low = Math.floor(zoom);
var high = Math.ceil(zoom);
resolution = this.resolutions[high] +
resolution = this.resolutions[low] -
((zoom-low) * (this.resolutions[low]-this.resolutions[high]));
} else {
resolution = this.resolutions[Math.round(zoom)];
@@ -1000,7 +1000,7 @@ OpenLayers.Layer = OpenLayers.Class({
}
var dRes = highRes - lowRes;
if(dRes > 0) {
zoom = lowZoom + ((resolution - lowRes) / dRes);
zoom = lowZoom + ((highRes - resolution) / dRes);
} else {
zoom = lowZoom;
}

View File

@@ -414,7 +414,7 @@
}
function test_Layer_getResolutionForZoom(t) {
t.plan(5);
t.plan(8);
var layer = new OpenLayers.Layer("test");
layer.map = {fractionalZoom: false};
layer.resolutions = ["zero", "one", "two"];
@@ -427,6 +427,16 @@
layer.map.fractionalZoom = true;
t.eq(layer.getResolutionForZoom(1).toPrecision(6), (4).toPrecision(6),
"(fractionalZoom true) returns resolution for integer zoom");
t.eq(layer.getResolutionForZoom(1.3).toPrecision(6), (4.6).toPrecision(6),
"(fractionalZoom true) for zoom 1.3 should be 4.6");
t.eq(layer.getResolutionForZoom(1.6).toPrecision(6), (5.2).toPrecision(6),
"(fractionalZoom true) for zoom 1.6 should be 5.2");
t.eq(layer.getResolutionForZoom(1.8).toPrecision(6), (5.6).toPrecision(6),
"(fractionalZoom true) for zoom 1.8 should be 5.6");
t.eq(layer.getResolutionForZoom(1.5).toPrecision(6), (5).toPrecision(6),
"(fractionalZoom true) returns resolution for float zoom");
t.eq(layer.getResolutionForZoom(3.5).toPrecision(6), (8).toPrecision(6),