function(elt, index, array) { const tileMatrixSet = find(tileMatrixSets, function(el) { return el['Identifier'] == elt['TileMatrixSet']; }); const supportedCRS = tileMatrixSet['SupportedCRS']; const proj1 = getProjection(supportedCRS.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) || getProjection(supportedCRS); const proj2 = getProjection(config['projection']); if (proj1 && proj2) { return equivalent(proj1, proj2); } else { return supportedCRS == config['projection']; } });
export const optionsFromCapabilities = (wmtsCap, config) => { const layers = wmtsCap['Contents']['Layer']; const l = find(layers, function(elt, index, array) { return elt['Identifier'] == config['layer']; }); if (l === null) { return null; } const tileMatrixSets = wmtsCap['Contents']['TileMatrixSet']; let idx; if (l['TileMatrixSetLink'].length > 1) { if ('projection' in config) { idx = findIndex(l['TileMatrixSetLink'], function(elt, index, array) { const tileMatrixSet = find(tileMatrixSets, function(el) { return el['Identifier'] == elt['TileMatrixSet']; }); const supportedCRS = tileMatrixSet['SupportedCRS']; const proj1 = getProjection(supportedCRS.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) || getProjection(supportedCRS); const proj2 = getProjection(config['projection']); if (proj1 && proj2) { return equivalent(proj1, proj2); } else { return supportedCRS == config['projection']; } }); } else { idx = findIndex(l['TileMatrixSetLink'], function(elt, index, array) { return elt['TileMatrixSet'] == config['matrixSet']; }); } } else { idx = 0; } if (idx < 0) { idx = 0; } const matrixSet = /** @type {string} */ (l['TileMatrixSetLink'][idx]['TileMatrixSet']); const matrixLimits = /** @type {Array<Object>} */ (l['TileMatrixSetLink'][idx]['TileMatrixSetLimits']); let format = /** @type {string} */ (l['Format'][0]); if ('format' in config) { format = config['format']; } idx = findIndex(l['Style'], function(elt, index, array) { if ('style' in config) { return elt['Title'] == config['style']; } else { return elt['isDefault']; } }); if (idx < 0) { idx = 0; } const style = /** @type {string} */ (l['Style'][idx]['Identifier']); const dimensions = {}; if ('Dimension' in l) { l['Dimension'].forEach(function(elt, index, array) { const key = elt['Identifier']; let value = elt['Default']; if (value === undefined) { value = elt['Value'][0]; } dimensions[key] = value; }); } const matrixSets = wmtsCap['Contents']['TileMatrixSet']; const matrixSetObj = find(matrixSets, function(elt, index, array) { return elt['Identifier'] == matrixSet; }); let projection; const code = matrixSetObj['SupportedCRS']; if (code) { projection = getProjection(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) || getProjection(code); } if ('projection' in config) { const projConfig = getProjection(config['projection']); if (projConfig) { if (!projection || equivalent(projConfig, projection)) { projection = projConfig; } } } const wgs84BoundingBox = l['WGS84BoundingBox']; let extent, wrapX; // PATCH init ------------------ if (config.extent) { extent = config.extent; } // PATCH end ------------------ else if (wgs84BoundingBox !== undefined) { const wgs84ProjectionExtent = getProjection('EPSG:4326').getExtent(); wrapX = (wgs84BoundingBox[0] == wgs84ProjectionExtent[0] && wgs84BoundingBox[2] == wgs84ProjectionExtent[2]); extent = transformExtent( wgs84BoundingBox, 'EPSG:4326', projection); const projectionExtent = projection.getExtent(); if (projectionExtent) { // If possible, do a sanity check on the extent - it should never be // bigger than the validity extent of the projection of a matrix set. if (!containsExtent(projectionExtent, extent)) { extent = undefined; } } } const tileGrid = createFromCapabilitiesMatrixSet(matrixSetObj, extent, matrixLimits); /** @type {!Array<string>} */ const urls = []; let requestEncoding = config['requestEncoding']; requestEncoding = requestEncoding !== undefined ? requestEncoding : ''; if ('OperationsMetadata' in wmtsCap && 'GetTile' in wmtsCap['OperationsMetadata']) { const gets = wmtsCap['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get']; for (let i = 0, ii = gets.length; i < ii; ++i) { if (gets[i]['Constraint']) { const constraint = find(gets[i]['Constraint'], function(element) { return element['name'] == 'GetEncoding'; }); const encodings = constraint['AllowedValues']['Value']; if (requestEncoding === '') { // requestEncoding not provided, use the first encoding from the list requestEncoding = encodings[0]; } if (requestEncoding === WMTSRequestEncoding.KVP) { if (includes(encodings, WMTSRequestEncoding.KVP)) { urls.push( /** @type {string} */ (gets[i]['href'])); } } else { break; } } else if (gets[i]['href']) { requestEncoding = WMTSRequestEncoding.KVP; urls.push( /** @type {string} */ (gets[i]['href'])); } } } if (urls.length === 0) { requestEncoding = WMTSRequestEncoding.REST; l['ResourceURL'].forEach(function(element) { if (element['resourceType'] === 'tile') { format = element['format']; urls.push( /** @type {string} */ (element['template'])); } }); } return { urls: urls, layer: config['layer'], matrixSet: matrixSet, format: format, projection: projection, requestEncoding: requestEncoding, tileGrid: tileGrid, style: style, dimensions: dimensions, wrapX: wrapX, crossOrigin: config['crossOrigin'] }; }