Give tile grids a width
This commit is contained in:
@@ -92,6 +92,16 @@ ol.tilegrid.TileGrid = function(options) {
|
||||
(!goog.isDef(this.tileSize_) && !goog.isNull(this.tileSizes_)) ||
|
||||
(goog.isDef(this.tileSize_) && goog.isNull(this.tileSizes_)));
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.widths_ = null;
|
||||
if (goog.isDef(options.widths)) {
|
||||
this.widths_ = options.widths;
|
||||
goog.asserts.assert(this.widths_.length == this.resolutions_.length);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -373,6 +383,25 @@ ol.tilegrid.TileGrid.prototype.getTileCoordResolution = function(tileCoord) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Zoom level.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @param {ol.TileRange=} opt_tileRange Tile range.
|
||||
* @return {ol.TileRange} Tile range.
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.getTileRange =
|
||||
function(z, projection, opt_tileRange) {
|
||||
var projectionExtentTileRange = this.getTileRangeForExtentAndZ(
|
||||
ol.tilegrid.extentFromProjection(projection), z);
|
||||
var width = this.getWidth(z);
|
||||
if (!goog.isDef(width)) {
|
||||
width = projectionExtentTileRange.getWidth();
|
||||
}
|
||||
return ol.TileRange.createOrUpdate(
|
||||
0, width - 1, 0, projectionExtentTileRange.getHeight(), opt_tileRange);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Z.
|
||||
* @return {number} Tile size.
|
||||
@@ -389,6 +418,19 @@ ol.tilegrid.TileGrid.prototype.getTileSize = function(z) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Zoom level.
|
||||
* @return {number|undefined} Width for the specified zoom level or `undefined`
|
||||
* if unknown.
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.getWidth = function(z) {
|
||||
if (!goog.isNull(this.widths_)) {
|
||||
goog.asserts.assert(this.minZoom <= z && z <= this.maxZoom);
|
||||
return this.widths_[z];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {number} Z.
|
||||
@@ -399,6 +441,26 @@ ol.tilegrid.TileGrid.prototype.getZForResolution = function(resolution) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Zoom level.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {boolean} Whether the tile grid is defined for the whole globe when
|
||||
* used with the provided `projection` at zoom level `z`.
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.isGlobal = function(z, projection) {
|
||||
var width = this.getWidth(z);
|
||||
if (goog.isDef(width)) {
|
||||
var projTileGrid = ol.tilegrid.getForProjection(projection);
|
||||
var projExtent = projection.getExtent();
|
||||
return this.getTileSize(z) * width ==
|
||||
projTileGrid.getTileSize(z) *
|
||||
projTileGrid.getTileRangeForExtentAndZ(projExtent, z).getWidth();
|
||||
} else {
|
||||
return projection.isGlobal();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {ol.tilegrid.TileGrid} Default tile grid for the passed projection.
|
||||
@@ -433,10 +495,17 @@ ol.tilegrid.createForExtent =
|
||||
var resolutions = ol.tilegrid.resolutionsFromExtent(
|
||||
extent, opt_maxZoom, tileSize);
|
||||
|
||||
var widths = new Array(resolutions.length);
|
||||
var extentWidth = ol.extent.getWidth(extent);
|
||||
for (var z = resolutions.length - 1; z >= 0; --z) {
|
||||
widths[z] = extentWidth / tileSize / resolutions[z];
|
||||
}
|
||||
|
||||
return new ol.tilegrid.TileGrid({
|
||||
origin: ol.extent.getCorner(extent, corner),
|
||||
resolutions: resolutions,
|
||||
tileSize: tileSize
|
||||
tileSize: tileSize,
|
||||
widths: widths
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ ol.tilegrid.WMTS = function(options) {
|
||||
origins: options.origins,
|
||||
resolutions: options.resolutions,
|
||||
tileSize: options.tileSize,
|
||||
tileSizes: options.tileSizes
|
||||
tileSizes: options.tileSizes,
|
||||
widths: options.widths
|
||||
});
|
||||
|
||||
};
|
||||
@@ -77,6 +78,8 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
|
||||
var origins = [];
|
||||
/** @type {!Array.<number>} */
|
||||
var tileSizes = [];
|
||||
/** @type {!Array.<number>} */
|
||||
var widths = [];
|
||||
|
||||
var supportedCRSPropName = 'SupportedCRS';
|
||||
var matrixIdsPropName = 'TileMatrix';
|
||||
@@ -112,12 +115,14 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
|
||||
var tileHeight = elt[tileHeightPropName];
|
||||
goog.asserts.assert(tileWidth == tileHeight);
|
||||
tileSizes.push(tileWidth);
|
||||
widths.push(elt['MatrixWidth']);
|
||||
});
|
||||
|
||||
return new ol.tilegrid.WMTS({
|
||||
origins: origins,
|
||||
resolutions: resolutions,
|
||||
matrixIds: matrixIds,
|
||||
tileSizes: tileSizes
|
||||
tileSizes: tileSizes,
|
||||
widths: widths
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user