Tile and image services · Angular, React and OpenLayers

A WMTS layer configured by hand

Configure an OpenLayers WMTS orthophotomap layer manually with an explicit WMTSTileGrid, string matrixIds, resolutions and 70% opacity.

Kraków's centre at zoom 13 in GUGiK's orthophotomap at 70 % opacity, with OpenStreetMap's streets and names showing through the photo.
A screenshot of the example. Orthophotomap © GUGiK. Map data © OpenStreetMap contributors.

What this example shows

Central Kraków opens at zoom 13 with GUGiK’s national aerial orthophotomap streamed via OGC Web Map Tile Service at 70% opacity over OpenStreetMap—letting street names and one-way arrows shine clearly through crisp aerial rooftops without waiting for an initial XML capabilities fetch.

When you need it

When your application connects to a well-known, stable national or enterprise WMTS endpoint on every startup, downloading and parsing a 40–200 KB GetCapabilities XML file before requesting the very first tile adds avoidable time-to-first-map latency.

Declaring the known tile matrix set parameters directly in code lets OpenLayers request visible aerial tiles on the very first render frame.

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.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { getTopLeft, getWidth } from 'ol/extent';
import { EXTENT } from 'ol/proj/epsg3857';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerTileComponent,
  MapComponent,
  SourceOsmComponent,
  SourceTileWMTSComponent,
  TileGridWMTSComponent,
  ViewComponent,
} from 'cc-openlayers';

const extent = EXTENT;
const size = getWidth(extent) / 256;

/** A WMTS source configured by hand (tile grid, matrix ids): the national orthophoto over OpenStreetMap. */
@Component({
  selector: 'app-wmts',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerTileComponent,
    MapComponent,
    SourceOsmComponent,
    SourceTileWMTSComponent,
    TileGridWMTSComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="13">
        <aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-tile><aol-source-osm /></aol-layer-tile>
      <aol-layer-tile [opacity]="0.7">
        <aol-source-tilewmts
          attributions='Tiles © <a href="https://www.geoportal.gov.pl/" target="_blank">GUGiK</a>'
          url="https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMTS/StandardResolution"
          layer="ORTOFOTOMAPA"
          matrixSet="EPSG:3857"
          format="image/jpeg"
          projection="EPSG:3857"
          [style]="'default'"
          [wrapX]="true"
        >
          <aol-tilegrid-wmts [origin]="origin" [resolutions]="resolutions" [matrixIds]="matrixIds" />
        </aol-source-tilewmts>
      </aol-layer-tile>
    </aol-map>
  `,
})
export class Wmts {
  protected readonly origin = getTopLeft(extent);
  protected readonly resolutions = Array.from({ length: 20 }, (_, z) => size / 2 ** z);
  protected readonly matrixIds = Array.from({ length: 20 }, (_, z) => `EPSG:3857:${z}`);
}

Architecture and OpenLayers mechanics

aol-tilegrid-wmts constructs the exact 20-level Web Mercator pyramid expected by GUGiK’s service: anchoring the top-left origin via getTopLeft of Web Mercator’s EXTENT, computing progressive resolutions (size / 2 ** z), and listing explicit string matrix identifiers (EPSG:3857:0 through EPSG:3857:19).

The WMTS source pairs that grid with layer (ORTOFOTOMAPA), matrixSet (EPSG:3857), JPEG format and default style, while [opacity]="0.7" blends the aerial layer over OpenStreetMap.

How it works

  • aol-tilegrid-wmts defines the 20-level grid from getTopLeft of Web Mercator EXTENT, size / 2 ** z resolutions and EPSG:3857:0..EPSG:3857:19 matrix IDs.
  • layer, matrixSet, format and default style supply the exact parameters required by each OGC GetTile request.
  • [opacity]="0.7" blends the JPEG orthophotomap over OpenStreetMap so street names remain legible.

Pitfalls

  • Hardcoded WMTS matrix definitions can drift silently if an upstream agency renames a matrix set or adds levels—use optionsFromCapabilities (wmts-layer-from-capabilities) when connecting to third-party services whose grid may evolve.
  • WMTS matrixIds are arbitrary server strings rather than bare zoom integers: passing 0..19 instead of EPSG:3857:0..EPSG:3857:19 causes every GetTile request on this server to fail.

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.