Use validity extent to generate default resolutions

Previously, the TiledWMS source generated a resolutions array
derived from the world extent in meters, to match the default
Web Mercator resolutions of the map. This wouldn't work for
projections with distance units different than meters. It is
better to commit to a default resolutions array where zoom level
0 is the validity extent of the projection (not the Web Mercator
world extent!) at a 256 pixel tile size.
This commit is contained in:
ahocevar
2013-01-14 16:10:55 +01:00
parent 57b25693af
commit 87ce763ccb
4 changed files with 37 additions and 19 deletions

View File

@@ -316,3 +316,26 @@ ol.tilegrid.TileGrid.prototype.getTileSize = function() {
ol.tilegrid.TileGrid.prototype.getZForResolution = function(resolution) {
return ol.array.linearFindNearest(this.resolutions_, resolution);
};
/**
* @param {ol.Projection} projection Projection.
* @param {number=} opt_maxZoom Maximum zoom level (optional). Default is 18.
* @return {ol.tilegrid.TileGrid} TileGrid instance.
*/
ol.tilegrid.createForProjection = function(projection, opt_maxZoom) {
var projectionExtent = projection.getExtent();
var size = Math.max(
projectionExtent.maxX - projectionExtent.minX,
projectionExtent.maxY - projectionExtent.minY);
var maxZoom = goog.isDef(opt_maxZoom) ?
opt_maxZoom : 18;
var resolutions = new Array(maxZoom + 1);
for (var z = 0, zz = resolutions.length; z < zz; ++z) {
resolutions[z] = size / (256 << z);
}
return new ol.tilegrid.TileGrid({
origin: projectionExtent.getTopLeft(),
resolutions: resolutions
});
};