Skip to content

Commit

Permalink
Merge pull request #81 from vprint/wmts_crs_fix
Browse files Browse the repository at this point in the history
Fix wrong crs for wmts layer
  • Loading branch information
jahow authored Nov 5, 2024
2 parents 3e2d3cc + 6d02992 commit d21fe18
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/wmts/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ describe('WMTS Capabilities', () => {
matrixSets: [
{
identifier: 'BigWorldPixel',
crs: 'urn:ogc:def:crs:EPSG:6.18:3:3857',
crs: 'urn:ogc:def:crs:OGC:1.3:CRS84',
limits: [],
},
{
Expand Down Expand Up @@ -681,7 +681,7 @@ describe('WMTS Capabilities', () => {
},
{
identifier: 'GoogleMapsCompatible',
crs: 'urn:ogc:def:crs:EPSG::3857',
crs: 'urn:ogc:def:crs:EPSG:6.18.3:3857',
limits: [],
},
],
Expand Down
32 changes: 28 additions & 4 deletions src/wmts/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,37 @@ export function readLayersFromCapabilities(
): WmtsLayer[] {
const rootEl = getRootElement(capabilitiesDoc);
const contentsEl = findChildElement(rootEl, 'Contents');

/**
* Get the TileMatrixSet CRS
* @param contentsEl - Contents
* @param identifier - TileMatrixSet identifier
* @returns The SupportedCRS of the TileMatrixSet
*/
function getMatrixSetCrs(contentsEl: XmlElement, identifier: string): string {
const matrixSet = findChildrenElement(contentsEl, 'TileMatrixSet').find(
(matrixSetEl) => {
const identifierEl = findChildElement(matrixSetEl, 'Identifier');
return getElementText(identifierEl) === identifier;
}
);
return getElementText(findChildElement(matrixSet, 'SupportedCRS'));
}

/**
* Get the parameters of the TileMatrixSetLink
* @param element - TileMatrixSetLink
* @returns
*/
function parseMatrixSetLink(element: XmlElement): MatrixSetLink {
const fullMatrixSet = findChildrenElement(contentsEl, 'TileMatrixSet').find(
(el) => getElementText(findChildElement(el, 'Identifier'))
const identifier = getElementText(
findChildElement(element, 'TileMatrixSet')
);
const crs = getMatrixSetCrs(contentsEl, identifier);

return {
identifier: getElementText(findChildElement(element, 'TileMatrixSet')),
crs: getElementText(findChildElement(fullMatrixSet, 'SupportedCRS')),
identifier,
crs,
limits: findChildrenElement(element, 'TileMatrixLimits', true).map(
(element) => ({
tileMatrix: getElementText(findChildElement(element, 'TileMatrix')),
Expand Down

0 comments on commit d21fe18

Please sign in to comment.