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.

A square Sentinel-2 image of Nowa Huta on a dark background: housing estates, a road junction in the north-east and fields and woods down to the Vistula.
A screenshot of the example. Contains modified Copernicus Sentinel data 2024.

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.ts
import { 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);
      }
    });
  }
}

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.tif inside PendingTasks produces an in-memory Blob passed via [{ blob }] into sources.
  • @if (sources(); as sources) mounts the GeoTIFF source once the Blob exists, 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 Blob holds 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 PendingTasks prevents prerenderers and E2E stability waiters from snapshotting the page before the Blob finishes loading.

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.