Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
A GeoTIFF scaled band by band
Balance Sentinel-2 true-colour GeoTIFF contrast in OpenLayers without shaders by configuring independent per-band min, max and nodata arrays.

What this example shows
A Copernicus Sentinel-2 true-colour scene (TCI.tif) covering Kraków, the Niepołomice Forest and surrounding farmland renders in its native UTM projection with noticeably brighter, colour-balanced contrast and transparent outer swath borders—achieved purely through source band configuration with zero custom WebGL style expressions.
When you need it
Raw earth-observation imagery frequently clusters pixel values inside a narrow sub-range of 0..255 or 0..65535 and suffers from atmospheric blue haze in the blue channel, looking dull or colour-cast out of the box.
Configuring per-band min and max arrays directly on SourceInfo stretches contrast and neutralises colour casts during tile decoding without writing custom shader math.
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-per-band-stats.tsimport { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { DefaultControlComponent, DefaultInteractionComponent, MapComponent, ViewComponent } from 'cc-openlayers';
import { LayerWebGLTileComponent, SourceGeoTIFFComponent } from 'cc-openlayers/webgl';
import type { ViewOptions } from 'ol/View';
import type { SourceInfo } from 'ol/source/GeoTIFF';
/** A true-colour Sentinel-2 scene over Kraków stretched with its own minimum and maximum for each of the red, green and blue bands. */
@Component({
selector: 'app-geotiff-per-band-stats',
imports: [
DefaultControlComponent,
DefaultInteractionComponent,
LayerWebGLTileComponent,
MapComponent,
SourceGeoTIFFComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
@if (view(); as options) {
<aol-view
[projection]="options.projection"
[resolutions]="options.resolutions"
[extent]="options.extent"
[center]="options.center"
[zoom]="options.zoom"
/>
}
<aol-layer-webgltile>
<aol-source-geotiff
[sources]="sources"
attributions="Contains modified Copernicus Sentinel data 2024"
(viewReady)="view.set($event)"
/>
</aol-layer-webgltile>
</aol-map>
`,
})
export class GeotiffPerBandStats {
readonly view = signal<ViewOptions | undefined>(undefined);
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,
min: [10, 20, 10],
max: [160, 170, 150],
},
];
} 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-per-band-stats.react.tsximport { useState } from 'react';
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',
nodata: 0,
min: [10, 20, 10],
max: [160, 170, 150],
},
];
/** A true-colour Sentinel-2 scene over Kraków stretched with its own minimum and maximum for each of the red, green and blue bands. */
export function GeotiffPerBandStats() {
const [options, setOptions] = useState<ViewOptions | undefined>(undefined);
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
{options && (
<View
projection={options.projection}
resolutions={options.resolutions}
extent={options.extent}
center={options.center}
zoom={options.zoom}
/>
)}
<WebGLTileLayer>
<GeoTIFFSource
sources={SOURCES}
attributions="Contains modified Copernicus Sentinel data 2024"
onViewReady={setOptions}
/>
</WebGLTileLayer>
</Map>
);
}How the React version works
A true-colour Sentinel-2 scene over Kraków stretched with its own minimum and maximum for each of the red, green and blue bands, zero pixels ignored. 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) and a signal of the view options | onViewReady and useState; the View is rendered once the options are there |
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
The single entry in sources points at TCI.tif with nodata: 0, min: [10, 20, 10] and max: [160, 170, 150] corresponding to the red, green and blue bands respectively. With default normalization active, aol-source-geotiff linearly rescales each band i from [min[i], max[i]] onto 0..255 (255 * (v - min) / (max - min)) and clamps out-of-range values.
(viewReady)="view.set($event)" passes the file’s native UTM projection, resolutions, extent, center and zoom straight into aol-view inside @if (view(); as options).
How it works
- Configuring
min: [10, 20, 10]andmax: [160, 170, 150]stretches the red, green and blue bands ofTCI.tifindependently. - OpenLayers maps each band linearly onto bytes (0..255) by 255 / (max - min) and clamps values below
minor abovemax. nodata: 0appends an alpha channel that turns outer collar pixels transparent where all three RGB bands equal0.
Pitfalls
- Multi-band
nodatatransparency triggers strictly when every band of a pixel matches its no-data value—a dark shadow pixel that hits0in red alone while green is 12 remains completely opaque. - Setting
mintoo high crushes dark forest shadows to solid black (0), while settingmaxtoo low clips bright industrial roofs and clouds to pure white (255).
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.