Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
A GeoTIFF in its own projection over an orthophoto
Overlay a UTM 34N Sentinel-2 GeoTIFF onto a Web Mercator WMTS orthophotomap in OpenLayers with automatic GeoKeys CRS detection and gamma style.

What this example shows
Across southern Poland at zoom 9, a Sentinel-2 satellite swath stored natively in UTM zone 34N (EPSG:32634)—complete with its slanted orbital edge and transparent nodata: 0 margins—reprojects on the GPU at 70% opacity with gamma: 0.7 colour correction directly atop GUGiK’s EPSG:3857 WMTS orthophotomap.
When you need it
Raw satellite scenes and engineering rasters arrive in regional UTM zones or national grids, yet analysts need to drape them directly over standard Web Mercator basemaps without running server-side gdalwarp jobs.
OpenLayers reads embedded GeoTIFF projection GeoKeys automatically and warps raster tiles on the fly inside WebGL.
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-projection.tsimport { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import type { Coordinate } from 'ol/coordinate';
import { getTopLeft, getWidth } from 'ol/extent';
import { transform } from 'ol/proj';
import { EXTENT } from 'ol/proj/epsg3857';
import type { SourceInfo } from 'ol/source/GeoTIFF';
import type { ViewOptions } from 'ol/View';
import {
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceTileWMTSComponent,
TileGridWMTSComponent,
ViewComponent,
} from 'cc-openlayers';
import { LayerWebGLTileComponent, SourceGeoTIFFComponent } from 'cc-openlayers/webgl';
const size = getWidth(EXTENT) / 256;
/** A Sentinel-2 COG in UTM zone 34N, its projection looked up automatically, drawn over the orthophoto of a Web Mercator map. */
@Component({
selector: 'app-cog-projection',
imports: [
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerWebGLTileComponent,
MapComponent,
SourceGeoTIFFComponent,
SourceTileWMTSComponent,
TileGridWMTSComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="9" [center]="center()" />
<aol-layer-tile>
<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'"
>
<aol-tilegrid-wmts [origin]="origin" [resolutions]="resolutions" [matrixIds]="matrixIds" />
</aol-source-tilewmts>
</aol-layer-tile>
<aol-layer-webgltile [opacity]="0.7" [style]="{ gamma: 0.7 }">
<aol-source-geotiff
attributions="Contains modified Copernicus Sentinel data 2024"
[sources]="sources"
[loadMissingProjection]="true"
(viewReady)="centerOn($event)"
/>
</aol-layer-webgltile>
</aol-map>
`,
})
export class CogProjection {
/** The map's centre in Web Mercator: Kraków until the image tells its own. */
readonly center = signal<Coordinate>(transform([19.9368, 50.0614], 'EPSG:4326', 'EPSG:3857'));
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}`);
protected readonly sources: SourceInfo[] = [
{
url: 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/34/U/DA/2024/8/S2B_34UDA_20240814_0_L2A/TCI.tif',
nodata: 0,
},
];
/** Moves the map to the image's centre, transformed from the image's projection to the map's. */
protected centerOn(view: ViewOptions): void {
if (!view.center || !view.projection) return;
this.center.set(transform(view.center, view.projection, 'EPSG:3857'));
}
} 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-projection.react.tsximport { useState } from 'react';
import type { Coordinate as OLCoordinate } from 'ol/coordinate.js';
import { getTopLeft, getWidth } from 'ol/extent.js';
import { transform } from 'ol/proj.js';
import { EXTENT } from 'ol/proj/epsg3857.js';
import type { SourceInfo } from 'ol/source/GeoTIFF.js';
import type { ViewOptions } from 'ol/View.js';
import {
DefaultControls,
DefaultInteractions,
Map,
TileLayer,
View,
WMTSSource,
useWMTSTileGrid,
} from 'cc-openlayers/react';
import { GeoTIFFSource, WebGLTileLayer } from 'cc-openlayers/react/webgl';
const size = getWidth(EXTENT) / 256;
const GRID = {
origin: getTopLeft(EXTENT),
resolutions: Array.from({ length: 20 }, (_, z) => size / 2 ** z),
matrixIds: Array.from({ length: 20 }, (_, z) => `EPSG:3857:${z}`),
};
const SOURCES: SourceInfo[] = [
{
url: 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/34/U/DA/2024/8/S2B_34UDA_20240814_0_L2A/TCI.tif',
nodata: 0,
},
];
const STYLE = { gamma: 0.7 };
/** A Sentinel-2 COG in UTM zone 34N, its projection looked up automatically, drawn over the orthophoto of a Web Mercator map. */
export function CogProjection() {
/** The map's centre in Web Mercator: Kraków until the image tells its own. */
const [center, setCenter] = useState<OLCoordinate>(() => transform([19.9368, 50.0614], 'EPSG:4326', 'EPSG:3857'));
const tileGrid = useWMTSTileGrid(GRID);
/** Moves the map to the image's centre, transformed from the image's projection to the map's. */
const centerOn = (view: ViewOptions) => {
if (!view.center || !view.projection) return;
setCenter(transform(view.center, view.projection, 'EPSG:3857'));
};
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={9} center={center} />
<TileLayer>
<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"
tileGrid={tileGrid}
/>
</TileLayer>
<WebGLTileLayer opacity={0.7} style={STYLE}>
<GeoTIFFSource
attributions="Contains modified Copernicus Sentinel data 2024"
sources={SOURCES}
loadMissingProjection={true}
onViewReady={centerOn}
/>
</WebGLTileLayer>
</Map>
);
}How the React version works
A Sentinel-2 scene in UTM zone 34N whose projection OpenLayers looks up, drawn translucent with a gamma of 0.7 over the orthophoto of a Web Mercator map; the map moves to the image's centre once the file 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. 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(...) |
<aol-layer-webgltile> with <aol-source-geotiff [sources]> inside | <WebGLTileLayer> with <GeoTIFFSource sources> inside, both from cc-openlayers/react/webgl |
(viewReady) setting the centre signal through transform | onViewReady setting the centre in useState through the same transform |
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-source-geotiff opens TCI.tif (nodata: 0), detects EPSG:32634 from its GeoKeys (supported natively by OpenLayers for all 120 north/south UTM zones, with [loadMissingProjection]="true" available for proj4 lookups on other EPSG codes), and renders at [opacity]="0.7" and [style]="{ gamma: 0.7 }" above aol-source-tilewmts (ORTOFOTOMAPA in EPSG:3857).
When (viewReady)="centerOn($event)" fires, the scene’s UTM centre transforms into EPSG:3857 to position the [zoom]="9" Web Mercator view.
How it works
aol-source-geotiffreadsTCI.tifwithnodata: 0and extracts EPSG:32634 (UTM zone 34N) automatically from embedded GeoKeys.- OpenLayers supports all standard UTM zones natively, while
[loadMissingProjection]="true"resolves other EPSG codes when proj4 is registered. - The WebGL layer applies
[opacity]="0.7"and[style]="{ gamma: 0.7 }"over GUGiK’sORTOFOTOMAPAaol-source-tilewmts(EPSG:3857). (viewReady)="centerOn($event)"reprojects the scene’s UTM midpoint toEPSG:3857for the[zoom]="9"map view.
Pitfalls
- While OpenLayers constructs UTM zones (EPSG:32601–32660 and EPSG:32701–32760) out of the box, national grids (such as Polish EPSG:2180) still require calling register(proj4) before
[loadMissingProjection]="true"can resolve them.
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.