From 10d55cb523d624f734dbf2aba11aa9684f3ab718 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 18 Dec 2008 17:03:44 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Layer.js | 4 ++-- tests/Layer.html | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 8ae093513c..ac81a86c59 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -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; } diff --git a/tests/Layer.html b/tests/Layer.html index 7e0fb9a136..f86490be9d 100644 --- a/tests/Layer.html +++ b/tests/Layer.html @@ -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),