diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index ad79a36d57..4eed13d2d3 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -393,7 +393,7 @@ OpenLayers.Layer.prototype = { */ getZoomForResolution: function(resolution) { - for(var i=1; i <= this.resolutions.length; i++) { + for(var i=1; i < this.resolutions.length; i++) { if ( this.resolutions[i] < resolution) { break; } diff --git a/tests/test_Layer.html b/tests/test_Layer.html index ba22a6a73f..41057d7470 100644 --- a/tests/test_Layer.html +++ b/tests/test_Layer.html @@ -126,6 +126,23 @@ } + function test_06_Layer_getZoomForResolution(t) { + + t.plan(4); + + var layer = new OpenLayers.Layer('Test Layer'); + + //make some dummy resolutions + layer.resolutions = [128, 64, 32, 16, 8, 4, 2]; + + t.eq(layer.getZoomForResolution(200), 0, "zoom all the way out"); + t.eq(layer.getZoomForResolution(25), 2, "zoom in middle"); + t.eq(layer.getZoomForResolution(3), 5, "zoom allmost all the way in"); + t.eq(layer.getZoomForResolution(1), 6, "zoom all the way in"); + + } + + /****** * *