From 9585341d9c39b8971cb6d6279a7b1f8f241056b2 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 26 Apr 2012 10:55:03 -0400 Subject: [PATCH 1/3] 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. --- lib/OpenLayers/Layer/Grid.js | 5 ++++- lib/OpenLayers/Layer/TMS.js | 4 +--- lib/OpenLayers/Layer/WMTS.js | 5 +---- lib/OpenLayers/Layer/XYZ.js | 5 +---- tests/Layer/Grid.html | 4 ++-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 5c3c46d4e3..9c3f70c0d4 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -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); }, /** diff --git a/lib/OpenLayers/Layer/TMS.js b/lib/OpenLayers/Layer/TMS.js index 74a7f0dfac..c4024edde3 100644 --- a/lib/OpenLayers/Layer/TMS.js +++ b/lib/OpenLayers/Layer/TMS.js @@ -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)) { diff --git a/lib/OpenLayers/Layer/WMTS.js b/lib/OpenLayers/Layer/WMTS.js index f7f1dd040a..168ef5a89e 100644 --- a/lib/OpenLayers/Layer/WMTS.js +++ b/lib/OpenLayers/Layer/WMTS.js @@ -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); }, /** diff --git a/lib/OpenLayers/Layer/XYZ.js b/lib/OpenLayers/Layer/XYZ.js index ef5a1950d9..dd1cc3c76f 100644 --- a/lib/OpenLayers/Layer/XYZ.js +++ b/lib/OpenLayers/Layer/XYZ.js @@ -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); diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 43791a67cb..bb632d1ea5 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -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]; From 40b4cc49e0dd820c07d1e68aead3a1d54ab8c589 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 26 Apr 2012 11:47:40 -0400 Subject: [PATCH 2/3] Using OpenLayers.Util.indexOf. Thanks @jorix for catching this. --- lib/OpenLayers/Layer/Grid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 9c3f70c0d4..f5837b15fc 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -660,7 +660,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { getServerZoom: function() { var serverResolution = this.getServerResolution(); return this.serverResolutions ? - this.serverResolutions.indexOf(serverResolution) : + OpenLayers.Util.indexOf(this.serverResolutions, serverResolution) : this.map.getZoomForResolution(serverResolution); }, From 72d1b54956ec2e04ada213318a1f6578c49204a2 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 27 Apr 2012 09:25:52 -0400 Subject: [PATCH 3/3] Also taking into account zoomOffset. Now the meaning of getServerZoom is fully clarified, and we can get rid of some code again as well. --- lib/OpenLayers/Layer/Grid.js | 13 +++++++------ lib/OpenLayers/Layer/TMS.js | 2 +- lib/OpenLayers/Layer/WMTS.js | 2 +- lib/OpenLayers/Layer/XYZ.js | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index f5837b15fc..ab83779334 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -651,17 +651,18 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { /** * Method: getServerZoom - * Return the zoom value corresponding to the best zoom supported by the server - * resolution. + * Return the zoom value corresponding to the best matching server + * resolution, taking into account and . * * Returns: - * {Number} The closest server supported zoom. + * {Number} The closest server supported zoom. This is not the map zoom + * level, but an index of the server's resolutions array. */ getServerZoom: function() { - var serverResolution = this.getServerResolution(); + var resolution = this.getServerResolution(); return this.serverResolutions ? - OpenLayers.Util.indexOf(this.serverResolutions, serverResolution) : - this.map.getZoomForResolution(serverResolution); + OpenLayers.Util.indexOf(this.serverResolutions, resolution) : + this.map.getZoomForResolution(resolution) + (this.zoomOffset || 0); }, /** diff --git a/lib/OpenLayers/Layer/TMS.js b/lib/OpenLayers/Layer/TMS.js index c4024edde3..da879b1de4 100644 --- a/lib/OpenLayers/Layer/TMS.js +++ b/lib/OpenLayers/Layer/TMS.js @@ -173,7 +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.getServerZoom() + (this.zoomOffset || 0); + var z = this.getServerZoom(); var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; var url = this.url; if (OpenLayers.Util.isArray(url)) { diff --git a/lib/OpenLayers/Layer/WMTS.js b/lib/OpenLayers/Layer/WMTS.js index 168ef5a89e..bf4cc5a38f 100644 --- a/lib/OpenLayers/Layer/WMTS.js +++ b/lib/OpenLayers/Layer/WMTS.js @@ -332,7 +332,7 @@ OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, { * Get the current index in the matrixIds array. */ getIdentifier: function() { - return this.getServerZoom() + (this.zoomOffset || 0); + return this.getServerZoom(); }, /** diff --git a/lib/OpenLayers/Layer/XYZ.js b/lib/OpenLayers/Layer/XYZ.js index dd1cc3c76f..504f093f62 100644 --- a/lib/OpenLayers/Layer/XYZ.js +++ b/lib/OpenLayers/Layer/XYZ.js @@ -143,7 +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 z = this.getServerZoom() + (this.zoomOffset || 0); + var z = this.getServerZoom(); if (this.wrapDateLine) { var limit = Math.pow(2, z);