[OpenLayers-Commits] r10903 - in trunk/openlayers:
lib/OpenLayers/Layer tests/Layer
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Wed Nov 17 07:51:22 EST 2010
Author: erilem
Date: 2010-11-17 04:51:22 -0800 (Wed, 17 Nov 2010)
New Revision: 10903
Modified:
trunk/openlayers/lib/OpenLayers/Layer/XYZ.js
trunk/openlayers/tests/Layer/XYZ.html
Log:
Layer.XYZ: support a subset of server resolutions, p=bbinet, r=me (closes #2909)
Modified: trunk/openlayers/lib/OpenLayers/Layer/XYZ.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/XYZ.js 2010-11-17 10:06:07 UTC (rev 10902)
+++ trunk/openlayers/lib/OpenLayers/Layer/XYZ.js 2010-11-17 12:51:22 UTC (rev 10903)
@@ -40,11 +40,20 @@
* for a requested tile. For example, if you supply a zoomOffset
* of 3, when the map is at the zoom 0, tiles will be requested from
* level 3 of your cache. Default is 0 (assumes cache level and map
- * zoom are equivalent).
+ * zoom are equivalent). Using <zoomOffset> is an alternative to
+ * setting <serverResolutions> if you only want to expose a subset
+ * of the server resolutions.
*/
zoomOffset: 0,
/**
+ * APIProperty: serverResolutions
+ * {Array} A list of all resolutions available on the server. Only set this
+ * property if the map resolutions differs from the server.
+ */
+ serverResolutions: null,
+
+ /**
* Constructor: OpenLayers.Layer.XYZ
*
* Parameters:
@@ -114,7 +123,9 @@
/ (res * this.tileSize.w));
var y = Math.round((this.maxExtent.top - bounds.top)
/ (res * this.tileSize.h));
- var z = this.map.getZoom() + this.zoomOffset;
+ var z = this.serverResolutions != null ?
+ OpenLayers.Util.indexOf(this.serverResolutions, res) :
+ this.map.getZoom() + this.zoomOffset;
var url = this.url;
var s = '' + x + y + z;
Modified: trunk/openlayers/tests/Layer/XYZ.html
===================================================================
--- trunk/openlayers/tests/Layer/XYZ.html 2010-11-17 10:06:07 UTC (rev 10902)
+++ trunk/openlayers/tests/Layer/XYZ.html 2010-11-17 12:51:22 UTC (rev 10903)
@@ -148,6 +148,31 @@
map.destroy();
}
+ function test_Layer_XYZ_serverResolutions(t) {
+ t.plan(2);
+
+ var map = new OpenLayers.Map('map', {
+ resolutions: [13,11]
+ });
+
+ var layer = new OpenLayers.Layer.XYZ(name, url, options);
+ map.addLayer(layer);
+ map.setCenter(new OpenLayers.LonLat(0,0), 1);
+
+ var tileurl = layer.getURL(new OpenLayers.Bounds(0,0,0,0));
+ var level = parseInt(tileurl.split('/')[7]);
+ t.eq(map.getZoom(), level, "Tile zoom level is correct without serverResolutions");
+
+ layer.serverResolutions = [14,13,12,11,10];
+ tileurl = layer.getURL(new OpenLayers.Bounds(0,0,0,0));
+ level = parseInt(tileurl.split('/')[7]);
+ var res = map.getResolution();
+ var gotLevel = OpenLayers.Util.indexOf(layer.serverResolutions, res);
+ t.eq(gotLevel, level, "Tile zoom level is correct with serverResolutions");
+
+ map.destroy();
+ }
+
function test_zoomOffset(t) {
t.plan(2);
More information about the Commits
mailing list