Raster, GeoTIFF and WebGL · Angular, React and OpenLayers

A Cloud Optimized GeoTIFF in a WebGL layer

Stream a Sentinel-2 Cloud Optimized GeoTIFF directly in OpenLayers WebGL using HTTP range reads, native UTM GeoKeys view setup and overzooming.

A true-colour Sentinel-2 image of Kraków from 2024: the Vistula winding through the city, the Planty ring around the Old Town, the woods of Las Wolski in the west and fields at the edges.
A screenshot of the example. Contains modified Copernicus Sentinel data 2024.

What this example shows

A true-colour Copernicus Sentinel-2 acquisition of Kraków from 14 August 2024—showing the winding Vistula, the Planty ring, Las Wolski forest and surrounding farmland—streams directly from a single Cloud Optimized GeoTIFF (TCI.tif) in a WebGL tile layer without any tile server.

When you need it

Modern earth-observation archives (AWS Registry of Open Data, Copernicus, Planetary Computer) store satellite scenes, drone orthomosaics and DEMs on plain S3/HTTP object storage as Cloud Optimized GeoTIFFs (COGs).

OpenLayers’ GeoTIFF source issues HTTP Range requests for only the internal TIFF tiles and overviews visible on screen—displaying multi-gigabyte rasters directly from static storage.

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.shared.ts
import type { Coordinate } from 'ol/coordinate.js';
import type { SourceInfo } from 'ol/source/GeoTIFF.js';

const SCENE =
  'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/34/U/DA/2024/8/S2B_34UDA_20240814_0_L2A';

/** The Main Market Square in the scene's projection, UTM zone 34N (EPSG:32634). */
export const KRAKOW: Coordinate = [423901, 5545999];

export const SOURCES: SourceInfo[] = [{ url: `${SCENE}/TCI.tif` }];
cog.ts
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { DefaultControlComponent, DefaultInteractionComponent, MapComponent, ViewComponent } from 'cc-openlayers';
import { LayerWebGLTileComponent, SourceGeoTIFFComponent } from 'cc-openlayers/webgl';
import { withHigherResolutions, type ViewOptions } from 'ol/View';
import { KRAKOW, SOURCES } from './cog.shared';

/** The true-colour image of a Sentinel-2 scene over Kraków: one three-band COG, read tile by tile in its own projection. */
@Component({
  selector: 'app-cog',
  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"
          [showFullExtent]="options.showFullExtent"
          [center]="krakow"
          [resolution]="20"
        />
      }
      <aol-layer-webgltile>
        <aol-source-geotiff
          [sources]="sources"
          attributions="Contains modified Copernicus Sentinel data 2024"
          (viewReady)="showScene($event)"
        />
      </aol-layer-webgltile>
    </aol-map>
  `,
})
export class Cog {
  readonly view = signal<ViewOptions | undefined>(undefined);
  protected readonly krakow = KRAKOW;
  protected readonly sources = SOURCES;

  /** The view of the scene with one resolution finer than its 10 m pixels, to zoom in past them. */
  protected showScene(view: ViewOptions): void {
    this.view.set(withHigherResolutions(1)(view));
  }
}

Architecture and OpenLayers mechanics

aol-source-geotiff opens TCI.tif and emits its embedded projection (UTM zone 34N, EPSG:32634), extent and resolution pyramid via (viewReady). Helper showScene pipes those view options through withHigherResolutions(1)—adding one extra 5 m/px overzoom step beyond the file’s finest 10 m/px pixels.

@if (view(); as options) mounts aol-view once metadata is ready, starting at [resolution]="20" centred on krakow ([423901, 5545999] in UTM 34N metres).

How it works

  • aol-source-geotiff reads the three-band true-colour TCI.tif scene and emits native view options through (viewReady).
  • withHigherResolutions(1) in showScene extends the view’s zoom ceiling one level finer than the file’s native 10 m pixels.
  • @if (view(); as options) initialises aol-view in native UTM zone 34N at [resolution]="20" m/px once headers parse.
  • krakow specifies the Main Square centre in projected UTM 34N metres ([423901, 5545999]).

Pitfalls

  • A view built directly from GeoTIFF metadata stops zooming at the file’s finest native pixel size (10 m/px here)—wrap view options with withHigherResolutions whenever users need closer street-level inspection.
  • When the view adopts the file’s native UTM projection, center coordinates must be given in UTM metres rather than WGS84 degrees.

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.