Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
A GeoTIFF read from a Blob
Render an in-memory GeoTIFF Blob directly in an OpenLayers WebGL layer with zero server uploads, full-extent view fitting and SSR PendingTasks.

What this example shows
A Sentinel-2 GeoTIFF crop over Nowa Huta in eastern Kraków—showing housing estates, arterial junctions and fields down to the Vistula—is read into browser memory as a binary Blob and rendered on a dark background fitted cleanly to its full extent.
When you need it
Desktop-grade WebGIS tools let drone operators, agronomists and engineers pick or drag local .tif files from disk via <input type="file"> or Drag-and-Drop—where the browser holds a File / Blob object rather than an HTTP URL.
Passing { blob } directly to OpenLayers’ GeoTIFF source decodes georeferenced imagery 100% locally in browser memory with complete data privacy.
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-blob.tsimport { ChangeDetectionStrategy, Component, inject, PendingTasks, signal } from '@angular/core';
import { DefaultControlComponent, DefaultInteractionComponent, MapComponent, ViewComponent } from 'cc-openlayers';
import { LayerWebGLTileComponent, SourceGeoTIFFComponent } from 'cc-openlayers/webgl';
import type { SourceInfo } from 'ol/source/GeoTIFF';
import type { ViewOptions } from 'ol/View';
/**
* A GeoTIFF read from a Blob: the sample, Sentinel-2's true-colour image of Nowa Huta, is fetched whole and handed
* to the source as a Blob; the view is the one the file describes, in its own projection, with all of it in view.
*/
@Component({
selector: 'app-cog-blob',
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"
[showFullExtent]="true"
/>
}
@if (sources(); as sources) {
<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 CogBlob {
readonly view = signal<ViewOptions | undefined>(undefined);
protected readonly sources = signal<SourceInfo[] | undefined>(undefined);
constructor() {
void inject(PendingTasks).run(async () => {
try {
const response = await fetch('assets/krakow/nowa-huta.tif');
if (!response.ok) throw new Error(`assets/krakow/nowa-huta.tif: ${response.status}`);
this.sources.set([{ blob: await response.blob() }]);
} catch (error) {
console.error('The image could not be loaded', error);
}
});
}
} 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-blob.react.tsximport { useEffect, 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';
/**
* A GeoTIFF read from a Blob: the sample, Sentinel-2's true-colour image of Nowa Huta, is fetched whole and handed
* to the source as a Blob; the view is the one the file describes, in its own projection, with all of it in view.
*/
export function CogBlob() {
const [view, setView] = useState<ViewOptions>();
const [sources, setSources] = useState<SourceInfo[]>();
useEffect(() => {
let current = true;
void (async () => {
try {
const response = await fetch('assets/krakow/nowa-huta.tif');
if (!response.ok) throw new Error(`assets/krakow/nowa-huta.tif: ${response.status}`);
const blob = await response.blob();
if (current) setSources([{ blob }]);
} catch (error) {
console.error('The image could not be loaded', error);
}
})();
return () => {
current = false;
};
}, []);
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
{view && (
<View
projection={view.projection}
resolutions={view.resolutions}
extent={view.extent}
center={view.center}
zoom={view.zoom}
showFullExtent={true}
/>
)}
{sources && (
<WebGLTileLayer>
<GeoTIFFSource
sources={sources}
attributions="Contains modified Copernicus Sentinel data 2024"
onViewReady={setView}
/>
</WebGLTileLayer>
)}
</Map>
);
}How the React version works
A sample of Nowa Huta fetched as a file and read from a Blob, shown whole in its own projection. 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 |
|---|---|
fetching the file into a signal of the Blob | useEffect with fetch and a flag that drops the answer after unmount, a failed load logged, the Blob in useState |
<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
Inside Angular’s PendingTasks wrapper (ensuring SSR prerendering and stability checks wait until binary loading finishes), fetch retrieves assets/krakow/nowa-huta.tif, converts the response to a Blob, and assigns [{ blob }] to sources.
Once @if (sources(); as sources) mounts the WebGL GeoTIFF layer, (viewReady)="view.set($event)" hydrates aol-view with [showFullExtent]="true" so the entire raster fits the viewport at any screen size.
How it works
- Fetching
assets/krakow/nowa-huta.tifinsidePendingTasksproduces an in-memoryBlobpassed via[{ blob }]intosources. @if (sources(); as sources)mounts the GeoTIFF source once theBlobexists, reading TIFF tiles straight from memory without further HTTP requests.(viewReady)="view.set($event)"combined with[showFullExtent]="true"frames the full Nowa Huta raster cleanly.
Pitfalls
- A
Blobholds the entire file in RAM, which is ideal for local user-dropped files of tens of megabytes; for multi-gigabyte rasters hosted remotely, pass a url instead so HTTP range requests stream only visible blocks. - Wrapping startup async work in Angular
PendingTasksprevents prerenderers and E2E stability waiters from snapshotting the page before the Blob finishes loading.
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.