Changing/fixing the meaning of getServerZoom.

If a layer is configured with serverResolutions, then getServerZoom should return the zoom level as index of the current resolution in the serverResolutions array.
This commit is contained in:
ahocevar
2012-04-26 10:55:03 -04:00
committed by Tim Schaub
parent a57c56ed96
commit 9585341d9c
5 changed files with 9 additions and 14 deletions

View File

@@ -658,7 +658,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
* {Number} The closest server supported zoom.
*/
getServerZoom: function() {
return this.map.getZoomForResolution(this.getServerResolution());
var serverResolution = this.getServerResolution();
return this.serverResolutions ?
this.serverResolutions.indexOf(serverResolution) :
this.map.getZoomForResolution(serverResolution);
},
/**

View File

@@ -173,9 +173,7 @@ OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
var res = this.getServerResolution();
var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
var z = this.serverResolutions != null ?
OpenLayers.Util.indexOf(this.serverResolutions, res) :
this.getServerZoom() + this.zoomOffset;
var z = this.getServerZoom() + (this.zoomOffset || 0);
var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
var url = this.url;
if (OpenLayers.Util.isArray(url)) {

View File

@@ -332,10 +332,7 @@ OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, {
* Get the current index in the matrixIds array.
*/
getIdentifier: function() {
return this.serverResolutions != null ?
OpenLayers.Util.indexOf(this.serverResolutions,
this.getServerResolution()) :
this.getServerZoom() + this.zoomOffset;
return this.getServerZoom() + (this.zoomOffset || 0);
},
/**

View File

@@ -143,10 +143,7 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
(res * this.tileSize.w));
var y = Math.round((this.maxExtent.top - bounds.top) /
(res * this.tileSize.h));
var resolutions = this.serverResolutions || this.resolutions;
var z = this.zoomOffset == 0 ?
OpenLayers.Util.indexOf(resolutions, res) :
this.getServerZoom() + this.zoomOffset;
var z = this.getServerZoom() + (this.zoomOffset || 0);
if (this.wrapDateLine) {
var limit = Math.pow(2, z);

View File

@@ -837,12 +837,12 @@
layer.serverResolutions = [2, 1];
resolution = 1;
zoom = layer.getServerZoom();
t.eq(zoom, 3, '[3] getServerZoom return value is correct');
t.eq(zoom, 1, '[3] getServerZoom return value is correct');
layer.serverResolutions = [2];
resolution = 0.5;
zoom = layer.getServerZoom();
t.eq(zoom, 2, '[4] getServerZoom return value is correct');
t.eq(zoom, 0, '[4] getServerZoom return value is correct');
var exc;
layer.serverResolutions = [0.5];