Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
A GeoTIFF reprojected to Web Mercator
Reproject a UTM zone 34N Sentinel-2 Cloud Optimized GeoTIFF onto a Web Mercator OpenLayers map in WebGL and recenter on viewReady metadata.

What this example shows
A standalone Copernicus Sentinel-2 true-colour scene (TCI.tif from 14 August 2024) covering Kraków, the Niepołomice Forest and the Carpathian foothills streams from cloud object storage and renders reprojected onto a standard Web Mercator (EPSG:3857) map at zoom 9 with its slanted UTM swath edge clearly visible.
The camera opens initially on central Kraków coordinates and shifts smoothly to the exact centre of the satellite scene as soon as the GeoTIFF header finishes parsing.
When you need it
Earth-observation scenes are archived in local UTM zones (such as EPSG:32634 for southern Poland), whereas web maps usually keep their View in EPSG:3857 so standard XYZ tiles, vector layers and URL coordinates work unchanged.
Letting WebGLTileLayer warp UTM raster tiles into Web Mercator on the GPU eliminates server-side gdalwarp preprocessing while keeping the application’s primary coordinate system consistent.
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.
geotiff-reprojection.tsimport { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { DefaultControlComponent, DefaultInteractionComponent, MapComponent, ViewComponent } from 'cc-openlayers';
import { LayerWebGLTileComponent, SourceGeoTIFFComponent } from 'cc-openlayers/webgl';
import type { Coordinate } from 'ol/coordinate';
import { transform } from 'ol/proj';
import type { ViewOptions } from 'ol/View';
import type { SourceInfo } from 'ol/source/GeoTIFF';
/** A GeoTIFF in UTM zone 34N (a Sentinel-2 scene over Kraków) drawn on a Web Mercator map, centred once its metadata is read. */
@Component({
selector: 'app-geotiff-reprojection',
imports: [
DefaultControlComponent,
DefaultInteractionComponent,
LayerWebGLTileComponent,
MapComponent,
SourceGeoTIFFComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="9" [center]="center()" />
<aol-layer-webgltile>
<aol-source-geotiff
[sources]="sources"
attributions="Contains modified Copernicus Sentinel data 2024"
(viewReady)="centerOn($event)"
/>
</aol-layer-webgltile>
</aol-map>
`,
})
export class GeotiffReprojection {
/** 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 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',
},
];
/** 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.
geotiff-reprojection.react.tsximport { useState } from 'react';
import type { Coordinate as OLCoordinate } from 'ol/coordinate.js';
import { transform } from 'ol/proj.js';
import type { SourceInfo } from 'ol/source/GeoTIFF.js';
import type { ViewOptions } from 'ol/View.js';
import { DefaultControls, DefaultInteractions, Map, View } from 'cc-openlayers/react';
import { GeoTIFFSource, WebGLTileLayer } from 'cc-openlayers/react/webgl';
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',
},
];
/** A GeoTIFF in UTM zone 34N (a Sentinel-2 scene over Kraków) drawn on a Web Mercator map, centred once its metadata is read. */
export function GeotiffReprojection() {
/** 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'));
/** 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} />
<WebGLTileLayer>
<GeoTIFFSource
sources={SOURCES}
attributions="Contains modified Copernicus Sentinel data 2024"
onViewReady={centerOn}
/>
</WebGLTileLayer>
</Map>
);
}How the React version works
A Sentinel-2 scene in UTM zone 34N drawn on a Web Mercator map, which moves to the scene's centre once its metadata are 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 |
|---|---|
<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-view [zoom]="9" [center]="center()" /> intentionally omits a projection input so the map stays in OpenLayers’ default EPSG:3857 Web Mercator projection, starting at transform([19.9368, 50.0614], 'EPSG:4326', 'EPSG:3857').
aol-source-geotiff opens the remote TCI.tif with no explicit projection override—detecting UTM zone 34N automatically from the file’s GeoKeys so aol-layer-webgltile reprojects tiles on the fly. When (viewReady)="centerOn($event)" fires, centerOn reads view.center and view.projection from the emitted UTM options and calls transform(view.center, view.projection, 'EPSG:3857') to update the center signal.
How it works
aol-source-geotiffreadsTCI.tiffrom[sources]="sources"and extracts its native UTM zone 34N projection from the TIFF headers.<aol-view [zoom]="9" [center]="center()" />leaves the map in default Web Mercator soaol-layer-webgltilereprojects UTM tiles during rendering.(viewReady)="centerOn($event)"transforms the file-reported UTM centre intoEPSG:3857and updates thecentersignal.
Pitfalls
- Passing the entire
ViewOptionsobject emitted by(viewReady)straight intoaol-viewswitches the map itself into UTM zone 34N—extract andtransformonlyview.center(or extent) when the map must remain inEPSG:3857. - Copernicus Sentinel-2 scenes require visible legal attribution (
Contains modified Copernicus Sentinel datawith the acquisition year), configured directly on the GeoTIFF source.
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.