adds TileMatrixSetLimits to WMTS format reader

enhance wmtstilegrid to use it when building matrixId and resolution arrays
This commit is contained in:
Thomas Tilak
2016-07-18 17:55:21 +02:00
parent fd3c9f58bf
commit 1f04a0aad9
6 changed files with 725 additions and 18 deletions

View File

@@ -251,6 +251,32 @@ ol.format.WMTSCapabilities.readTileMatrix_ = function(node, objectStack) {
};
/**
* @private
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {Object|undefined} TileMatrixSetLimits Object.
*/
ol.format.WMTSCapabilities.readTileMatrixLimitsList_ = function(node,
objectStack) {
return ol.xml.pushParseAndPop([],
ol.format.WMTSCapabilities.TMS_LIMITS_LIST_PARSERS_, node,
objectStack);
};
/**
* @private
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {Object|undefined} TileMatrixLimits Array.
*/
ol.format.WMTSCapabilities.readTileMatrixLimits_ = function(node, objectStack) {
return ol.xml.pushParseAndPop({},
ol.format.WMTSCapabilities.TMS_LIMITS_PARSERS_, node, objectStack);
};
/**
* @const
* @private
@@ -353,7 +379,40 @@ ol.format.WMTSCapabilities.STYLE_PARSERS_ = ol.xml.makeStructureNS(
ol.format.WMTSCapabilities.TMS_LINKS_PARSERS_ = ol.xml.makeStructureNS(
ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
'TileMatrixSet': ol.xml.makeObjectPropertySetter(
ol.format.XSD.readString)
ol.format.XSD.readString),
'TileMatrixSetLimits': ol.xml.makeObjectPropertySetter(
ol.format.WMTSCapabilities.readTileMatrixLimitsList_)
});
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
ol.format.WMTSCapabilities.TMS_LIMITS_LIST_PARSERS_ = ol.xml.makeStructureNS(
ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
'TileMatrixLimits': ol.xml.makeArrayPusher(
ol.format.WMTSCapabilities.readTileMatrixLimits_)
});
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
ol.format.WMTSCapabilities.TMS_LIMITS_PARSERS_ = ol.xml.makeStructureNS(
ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
'TileMatrix': ol.xml.makeObjectPropertySetter(
ol.format.XSD.readString),
'MinTileRow': ol.xml.makeObjectPropertySetter(
ol.format.XSD.readNonNegativeInteger),
'MaxTileRow': ol.xml.makeObjectPropertySetter(
ol.format.XSD.readNonNegativeInteger),
'MinTileCol': ol.xml.makeObjectPropertySetter(
ol.format.XSD.readNonNegativeInteger),
'MaxTileCol': ol.xml.makeObjectPropertySetter(
ol.format.XSD.readNonNegativeInteger)
});

View File

@@ -309,7 +309,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
ol.DEBUG && console.assert(l['TileMatrixSetLink'].length > 0,
'layer has TileMatrixSetLink');
var tileMatrixSets = wmtsCap['Contents']['TileMatrixSet'];
var idx, matrixSet;
var idx, matrixSet, matrixLimits;
if (l['TileMatrixSetLink'].length > 1) {
if ('projection' in config) {
idx = ol.array.findIndex(l['TileMatrixSetLink'],
@@ -340,6 +340,8 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
}
matrixSet = /** @type {string} */
(l['TileMatrixSetLink'][idx]['TileMatrixSet']);
matrixLimits = /** @type {Array.<Object>} */
(l['TileMatrixSetLink'][idx]['TileMatrixSetLimits']);
ol.DEBUG && console.assert(matrixSet, 'TileMatrixSet must not be null');
@@ -409,7 +411,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
}
var tileGrid = ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(
matrixSetObj, extent);
matrixSetObj, extent, matrixLimits);
/** @type {!Array.<string>} */
var urls = [];

View File

@@ -65,15 +65,19 @@ ol.tilegrid.WMTS.prototype.getMatrixIds = function() {
/**
* Create a tile grid from a WMTS capabilities matrix set.
* Create a tile grid from a WMTS capabilities matrix set and an
* optional TileMatrixSetLimits.
* @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.
* @param {Array.<Object>=} opt_matrixLimits An optional object representing
* the available matrices for tileGrid.
* @return {ol.tilegrid.WMTS} WMTS tileGrid instance.
* @api
*/
ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet = function(matrixSet, opt_extent) {
ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet = function(matrixSet, opt_extent,
opt_matrixLimits) {
/** @type {!Array.<number>} */
var resolutions = [];
@@ -86,6 +90,8 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet = function(matrixSet, opt_exten
/** @type {!Array.<ol.Size>} */
var sizes = [];
var matrixLimits = opt_matrixLimits !== undefined ? opt_matrixLimits : [];
var supportedCRSPropName = 'SupportedCRS';
var matrixIdsPropName = 'TileMatrix';
var identifierPropName = 'Identifier';
@@ -106,21 +112,36 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet = function(matrixSet, opt_exten
});
matrixSet[matrixIdsPropName].forEach(function(elt, index, array) {
matrixIds.push(elt[identifierPropName]);
var resolution = elt[scaleDenominatorPropName] * 0.28E-3 / metersPerUnit;
var tileWidth = elt[tileWidthPropName];
var tileHeight = elt[tileHeightPropName];
if (switchOriginXY) {
origins.push([elt[topLeftCornerPropName][1],
elt[topLeftCornerPropName][0]]);
var matrixAvailable;
// use of matrixLimits to filter TileMatrices from GetCapabilities
// TileMatrixSet from unavailable matrix levels.
if (matrixLimits.length > 0) {
matrixAvailable = ol.array.find(matrixLimits,
function(elt_ml, index_ml, array_ml) {
return elt[identifierPropName] == elt_ml[matrixIdsPropName];
});
} else {
origins.push(elt[topLeftCornerPropName]);
matrixAvailable = true;
}
if (matrixAvailable) {
matrixIds.push(elt[identifierPropName]);
var resolution = elt[scaleDenominatorPropName] * 0.28E-3 / metersPerUnit;
var tileWidth = elt[tileWidthPropName];
var tileHeight = elt[tileHeightPropName];
if (switchOriginXY) {
origins.push([elt[topLeftCornerPropName][1],
elt[topLeftCornerPropName][0]]);
} else {
origins.push(elt[topLeftCornerPropName]);
}
resolutions.push(resolution);
tileSizes.push(tileWidth == tileHeight ?
tileWidth : [tileWidth, tileHeight]);
// top-left origin, so height is negative
sizes.push([elt['MatrixWidth'], -elt['MatrixHeight']]);
}
resolutions.push(resolution);
tileSizes.push(tileWidth == tileHeight ?
tileWidth : [tileWidth, tileHeight]);
// top-left origin, so height is negative
sizes.push([elt['MatrixWidth'], -elt['MatrixHeight']]);
});
return new ol.tilegrid.WMTS({