diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 05747f2cbf..9ccc9c9f3a 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -884,16 +884,6 @@ OpenLayers.Layer = OpenLayers.Class({ props.resolutions = this.resolutionsFromScales(props.scales); } if(props.resolutions == null) { - var maxExtent = this.maxExtent; - if (!props.maxResolution && maxExtent) { - // maxResolution for default grid sets assumes that at zoom - // level zero, the whole world fits on one tile. - var tileSize = this.tileSize || this.map.getTileSize(); - props.maxResolution = Math.max( - maxExtent.getWidth() / tileSize.w, - maxExtent.getHeight() / tileSize.h - ); - } props.resolutions = this.calculateResolutions(props); } } @@ -1029,6 +1019,18 @@ OpenLayers.Layer = OpenLayers.Class({ minResolution = Math.max(wRes, hRes); } + if(typeof maxResolution !== "number" && + typeof minResolution !== "number" && + this.maxExtent != null) { + // maxResolution for default grid sets assumes that at zoom + // level zero, the whole world fits on one tile. + var tileSize = this.tileSize || this.map.getTileSize(); + maxResolution = Math.max( + this.maxExtent.getWidth() / tileSize.w, + this.maxExtent.getHeight() / tileSize.h + ); + } + // determine numZoomLevels var maxZoomLevel = props.maxZoomLevel; var numZoomLevels = props.numZoomLevels; diff --git a/tests/Layer.html b/tests/Layer.html index eb2c9270f7..1391ac9396 100644 --- a/tests/Layer.html +++ b/tests/Layer.html @@ -398,6 +398,9 @@ "1.20", null, {maxScale: 100000, numZoomLevels: 3, units: "m"}, [141.11103491115225, 70.55551745557612, 35.27775872778806], 35.27775872778806, 141.11103491115225 ], [ + "1.21", null, {numZoomLevels: 2}, // maxResolution calculated based on the projection's maxExtent here + [1.40625, 0.703125], 0.703125, 1.40625 + ], [ /* * Batch 2: custom map options map and sensible layer options @@ -541,8 +544,8 @@ /* * Batch 2.8: numZoomLevels set in the layer options */ - "2.8.0", {maxResolution: 80}, {numZoomLevels: 4}, - [80, 40, 20, 10], 10, 80 + "2.8.0", {maxResolution: 80}, {numZoomLevels: 4}, // maxResolution calculated based on the projection's maxExtent here + [1.40625, 0.703125, 0.3515625, 0.17578125], 0.17578125, 1.40625 ], [ "2.8.1", {maxResolution: 80, numZoomLevels: 4}, {numZoomLevels: null}, [80, 40, 20, 10], 10, 80