Layer.XYZ: support a subset of server resolutions, p=bbinet, r=me (closes #2909)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10903 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -40,10 +40,19 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
* for a requested tile. For example, if you supply a zoomOffset
|
* 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
|
* 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
|
* 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,
|
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
|
* Constructor: OpenLayers.Layer.XYZ
|
||||||
*
|
*
|
||||||
@@ -114,7 +123,9 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
/ (res * this.tileSize.w));
|
/ (res * this.tileSize.w));
|
||||||
var y = Math.round((this.maxExtent.top - bounds.top)
|
var y = Math.round((this.maxExtent.top - bounds.top)
|
||||||
/ (res * this.tileSize.h));
|
/ (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 url = this.url;
|
||||||
var s = '' + x + y + z;
|
var s = '' + x + y + z;
|
||||||
|
|||||||
@@ -148,6 +148,31 @@
|
|||||||
map.destroy();
|
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) {
|
function test_zoomOffset(t) {
|
||||||
|
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user