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:
@@ -952,7 +952,7 @@ OpenLayers.Layer = OpenLayers.Class({
|
|||||||
if(this.map.fractionalZoom) {
|
if(this.map.fractionalZoom) {
|
||||||
var low = Math.floor(zoom);
|
var low = Math.floor(zoom);
|
||||||
var high = Math.ceil(zoom);
|
var high = Math.ceil(zoom);
|
||||||
resolution = this.resolutions[high] +
|
resolution = this.resolutions[low] -
|
||||||
((zoom-low) * (this.resolutions[low]-this.resolutions[high]));
|
((zoom-low) * (this.resolutions[low]-this.resolutions[high]));
|
||||||
} else {
|
} else {
|
||||||
resolution = this.resolutions[Math.round(zoom)];
|
resolution = this.resolutions[Math.round(zoom)];
|
||||||
@@ -1000,7 +1000,7 @@ OpenLayers.Layer = OpenLayers.Class({
|
|||||||
}
|
}
|
||||||
var dRes = highRes - lowRes;
|
var dRes = highRes - lowRes;
|
||||||
if(dRes > 0) {
|
if(dRes > 0) {
|
||||||
zoom = lowZoom + ((resolution - lowRes) / dRes);
|
zoom = lowZoom + ((highRes - resolution) / dRes);
|
||||||
} else {
|
} else {
|
||||||
zoom = lowZoom;
|
zoom = lowZoom;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-1
@@ -414,7 +414,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Layer_getResolutionForZoom(t) {
|
function test_Layer_getResolutionForZoom(t) {
|
||||||
t.plan(5);
|
t.plan(8);
|
||||||
var layer = new OpenLayers.Layer("test");
|
var layer = new OpenLayers.Layer("test");
|
||||||
layer.map = {fractionalZoom: false};
|
layer.map = {fractionalZoom: false};
|
||||||
layer.resolutions = ["zero", "one", "two"];
|
layer.resolutions = ["zero", "one", "two"];
|
||||||
@@ -427,6 +427,16 @@
|
|||||||
layer.map.fractionalZoom = true;
|
layer.map.fractionalZoom = true;
|
||||||
t.eq(layer.getResolutionForZoom(1).toPrecision(6), (4).toPrecision(6),
|
t.eq(layer.getResolutionForZoom(1).toPrecision(6), (4).toPrecision(6),
|
||||||
"(fractionalZoom true) returns resolution for integer zoom");
|
"(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),
|
t.eq(layer.getResolutionForZoom(1.5).toPrecision(6), (5).toPrecision(6),
|
||||||
"(fractionalZoom true) returns resolution for float zoom");
|
"(fractionalZoom true) returns resolution for float zoom");
|
||||||
t.eq(layer.getResolutionForZoom(3.5).toPrecision(6), (8).toPrecision(6),
|
t.eq(layer.getResolutionForZoom(3.5).toPrecision(6), (8).toPrecision(6),
|
||||||
|
|||||||
Reference in New Issue
Block a user