Respecting minResolution and maxScale if specified in the layer options. r=ahocevar (closes #1321)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6332 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-02-21 00:03:11 +00:00
parent 697da4900d
commit db8869e50f
2 changed files with 68 additions and 18 deletions

View File

@@ -715,6 +715,7 @@ OpenLayers.Layer = OpenLayers.Class({
}
// determine numZoomLevels if not already set on the layer
// this gives numZoomLevels assuming approximately base 2 scaling
if (confProps.minResolution != null &&
this.options.numZoomLevels == undefined) {
var ratio = confProps.maxResolution / confProps.minResolution;
@@ -727,13 +728,12 @@ OpenLayers.Layer = OpenLayers.Class({
confProps.resolutions = new Array(confProps.numZoomLevels);
var base = 2;
if(typeof confProps.minResolution == "number" &&
this.options.numZoomLevels > 1) {
confProps.numZoomLevels > 1) {
/**
* If numZoomLevels is explicitly set in the layer options,
* respect it. If numZoomLevels is not specified, we use
* exponential scaling with a base of 2. If numZoomLevels
* is specified, we use exponential scaling and determine the
* appropriate base so minResolution is reached.
* If maxResolution and minResolution are set (or related
* scale properties), we calculate the base for exponential
* scaling that starts at maxResolution and ends at
* minResolution in numZoomLevels steps.
*/
base = Math.pow(
(confProps.maxResolution / confProps.minResolution),

View File

@@ -120,21 +120,71 @@
}
function test_Layer_initResolutions(t) {
t.plan(3);
t.plan(12);
var map = new OpenLayers.Map("map");
var options = {
minResolution: 1,
maxResolution: 10,
numZoomLevels: 5
var options, layer;
// three tests for minResolution, maxResolution, and numZoomLevels
options = {
minResolution: 1.5,
maxResolution: 10.5,
numZoomLevels: 5,
map: map
};
var layer = new OpenLayers.Layer("test", options);
layer.map = map;
layer = new OpenLayers.Layer("test", options);
layer.initResolutions();
t.eq(layer.minResolution.toPrecision(9), (1).toPrecision(9),
"layer minResolution preserved");
t.eq(layer.maxResolution.toPrecision(9), (10).toPrecision(9),
"layer maxResolution preserved");
t.eq(layer.numZoomLevels, 5, "layer numZoomLevels preserved");
t.eq(layer.minResolution.toPrecision(6), (1.5).toPrecision(6),
"(with numZoomLevels) layer minResolution preserved");
t.eq(layer.maxResolution.toPrecision(6), (10.5).toPrecision(6),
"(with numZoomLevels) layer maxResolution preserved");
t.eq(layer.numZoomLevels, 5, "(with numZoomLevels) layer numZoomLevels preserved");
// three tests for minResolution, and maxResolution
options = {
minResolution: 1.5,
maxResolution: 10.5,
map: map
};
layer = new OpenLayers.Layer("test", options);
layer.initResolutions();
t.eq(layer.minResolution.toPrecision(6), (1.5).toPrecision(6),
"(without numZoomLevels) layer minResolution preserved");
t.eq(layer.maxResolution.toPrecision(6), (10.5).toPrecision(6),
"(without numZoomLevels) layer maxResolution preserved");
t.eq(layer.numZoomLevels, 3, "(without numZoomLevels) layer numZoomLevels calculated");
// three tests for minScale, maxScale, and numZoomLevels
options = {
minScale: 105,
maxScale: 15,
numZoomLevels: 10,
map: map
};
layer = new OpenLayers.Layer("test", options);
layer.initResolutions();
t.eq(layer.minScale.toPrecision(6), (105).toPrecision(6),
"(with numZoomLevels) layer minScale preserved");
t.eq(layer.maxScale.toPrecision(6), (15).toPrecision(6),
"(with numZoomLevels) layer maxScale preserved");
t.eq(layer.numZoomLevels, 10, "(with numZoomLevels) layer numZoomLevels preserved");
// three tests for minScale, and maxScale
options = {
minScale: 1555,
maxScale: 155,
map: map
};
layer = new OpenLayers.Layer("test", options);
layer.initResolutions();
t.eq(layer.minScale.toPrecision(6), (1555).toPrecision(6),
"(without numZoomLevels) layer minScale preserved");
t.eq(layer.maxScale.toPrecision(6), (155).toPrecision(6),
"(without numZoomLevels) layer maxScale preserved");
t.eq(layer.numZoomLevels, 4, "(without numZoomLevels) layer numZoomLevels calculated");
map.destroy();
}
function test_05_Layer_visibility(t) {