Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
A GeoTIFF fetched through your own loader
Fetch Cloud Optimized GeoTIFF byte ranges through a custom OpenLayers HTTP loader hook for auth headers, retries or caching, keeping Range requests intact.

What this example shows
A true-colour Sentinel-2 scene spanning eastern Kraków and the dark Niepołomice Forest streams byte-range chunks through an application-controlled fetch loader function, automatically centring the viewport on the scene’s footprint (withExtentCenter()).
When you need it
Commercial satellite tasking APIs, enterprise STAC catalogues and private S3 buckets protect Cloud Optimized GeoTIFFs behind Bearer tokens, signed-header proxies, custom retry policies or request telemetry.
Providing a custom loader lets your code attach Authorization headers or retry transient 503s while keeping geotiff.js partial byte-range streaming intact.
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-custom-client.shared.tsimport type { SourceInfo } from 'ol/source/GeoTIFF.js';
export 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',
// The loader controls how the data is fetched: it receives the URL, the request headers and an abort signal.
loader: (url, headers, abortSignal) =>
// Custom headers (an authorization token, say), logging, retries or caching would go here.
fetch(url, { headers: { ...headers }, signal: abortSignal }),
},
];cog-custom-client.tsimport { ChangeDetectionStrategy, Component, signal, viewChild } from '@angular/core';
import { DefaultControlComponent, DefaultInteractionComponent, MapComponent, ViewComponent } from 'cc-openlayers';
import { LayerWebGLTileComponent, SourceGeoTIFFComponent } from 'cc-openlayers/webgl';
import { getView, withExtentCenter, withHigherResolutions, type ViewOptions } from 'ol/View';
import { SOURCES } from './cog-custom-client.shared';
/** A true-colour Sentinel-2 scene over Kraków whose requests go through a custom loader function. */
@Component({
selector: 'app-cog-custom-client',
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"
[center]="options.center"
[zoom]="options.zoom"
/>
}
<aol-layer-webgltile>
<aol-source-geotiff
[sources]="sources"
attributions="Contains modified Copernicus Sentinel data 2024"
(viewReady)="showScene()"
/>
</aol-layer-webgltile>
</aol-map>
`,
})
export class CogCustomClient {
readonly view = signal<ViewOptions | undefined>(undefined);
private readonly source = viewChild.required(SourceGeoTIFFComponent);
protected readonly sources = SOURCES;
/** Shows the whole scene with one more level of resolution, centred on its extent. */
protected showScene(): void {
void getView(this.source().instance, withHigherResolutions(1), withExtentCenter()).then((options) =>
this.view.set(options)
);
}
} 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-custom-client.react.tsximport { useRef, useState } from 'react';
import type GeoTIFF from 'ol/source/GeoTIFF.js';
import { getView, withExtentCenter, withHigherResolutions, type ViewOptions } from 'ol/View.js';
import { DefaultControls, DefaultInteractions, Map, View } from 'cc-openlayers/react';
import { GeoTIFFSource, WebGLTileLayer } from 'cc-openlayers/react/webgl';
import { SOURCES } from './cog-custom-client.shared';
/** A true-colour Sentinel-2 scene over Kraków whose requests go through a custom loader function. */
export function CogCustomClient() {
const [view, setView] = useState<ViewOptions>();
const source = useRef<GeoTIFF>(null);
/** Shows the whole scene with one more level of resolution, centred on its extent. */
const showScene = () => {
if (!source.current) return;
void getView(source.current, withHigherResolutions(1), withExtentCenter()).then(setView);
};
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
{view && (
<View projection={view.projection} resolutions={view.resolutions} center={view.center} zoom={view.zoom} />
)}
<WebGLTileLayer>
<GeoTIFFSource
ref={source}
sources={SOURCES}
attributions="Contains modified Copernicus Sentinel data 2024"
onViewReady={showScene}
/>
</WebGLTileLayer>
</Map>
);
}cog-custom-client.shared.tsimport type { SourceInfo } from 'ol/source/GeoTIFF.js';
export 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',
// The loader controls how the data is fetched: it receives the URL, the request headers and an abort signal.
loader: (url, headers, abortSignal) =>
// Custom headers (an authorization token, say), logging, retries or caching would go here.
fetch(url, { headers: { ...headers }, signal: abortSignal }),
},
];How the React version works
A Sentinel-2 scene over Kraków whose range requests go through a custom loader function that receives the URL, the headers and an abort signal. 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 sources with their custom loader from the example's .shared.ts file, so the logic exists once.
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 |
viewChild of the source and (viewReady) | ref on GeoTIFFSource (useRef) and onViewReady calling getView on it |
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
Each source entry supplies a custom loader callback invoked by OpenLayers / geotiff.js with (url, headers, abortSignal) and returning fetch(url, { headers: { ...headers }, signal: abortSignal }).
When (viewReady)="showScene()" fires, getView(this.source().instance, withHigherResolutions(1), withExtentCenter()) reads metadata from viewChild.required(SourceGeoTIFFComponent), adds one overzoom step, and centres the view on the scene.
How it works
- Custom
loaderintercepts every tile/header request with URL, requestheadersand cancellationabortSignal, returningfetch(url, { headers: { ...headers }, signal: abortSignal }). (viewReady)="showScene()"constructs view options viagetView(this.source().instance, withHigherResolutions(1), withExtentCenter())usingviewChild.required(SourceGeoTIFFComponent).withHigherResolutions(1)enables 2× overzoom whilewithExtentCenter()centres the camera without locking pan bounds.
Pitfalls
- Always forward incoming
headers({ ...headers, Authorization: ... }) inside your customfetchcall: geotiff.js relies on the Range: bytes=... header inheaders, and dropping it causes servers to return HTTP 200 with the entire file (Server responded with full file error). - Note that
withExtentCenter()intentionally omits the constrainingextentfrom view options so users can pan freely past the scene’s slanted swath border.
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.