Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
A GeoTIFF on a turned grid
Render a 20-degree rotated Sentinel-2 GeoTIFF placed by its ModelTransformation tag over OpenStreetMap in OpenLayers with rotated TileDebug.

What this example shows
Over an OpenStreetMap street backdrop of central Kraków—showing the Planty ring, Wawel bend of the Vistula and Błonia meadow—a local Sentinel-2 crop (assets/krakow/rotated-sentinel.tif) stored on an oblique pixel grid rotated by 20 degrees renders in exact geographic alignment at 80% opacity.
Checking the Show tiles box beneath the map overlays a rotated TileDebug wireframe that follows the GeoTIFF’s tilted internal tile grid rather than OpenStreetMap’s north-up grid.
When you need it
Flight-line aerial strips, synthetic-aperture radar (SAR) swaths and unrectified engineering scans frequently orient their pixel rows along a sensor track or building axis, storing an affine rotation matrix inside the GeoTIFF ModelTransformation tag instead of resampling pixels north-up.
Supporting ModelTransformation directly in WebGL places oblique rasters accurately without destructive double-resampling in desktop GIS beforehand.
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.
cog-modeltransformation.tsimport { ChangeDetectionStrategy, Component, DestroyRef, inject, signal, viewChild } from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
SourceTileDebugComponent,
ViewComponent,
} from 'cc-openlayers';
import { LayerWebGLTileComponent } from 'cc-openlayers/webgl';
import { transformExtent } from 'ol/proj';
import GeoTIFF from 'ol/source/GeoTIFF';
/**
* A COG whose grid is turned against its projection: the sample holds Sentinel-2's true-colour image of Kraków's
* centre on a grid turned by 20°, which its ModelTransformation tag places in UTM zone 34N. OpenLayers reprojects it
* to the map, and a debug source given the image's source outlines its tiles, turned with them.
*/
@Component({
selector: 'app-cog-modeltransformation',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerWebGLTileComponent,
MapComponent,
SourceOsmComponent,
SourceTileDebugComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="13">
<aol-coordinate [x]="19.9373" [y]="50.0617" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-webgltile [sources]="[image]" [opacity]="0.8" />
<aol-layer-webgltile [visible]="showTiles()">
<aol-source-tiledebug [source]="image" />
</aol-layer-webgltile>
</aol-map>
<form class="example-controls">
<label>
<input type="checkbox" id="show-tiles" [checked]="showTiles()" (change)="showTiles.set(!showTiles())" />
Show tiles
</label>
</form>
`,
})
export class CogModeltransformation {
readonly showTiles = signal(false);
protected readonly image = new GeoTIFF({
sources: [{ url: 'assets/krakow/rotated-sentinel.tif' }],
attributions: 'Contains modified Copernicus Sentinel data 2024',
});
private readonly map = viewChild.required(MapComponent);
constructor() {
// The file names its projection by code, EPSG:32634: OpenLayers builds the UTM zones itself, without proj4.
let destroyed = false;
inject(DestroyRef).onDestroy(() => (destroyed = true));
void this.image.getView().then(({ extent, projection }) => {
if (destroyed) return;
const view = this.map().instance.getView();
if (extent && projection) view.fit(transformExtent(extent, projection, view.getProjection()));
});
}
} 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.
cog-modeltransformation.react.tsximport { useEffect, useMemo, useState } from 'react';
import type OLView from 'ol/View.js';
import { transformExtent } from 'ol/proj.js';
import GeoTIFF from 'ol/source/GeoTIFF.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
TileDebugSource,
TileLayer,
View,
} from 'cc-openlayers/react';
import { WebGLTileLayer } from 'cc-openlayers/react/webgl';
/**
* A COG whose grid is turned against its projection: the sample holds Sentinel-2's true-colour image of Kraków's
* centre on a grid turned by 20°, which its ModelTransformation tag places in UTM zone 34N. OpenLayers reprojects it
* to the map, and a debug source given the image's source outlines its tiles, turned with them.
*/
export function CogModeltransformation() {
const [showTiles, setShowTiles] = useState(false);
const [view, setView] = useState<OLView | null>(null);
// Memoised so that StrictMode's second render reuses the source (it starts reading its file at creation).
const image = useMemo(
() =>
new GeoTIFF({
sources: [{ url: 'assets/krakow/rotated-sentinel.tif' }],
attributions: 'Contains modified Copernicus Sentinel data 2024',
}),
[]
);
const sources = useMemo(() => [image], [image]);
useEffect(() => {
if (!view) return;
let current = true;
// The file names its projection by code, EPSG:32634: OpenLayers builds the UTM zones itself, without proj4.
void image.getView().then(({ extent, projection }) => {
if (current && extent && projection) view.fit(transformExtent(extent, projection, view.getProjection()));
});
return () => {
current = false;
};
}, [image, view]);
return (
<>
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View ref={setView} zoom={13}>
<Coordinate x={19.9373} y={50.0617} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<WebGLTileLayer sources={sources} opacity={0.8} />
<WebGLTileLayer visible={showTiles}>
<TileDebugSource source={image} />
</WebGLTileLayer>
</Map>
<form className="example-controls">
<label>
<input type="checkbox" id="show-tiles" checked={showTiles} onChange={() => setShowTiles(!showTiles)} />
Show tiles
</label>
</form>
</>
);
}How the React version works
A GeoTIFF placed and turned by its model transformation, drawn at 80 % opacity over OpenStreetMap; "Show tiles" outlines its tiles, turned with them, and the view fits the image once it is read. The source reads the file in the browser, so nothing is drawn before its metadata arrive.
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. OpenLayers draws the tiles with WebGL; the style expressions run on the GPU in both versions.
From Angular to React
| Angular | React |
|---|---|
an ol/source/GeoTIFF field passed as [sources], and <aol-source-tiledebug [source]> in a second layer | the same source made once in useMemo and passed as sources to WebGLTileLayer, and a TileDebugSource in a second layer |
viewChild of the map and fit on its view after getView() | ref={setView} on View into useState and a useEffect that fits it once the source's getView() resolves |
the "Show tiles" checkbox and a signal | useState and visible on the debug layer |
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. The GeoTIFF source is made in useMemo because it starts reading when it is constructed.
Architecture and OpenLayers mechanics
image instantiates new GeoTIFF over assets/krakow/rotated-sentinel.tif (whose GeoKeys declare EPSG:32634 alongside a 20° affine ModelTransformation matrix). In the constructor—guarded by a destroyed flag wired to DestroyRef—image.getView() resolves the scene’s native extent and projection so view.fit(transformExtent(extent, projection, view.getProjection())) frames the tilted footprint on the Web Mercator view.
Two aol-layer-webgltile layers share the same image instance: the first renders the imagery via [sources]="[image]" at [opacity]="0.8", and the second ([visible]="showTiles()") wraps <aol-source-tiledebug [source]="image" /> to outline the rotated source tiles.
How it works
imagecreates anew GeoTIFFforassets/krakow/rotated-sentinel.tif, whoseModelTransformationtag rotates itsEPSG:32634grid by 20°.- Two
aol-layer-webgltilelayers shareimage: one drawing imagery at[opacity]="0.8"over OpenStreetMap, and one drawing<aol-source-tiledebug [source]="image" />. - Checkbox state drives
[visible]="showTiles()"on the debug layer (unchecked initially). - Once
image.getView()resolves,view.fit(transformExtent(extent, projection, view.getProjection()))frames the rotated scene cleanly unless already destroyed viaDestroyRef.
Pitfalls
- OpenLayers resolves standard UTM EPSG codes such as
EPSG:32634natively withoutproj4, whereas custom national CRS codes require registering aproj4definition beforetransformExtentcan project their bounds. - Mounting
aol-source-tiledebugwithout[source]="image"draws north-up Web Mercator XYZ squares instead of the rotated GeoTIFF grid.
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.