Add ability to get wmts source from capabilities

Added functionality to create a wmts tilegrid and wmts source from the
capabilities object created from ol.format.WMTSCapabilities.read().
Added tests for these functions and an example.

Also altered the REST url template replacement to be case insensitive
and added tests for this. This is because the spec uses both style
and Style and both of these are used by existing WMTS services.
This commit is contained in:
Sara Metz
2015-01-16 09:25:27 +13:00
parent f117cddb34
commit 6894bc8444
9 changed files with 776 additions and 2300 deletions
+19 -9
View File
@@ -64,6 +64,7 @@ ol.tilegrid.WMTS.prototype.getMatrixIds = function() {
* @param {Object} matrixSet An object representing a matrixSet in the
* capabilities document.
* @return {ol.tilegrid.WMTS} WMTS tileGrid instance.
* @api
*/
ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
function(matrixSet) {
@@ -77,16 +78,20 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
/** @type {!Array.<number>} */
var tileSizes = [];
var supportedCRSPropName = 'supportedCRS';
var matrixIdsPropName = 'matrixIds';
var identifierPropName = 'identifier';
var scaleDenominatorPropName = 'scaleDenominator';
var topLeftCornerPropName = 'topLeftCorner';
var tileWidthPropName = 'tileWidth';
var tileHeightPropName = 'tileHeight';
var supportedCRSPropName = 'SupportedCRS';
var matrixIdsPropName = 'TileMatrix';
var identifierPropName = 'Identifier';
var scaleDenominatorPropName = 'ScaleDenominator';
var topLeftCornerPropName = 'TopLeftCorner';
var tileWidthPropName = 'TileWidth';
var tileHeightPropName = 'TileHeight';
var projection = ol.proj.get(matrixSet[supportedCRSPropName]);
var projection;
projection = ol.proj.get(matrixSet[supportedCRSPropName].replace(
/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3'));
var metersPerUnit = projection.getMetersPerUnit();
// swap origin x and y coordinates if axis orientation is lat/long
var switchOriginXY = projection.getAxisOrientation().substr(0, 2) == 'ne';
goog.array.sort(matrixSet[matrixIdsPropName], function(a, b) {
return b[scaleDenominatorPropName] - a[scaleDenominatorPropName];
@@ -95,7 +100,12 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
goog.array.forEach(matrixSet[matrixIdsPropName],
function(elt, index, array) {
matrixIds.push(elt[identifierPropName]);
origins.push(elt[topLeftCornerPropName]);
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];