Raster, GeoTIFF and WebGL · Angular, React and OpenLayers

A GeoTIFF reprojected to Web Mercator

Reproject a UTM zone 34N Sentinel-2 Cloud Optimized GeoTIFF onto a Web Mercator OpenLayers map in WebGL and recenter on viewReady metadata.

The Sentinel-2 scene of Kraków on a Web Mercator map: the city in the middle, the Niepołomice Forest east of it, wooded hills in the south and the slanted eastern edge of the scene on the right.
A screenshot of the example. Contains modified Copernicus Sentinel data 2024.

What this example shows

A standalone Copernicus Sentinel-2 true-colour scene (TCI.tif from 14 August 2024) covering Kraków, the Niepołomice Forest and the Carpathian foothills streams from cloud object storage and renders reprojected onto a standard Web Mercator (EPSG:3857) map at zoom 9 with its slanted UTM swath edge clearly visible.

The camera opens initially on central Kraków coordinates and shifts smoothly to the exact centre of the satellite scene as soon as the GeoTIFF header finishes parsing.

When you need it

Earth-observation scenes are archived in local UTM zones (such as EPSG:32634 for southern Poland), whereas web maps usually keep their View in EPSG:3857 so standard XYZ tiles, vector layers and URL coordinates work unchanged.

Letting WebGLTileLayer warp UTM raster tiles into Web Mercator on the GPU eliminates server-side gdalwarp preprocessing while keeping the application’s primary coordinate system consistent.

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-reprojection.ts
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { DefaultControlComponent, DefaultInteractionComponent, MapComponent, ViewComponent } from 'cc-openlayers';
import { LayerWebGLTileComponent, SourceGeoTIFFComponent } from 'cc-openlayers/webgl';
import type { Coordinate } from 'ol/coordinate';
import { transform } from 'ol/proj';
import type { ViewOptions } from 'ol/View';
import type { SourceInfo } from 'ol/source/GeoTIFF';

/** A GeoTIFF in UTM zone 34N (a Sentinel-2 scene over Kraków) drawn on a Web Mercator map, centred once its metadata is read. */
@Component({
  selector: 'app-geotiff-reprojection',
  imports: [
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerWebGLTileComponent,
    MapComponent,
    SourceGeoTIFFComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="9" [center]="center()" />
      <aol-layer-webgltile>
        <aol-source-geotiff
          [sources]="sources"
          attributions="Contains modified Copernicus Sentinel data 2024"
          (viewReady)="centerOn($event)"
        />
      </aol-layer-webgltile>
    </aol-map>
  `,
})
export class GeotiffReprojection {
  /** The map's centre in Web Mercator: Kraków until the image tells its own. */
  readonly center = signal<Coordinate>(transform([19.9368, 50.0614], 'EPSG:4326', 'EPSG:3857'));

  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',
    },
  ];

  /** Moves the map to the image's centre, transformed from the image's projection to the map's. */
  protected centerOn(view: ViewOptions): void {
    if (!view.center || !view.projection) return;
    this.center.set(transform(view.center, view.projection, 'EPSG:3857'));
  }
}

Architecture and OpenLayers mechanics

<aol-view [zoom]="9" [center]="center()" /> intentionally omits a projection input so the map stays in OpenLayers’ default EPSG:3857 Web Mercator projection, starting at transform([19.9368, 50.0614], 'EPSG:4326', 'EPSG:3857').

aol-source-geotiff opens the remote TCI.tif with no explicit projection override—detecting UTM zone 34N automatically from the file’s GeoKeys so aol-layer-webgltile reprojects tiles on the fly. When (viewReady)="centerOn($event)" fires, centerOn reads view.center and view.projection from the emitted UTM options and calls transform(view.center, view.projection, 'EPSG:3857') to update the center signal.

How it works

  • aol-source-geotiff reads TCI.tif from [sources]="sources" and extracts its native UTM zone 34N projection from the TIFF headers.
  • <aol-view [zoom]="9" [center]="center()" /> leaves the map in default Web Mercator so aol-layer-webgltile reprojects UTM tiles during rendering.
  • (viewReady)="centerOn($event)" transforms the file-reported UTM centre into EPSG:3857 and updates the center signal.

Pitfalls

  • Passing the entire ViewOptions object emitted by (viewReady) straight into aol-view switches the map itself into UTM zone 34N—extract and transform only view.center (or extent) when the map must remain in EPSG:3857.
  • Copernicus Sentinel-2 scenes require visible legal attribution (Contains modified Copernicus Sentinel data with the acquisition year), configured directly on the GeoTIFF source.

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.