Tile and image services · Angular, React and OpenLayers
Read a WMTS service's capabilities
Parse OGC WMTS GetCapabilities XML in OpenLayers with WMTSCapabilities to inspect available layers, formats, KVP GetTile endpoints and tile matrix sets.

What this example shows
This example parses GUGiK’s OGC WMTS 1.0.0 GetCapabilities XML document into a structured JavaScript object and formats it as indented JSON—exposing the ORTOFOTOMAPA layer, its JPEG format, KVP GetTile operation URLs, and all 54 tile matrices across EPSG:2180, EPSG:4326 and EPSG:3857.
When you need it
Unlike XYZ services that share one implicit pyramid, every OGC WMTS server defines custom matrix identifiers, scale denominators, top-left corners and tile dimensions in XML.
Inspecting parsed WMTS capabilities lets applications list supported coordinate systems dynamically or debug why a handmade grid fails against a national geoportal.
The code
The example uses cc-openlayers, my Angular component library for OpenLayers: each aol-… element creates the OpenLayers object it names, updates it from its inputs and disposes of it with the component.
wmts-capabilities.tsimport { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import WMTSCapabilities from 'ol/format/WMTSCapabilities';
/** The result of parsing a WMTS GetCapabilities response (the national orthophoto service) shown as JSON. */
@Component({
selector: 'app-wmts-capabilities',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `<pre><code>{{ log() }}</code></pre>`,
})
export class WmtsCapabilities {
readonly log = signal('');
constructor() {
const parser = new WMTSCapabilities();
void fetch('assets/wmts-capabilities.xml')
.then((response) => response.text())
.then((text) => this.log.set(JSON.stringify(parser.read(text), null, 2)));
}
} The React version uses the library's React adapter, cc-openlayers/react: each component creates the OpenLayers object it names when it mounts, updates it from its props and disposes of it when it unmounts.
wmts-capabilities.react.tsximport { useEffect, useState } from 'react';
import WMTSCapabilitiesFormat from 'ol/format/WMTSCapabilities.js';
/** The result of parsing a WMTS GetCapabilities response (the national orthophoto service) shown as JSON. */
export function WmtsCapabilities() {
const [log, setLog] = useState('');
useEffect(() => {
let current = true;
const parser = new WMTSCapabilitiesFormat();
void fetch('assets/wmts-capabilities.xml')
.then((response) => response.text())
.then((text) => {
if (current) setLog(JSON.stringify(parser.read(text), null, 2));
});
return () => {
current = false;
};
}, []);
return (
<pre>
<code>{log}</code>
</pre>
);
}How the React version works
A WMTS GetCapabilities document parsed by WMTSCapabilities and shown as JSON. The example has no map.
What both versions share
OpenLayers renders the map and handles the interactions; the cc-openlayers/core layer gives both adapters the same view binding (MapViewBinding) and the same conversion of coordinates from EPSG:4326 to the map's projection.
From Angular to React
| Angular | React |
|---|---|
| a fetch in the constructor | useEffect with a cancel flag |
Who creates, updates and disposes
Map creates the ol/Map in useLayoutEffect and disposes of it on unmount; each layer, source and interaction component adds its object to the parent it gets from context and removes it in its effect's cleanup, as ngOnDestroy does in Angular. Fetching the document lives in a useEffect with a flag that ignores an answer after unmount; under StrictMode the effect runs twice, and the flag drops the first fetch.
Architecture and OpenLayers mechanics
WMTSCapabilities parses the 40 KB OGC XML document into a clean JavaScript tree printed with JSON.stringify. Inside Contents, each TileMatrixSet lists its CRS and per-level ScaleDenominator, TopLeftCorner, TileWidth/TileHeight and MatrixWidth/MatrixHeight—which OpenLayers converts into map-unit resolutions using the standard OGC 0.28 mm pixel size.
When a layer omits RESTful ResourceURL templates, clients automatically fall back to Key-Value Pair (KVP) GetTile query strings advertised in OperationsMetadata.
How it works
WMTSCapabilitiesconverts the OGC WMTS XML capabilities document into a plain JavaScript object displayed viaJSON.stringify.- The parsed tree reveals one ORTOFOTOMAPA JPEG layer offered in three matrix sets: national EPSG:2180 (17 levels, 512 px), EPSG:4326 (17 levels, 512 px) and EPSG:3857 (20 levels, 256 px).
- OpenLayers derives map resolution per matrix from its OGC scale denominator using the standard 0.28 mm pixel convention.
- With no REST template declared on the layer, tile requests use KVP query parameters against the GetTile operation URL.
Pitfalls
- TopLeftCorner coordinates in WMTS XML follow strict CRS axis order—northing before easting in EPSG:2180 and latitude before longitude in EPSG:4326; if you register a custom proj4 CRS such as EPSG:2180 without +axis=neu, OpenLayers will fail to swap axes and request non-existent tiles.
- Even single-layer WMTS capability files weigh tens of kilobytes because every individual zoom matrix is listed—fetch and parse capabilities once per session rather than per component mount.
Related examples
The same feature in the OpenLayers examples .
Background: state and lifecycle of maps in Angular with OpenLayers, which the components of cc-openlayers take care of.