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.

The start of the parsed capabilities of GUGiK's orthophotomap WMTS as JSON: the service's Polish title and abstract, its type OGC WMTS 1.0.0 and its provider.
A screenshot of the example. Capabilities: GUGiK's orthophotomap WMTS.

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.ts
import { 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)));
  }
}

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

  • WMTSCapabilities converts the OGC WMTS XML capabilities document into a plain JavaScript object displayed via JSON.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.

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.