Allow extents to restrict tile ranges requested from the server

The addition of full extent tile ranges also allows us to simplify wrapX
handling for tile layers. By limiting wrapX to true and false as possible
values, we can remove a lot of guessing logic.
This commit is contained in:
Andreas Hocevar
2015-04-28 23:14:08 +02:00
parent 700903ca5c
commit a116878a57
17 changed files with 535 additions and 199 deletions
+17 -10
View File
@@ -32,12 +32,13 @@ ol.tilegrid.WMTS = function(options) {
// FIXME: should the matrixIds become optionnal?
goog.base(this, {
extent: options.extent,
origin: options.origin,
origins: options.origins,
resolutions: options.resolutions,
tileSize: options.tileSize,
tileSizes: options.tileSizes,
widths: options.widths
sizes: options.sizes
});
};
@@ -69,11 +70,13 @@ ol.tilegrid.WMTS.prototype.getMatrixIds = function() {
* Create a tile grid from a WMTS capabilities matrix set.
* @param {Object} matrixSet An object representing a matrixSet in the
* capabilities document.
* @param {ol.Extent=} opt_extent An optional extent to restrict the tile
* ranges the server provides.
* @return {ol.tilegrid.WMTS} WMTS tileGrid instance.
* @api
*/
ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
function(matrixSet) {
function(matrixSet, opt_extent) {
/** @type {!Array.<number>} */
var resolutions = [];
@@ -83,8 +86,8 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
var origins = [];
/** @type {!Array.<ol.Size>} */
var tileSizes = [];
/** @type {!Array.<number>} */
var widths = [];
/** @type {!Array.<ol.Size>} */
var sizes = [];
var supportedCRSPropName = 'SupportedCRS';
var matrixIdsPropName = 'TileMatrix';
@@ -108,26 +111,30 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
goog.array.forEach(matrixSet[matrixIdsPropName],
function(elt, index, array) {
matrixIds.push(elt[identifierPropName]);
var resolution = elt[scaleDenominatorPropName] * 0.28E-3 /
metersPerUnit;
var tileWidth = elt[tileWidthPropName];
var tileHeight = elt[tileHeightPropName];
var matrixHeight = elt['MatrixHeight'];
if (switchOriginXY) {
origins.push([elt[topLeftCornerPropName][1],
elt[topLeftCornerPropName][0]]);
} else {
origins.push(elt[topLeftCornerPropName]);
}
resolutions.push(elt[scaleDenominatorPropName] * 0.28E-3 /
metersPerUnit);
var tileWidth = elt[tileWidthPropName];
var tileHeight = elt[tileHeightPropName];
resolutions.push(resolution);
tileSizes.push(tileWidth == tileHeight ?
tileWidth : [tileWidth, tileHeight]);
widths.push(elt['MatrixWidth']);
// top-left origin, so height is negative
sizes.push([elt['MatrixWidth'], -matrixHeight]);
});
return new ol.tilegrid.WMTS({
extent: opt_extent,
origins: origins,
resolutions: resolutions,
matrixIds: matrixIds,
tileSizes: tileSizes,
widths: widths
sizes: sizes
});
};