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.

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.tsimport { 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}`);
} 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.react.tsximport { getTopLeft, getWidth } from 'ol/extent.js';
import { EXTENT } from 'ol/proj/epsg3857.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
TileLayer,
View,
WMTSSource,
useWMTSTileGrid,
} from 'cc-openlayers/react';
const extent = EXTENT;
const size = getWidth(extent) / 256;
const origin = getTopLeft(extent);
const resolutions = Array.from({ length: 20 }, (_, z) => size / 2 ** z);
const matrixIds = Array.from({ length: 20 }, (_, z) => `EPSG:3857:${z}`);
const gridOptions = { origin, resolutions, matrixIds };
/** A WMTS source configured by hand (tile grid, matrix ids): the national orthophoto over OpenStreetMap. */
export function Wmts() {
const tileGrid = useWMTSTileGrid(gridOptions);
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={13}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<TileLayer opacity={0.7}>
<WMTSSource
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}
tileGrid={tileGrid}
/>
</TileLayer>
</Map>
);
}How the React version works
GUGiK's orthophoto from a hand-configured WMTS (grid, matrix ids) at 70 % opacity over OpenStreetMap.
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. Both versions compute the WMTS tile grid of GUGiK's orthophoto (origin, 20 resolutions, ids EPSG:3857:z) in the same way; in React the useWMTSTileGrid hook creates it once from module constants.
From Angular to React
| Angular | React |
|---|---|
<aol-source-tilewmts> with <aol-tilegrid-wmts> inside | <WMTSSource tileGrid={tileGrid}> with useWMTSTileGrid(...) |
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.
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-wmtsdefines the 20-level grid fromgetTopLeftof Web MercatorEXTENT,size / 2 ** zresolutions and EPSG:3857:0..EPSG:3857:19 matrix IDs.layer,matrixSet,formatanddefaultstyle 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
matrixIdsare 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.
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.