Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
Three COGs in two UTM zones as one layer
Mosaic three Sentinel-2 Cloud Optimized GeoTIFFs across UTM zones 33N and 34N in one OpenLayers WebGLTileLayer with live band-channel selects.

What this example shows
Three adjacent Sentinel-2 scenes acquired on 13 August 2025 across southern Poland—straddling the 18° E meridian boundary between UTM zone 33N (EPSG:32633) and UTM zone 34N (EPSG:32634)—render seamlessly as a single reprojected WebGL mosaic centred on Kraków.
Three dropdown selects below the map (Red channel, Green channel, Blue channel) let you map any of the four loaded spectral bands (visible red, visible green, visible blue, near infrared) into each display channel on the fly.
When you need it
Regional agriculture, forestry and flood assessments routinely span multiple satellite granules and cross adjacent 6-degree UTM zone boundaries.
Passing an array of GeoTIFF sources directly to a single WebGLTileLayer lets OpenLayers reproject each granule from its own UTM zone into EPSG:3857 and style the entire mosaic with one unified shader and shared style variables.
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.
multiple-cogs.shared.tsimport { createEmpty, extend, type Extent } from 'ol/extent.js';
import type { Style } from 'ol/layer/WebGLTile.js';
import { transformExtent } from 'ol/proj.js';
import GeoTIFF from 'ol/source/GeoTIFF.js';
import type { ViewOptions } from 'ol/View.js';
const ARCHIVE = 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs';
/** Three Sentinel-2 scenes of one pass over Kraków, on both sides of the edge of UTM zones 33 and 34. */
const SCENES = [
'33/U/YR/2025/8/S2A_33UYR_20250813_0_L2A',
'34/U/CA/2025/8/S2A_34UCA_20250813_0_L2A',
'34/U/DA/2025/8/S2A_34UDA_20250813_0_L2A',
];
/** The visible red, green and blue bands and the near infrared one, as bands 1 to 4 of each source. */
const BANDS = ['B04', 'B03', 'B02', 'B08'];
export const CHANNELS = ['red', 'green', 'blue'] as const;
export type Channel = (typeof CHANNELS)[number];
export const BAND_OPTIONS = ['visible red', 'visible green', 'visible blue', 'near infrared'].map((label, index) => ({
value: index + 1,
label,
}));
export const STYLE: Style = {
color: [
'array',
['band', ['var', 'red']],
['band', ['var', 'green']],
['band', ['var', 'blue']],
// The alpha band OpenLayers adds after the four from the files' no-data value: clear outside the scenes.
['band', 5],
],
};
/** One GeoTIFF source for each scene; each starts reading its files at creation. */
export function createSources(): GeoTIFF[] {
return SCENES.map(
(scene) =>
new GeoTIFF({
sources: BANDS.map((band) => ({ url: `${ARCHIVE}/${scene}/${band}.tif`, max: 3000 })),
attributions: 'Contains modified Copernicus Sentinel data 2025',
})
);
}
/**
* Reads the grids of the sources' files and returns the scenes together in Spherical Mercator. The files name
* their projections by code, EPSG:32633 and EPSG:32634: OpenLayers builds the UTM zones itself.
*/
export async function sceneExtent(sources: GeoTIFF[]): Promise<Extent> {
const views: ViewOptions[] = await Promise.all(sources.map((source) => source.getView()));
const extent = createEmpty();
for (const { extent: scene, projection } of views) {
if (scene && projection) extend(extent, transformExtent(scene, projection, 'EPSG:3857'));
}
return extent;
}multiple-cogs.tsimport { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { DefaultControlComponent, DefaultInteractionComponent, MapComponent, ViewComponent } from 'cc-openlayers';
import { LayerWebGLTileComponent } from 'cc-openlayers/webgl';
import type { Extent } from 'ol/extent';
import { fromLonLat } from 'ol/proj';
import { BAND_OPTIONS, type Channel, CHANNELS, createSources, sceneExtent, STYLE } from './multiple-cogs.shared';
/**
* Three Sentinel-2 COGs of 13 August 2025, each with its visible red, green and blue bands and the near infrared
* one. The scenes lie on both sides of the edge of UTM zones 33 and 34, so they are reprojected onto one map; the
* selects choose which band each colour channel shows.
*/
@Component({
selector: 'app-multiple-cogs',
imports: [DefaultControlComponent, DefaultInteractionComponent, LayerWebGLTileComponent, MapComponent, ViewComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
@if (extent(); as extent) {
<aol-view projection="EPSG:3857" [center]="krakow" [zoom]="9" [extent]="extent" />
}
<aol-layer-webgltile [sources]="sources" [style]="style" [variables]="variables()" />
</aol-map>
<form class="example-controls">
@for (channel of channels; track channel) {
<label>
{{ channel === 'red' ? 'Red' : channel === 'green' ? 'Green' : 'Blue' }} channel
<select [id]="channel" (change)="choose(channel, $event)">
@for (band of bands; track band.value) {
<option [value]="band.value" [selected]="band.value === variables()[channel]">{{ band.label }}</option>
}
</select>
</label>
}
</form>
`,
})
export class MultipleCogs {
protected readonly krakow = fromLonLat([19.9373, 50.0617]);
protected readonly channels = CHANNELS;
protected readonly bands = BAND_OPTIONS;
protected readonly style = STYLE;
protected readonly sources = createSources();
/** The scenes together in Spherical Mercator, read from their files. */
protected readonly extent = signal<Extent | undefined>(undefined);
/** The band each colour channel shows. */
protected readonly variables = signal<Record<Channel, number>>({ red: 1, green: 2, blue: 3 });
constructor() {
void sceneExtent(this.sources).then(
(extent) => this.extent.set(extent),
(error: unknown) => console.error('The scenes could not be read', error)
);
}
protected choose(channel: Channel, event: Event): void {
const band = Number((event.target as HTMLSelectElement).value);
this.variables.update((bands) => ({ ...bands, [channel]: band }));
}
} 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.
multiple-cogs.react.tsximport { useEffect, useMemo, useState } from 'react';
import type { Extent } from 'ol/extent.js';
import { fromLonLat } from 'ol/proj.js';
import { DefaultControls, DefaultInteractions, Map, View } from 'cc-openlayers/react';
import { WebGLTileLayer } from 'cc-openlayers/react/webgl';
import { BAND_OPTIONS, type Channel, CHANNELS, createSources, sceneExtent, STYLE } from './multiple-cogs.shared';
const LABELS: Record<Channel, string> = { red: 'Red', green: 'Green', blue: 'Blue' };
const KRAKOW = fromLonLat([19.9373, 50.0617]);
/**
* Three Sentinel-2 COGs of 13 August 2025, each with its visible red, green and blue bands and the near infrared
* one. The scenes lie on both sides of the edge of UTM zones 33 and 34, so they are reprojected onto one map; the
* selects choose which band each colour channel shows.
*/
export function MultipleCogs() {
// Memoised so that StrictMode's second render reuses the sources (each starts reading its files at creation).
const sources = useMemo(() => createSources(), []);
/** The scenes together in Spherical Mercator, read from their files. */
const [extent, setExtent] = useState<Extent>();
/** The band each colour channel shows. */
const [variables, setVariables] = useState<Record<Channel, number>>({ red: 1, green: 2, blue: 3 });
useEffect(() => {
let current = true;
void sceneExtent(sources).then(
(all) => {
if (current) setExtent(all);
},
(error: unknown) => console.error('The scenes could not be read', error)
);
return () => {
current = false;
};
}, [sources]);
return (
<>
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
{extent && <View projection="EPSG:3857" center={KRAKOW} zoom={9} extent={extent} />}
<WebGLTileLayer sources={sources} style={STYLE} variables={variables} />
</Map>
<form className="example-controls">
{CHANNELS.map((channel) => (
<label key={channel}>
{LABELS[channel]} channel
<select
id={channel}
value={variables[channel]}
onChange={(event) => setVariables({ ...variables, [channel]: Number(event.target.value) })}
>
{BAND_OPTIONS.map((band) => (
<option key={band.value} value={band.value}>
{band.label}
</option>
))}
</select>
</label>
))}
</form>
</>
);
}multiple-cogs.shared.tsimport { createEmpty, extend, type Extent } from 'ol/extent.js';
import type { Style } from 'ol/layer/WebGLTile.js';
import { transformExtent } from 'ol/proj.js';
import GeoTIFF from 'ol/source/GeoTIFF.js';
import type { ViewOptions } from 'ol/View.js';
const ARCHIVE = 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs';
/** Three Sentinel-2 scenes of one pass over Kraków, on both sides of the edge of UTM zones 33 and 34. */
const SCENES = [
'33/U/YR/2025/8/S2A_33UYR_20250813_0_L2A',
'34/U/CA/2025/8/S2A_34UCA_20250813_0_L2A',
'34/U/DA/2025/8/S2A_34UDA_20250813_0_L2A',
];
/** The visible red, green and blue bands and the near infrared one, as bands 1 to 4 of each source. */
const BANDS = ['B04', 'B03', 'B02', 'B08'];
export const CHANNELS = ['red', 'green', 'blue'] as const;
export type Channel = (typeof CHANNELS)[number];
export const BAND_OPTIONS = ['visible red', 'visible green', 'visible blue', 'near infrared'].map((label, index) => ({
value: index + 1,
label,
}));
export const STYLE: Style = {
color: [
'array',
['band', ['var', 'red']],
['band', ['var', 'green']],
['band', ['var', 'blue']],
// The alpha band OpenLayers adds after the four from the files' no-data value: clear outside the scenes.
['band', 5],
],
};
/** One GeoTIFF source for each scene; each starts reading its files at creation. */
export function createSources(): GeoTIFF[] {
return SCENES.map(
(scene) =>
new GeoTIFF({
sources: BANDS.map((band) => ({ url: `${ARCHIVE}/${scene}/${band}.tif`, max: 3000 })),
attributions: 'Contains modified Copernicus Sentinel data 2025',
})
);
}
/**
* Reads the grids of the sources' files and returns the scenes together in Spherical Mercator. The files name
* their projections by code, EPSG:32633 and EPSG:32634: OpenLayers builds the UTM zones itself.
*/
export async function sceneExtent(sources: GeoTIFF[]): Promise<Extent> {
const views: ViewOptions[] = await Promise.all(sources.map((source) => source.getView()));
const extent = createEmpty();
for (const { extent: scene, projection } of views) {
if (scene && projection) extend(extent, transformExtent(scene, projection, 'EPSG:3857'));
}
return extent;
}How the React version works
Three Sentinel-2 scenes of one pass over Kraków, on both sides of the edge of UTM zones 33 and 34, mixed in one layer; three lists choose the band of each colour channel, for example near infrared in red as false colour. 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 import the channels, the band options, the style, createSources, which makes the three sources, and sceneExtent from the example's .shared.ts file, so the logic exists once.
From Angular to React
| Angular | React |
|---|---|
three ol/source/GeoTIFF objects passed as [sources] | the same three made once by createSources in useMemo and passed as sources to WebGLTileLayer |
the extent of the three views combined after getView() | a useEffect that combines the three views' extents into useState; the View is rendered once the extent is known |
the band lists and style variables in a computed | useState per channel and variables on the 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 sources are made in useMemo because each starts reading when it is constructed.
Architecture and OpenLayers mechanics
In multiple-cogs.shared.ts, SCENES lists one EPSG:32633 scene (33UYR) and two EPSG:32634 scenes (34UCA, 34UDA), each instantiated as a new GeoTIFF over four single-band COG files (B04, B03, B02 and B08 with max: 3000). Helper sceneExtent awaits Promise.all across all three source.getView() promises and merges each transformExtent(scene, projection, 'EPSG:3857') box before @if (extent(); as extent) mounts aol-view fenced to [extent]="extent".
One aol-layer-webgltile binds [sources]="sources", [style]="style" and [variables]="variables()". Its RGBA array expression reads ['band', ['var', 'red']], green and blue alongside ['band', 5] for alpha, so changing any <select> updates variables without replacing the compiled style.
How it works
SCENEScreates threenew GeoTIFFinstances (13 August 2025), each combiningB04,B03,B02andB08withmax: 3000.- A single
aol-layer-webgltilerenders all three sources via[sources]="sources", mappingred,greenandbluestyle variables to bands 1–4 and using['band', 5]for transparency outside swath edges. Promise.allreads all three headers and mergestransformExtent(scene, projection, 'EPSG:3857')into the constrainingextentofaol-view.- Channel <select> controls mutate
variables, updating WebGL uniforms live rather than rebuilding[style].
Pitfalls
- OpenLayers appends the automatic nodata alpha channel after all data bands of a
GeoTIFFsource: with four single-band TIFFs (B04,B03,B02,B08), alpha is['band', 5], without which one scene’s black nodata collar would paint opaque black over its neighbour. - Both
EPSG:32633(UTM 33N) andEPSG:32634(UTM 34N) are built into OpenLayers natively, so cross-zone UTM mosaicking requires zero external proj4 definitions.
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.