Raster, GeoTIFF and WebGL · Angular, React and OpenLayers

A GeoTIFF in its own projection over an orthophoto

Overlay a UTM 34N Sentinel-2 GeoTIFF onto a Web Mercator WMTS orthophotomap in OpenLayers with automatic GeoKeys CRS detection and gamma style.

GUGiK's orthophotomap of southern Poland with the Sentinel-2 scene of Kraków laid over it at 70 % opacity, browner than the photo, its western and slanted eastern edges both in view.
A screenshot of the example. Contains modified Copernicus Sentinel data 2024. Orthophotomap © GUGiK.

What this example shows

Across southern Poland at zoom 9, a Sentinel-2 satellite swath stored natively in UTM zone 34N (EPSG:32634)—complete with its slanted orbital edge and transparent nodata: 0 margins—reprojects on the GPU at 70% opacity with gamma: 0.7 colour correction directly atop GUGiK’s EPSG:3857 WMTS orthophotomap.

When you need it

Raw satellite scenes and engineering rasters arrive in regional UTM zones or national grids, yet analysts need to drape them directly over standard Web Mercator basemaps without running server-side gdalwarp jobs.

OpenLayers reads embedded GeoTIFF projection GeoKeys automatically and warps raster tiles on the fly inside WebGL.

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

const size = getWidth(EXTENT) / 256;

/** A Sentinel-2 COG in UTM zone 34N, its projection looked up automatically, drawn over the orthophoto of a Web Mercator map. */
@Component({
  selector: 'app-cog-projection',
  imports: [
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerTileComponent,
    LayerWebGLTileComponent,
    MapComponent,
    SourceGeoTIFFComponent,
    SourceTileWMTSComponent,
    TileGridWMTSComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="9" [center]="center()" />
      <aol-layer-tile>
        <aol-source-tilewmts
          attributions='Tiles © <a href="https://www.geoportal.gov.pl/" target="_blank">GUGiK</a>'
          url="https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMTS/StandardResolution"
          layer="ORTOFOTOMAPA"
          matrixSet="EPSG:3857"
          format="image/jpeg"
          projection="EPSG:3857"
          [style]="'default'"
        >
          <aol-tilegrid-wmts [origin]="origin" [resolutions]="resolutions" [matrixIds]="matrixIds" />
        </aol-source-tilewmts>
      </aol-layer-tile>
      <aol-layer-webgltile [opacity]="0.7" [style]="{ gamma: 0.7 }">
        <aol-source-geotiff
          attributions="Contains modified Copernicus Sentinel data 2024"
          [sources]="sources"
          [loadMissingProjection]="true"
          (viewReady)="centerOn($event)"
        />
      </aol-layer-webgltile>
    </aol-map>
  `,
})
export class CogProjection {
  /** 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 origin = getTopLeft(EXTENT);
  protected readonly resolutions = Array.from({ length: 20 }, (_, z) => size / 2 ** z);
  protected readonly matrixIds = Array.from({ length: 20 }, (_, z) => `EPSG:3857:${z}`);
  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',
      nodata: 0,
    },
  ];

  /** 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-source-geotiff opens TCI.tif (nodata: 0), detects EPSG:32634 from its GeoKeys (supported natively by OpenLayers for all 120 north/south UTM zones, with [loadMissingProjection]="true" available for proj4 lookups on other EPSG codes), and renders at [opacity]="0.7" and [style]="{ gamma: 0.7 }" above aol-source-tilewmts (ORTOFOTOMAPA in EPSG:3857).

When (viewReady)="centerOn($event)" fires, the scene’s UTM centre transforms into EPSG:3857 to position the [zoom]="9" Web Mercator view.

How it works

  • aol-source-geotiff reads TCI.tif with nodata: 0 and extracts EPSG:32634 (UTM zone 34N) automatically from embedded GeoKeys.
  • OpenLayers supports all standard UTM zones natively, while [loadMissingProjection]="true" resolves other EPSG codes when proj4 is registered.
  • The WebGL layer applies [opacity]="0.7" and [style]="{ gamma: 0.7 }" over GUGiK’s ORTOFOTOMAPA aol-source-tilewmts (EPSG:3857).
  • (viewReady)="centerOn($event)" reprojects the scene’s UTM midpoint to EPSG:3857 for the [zoom]="9" map view.

Pitfalls

  • While OpenLayers constructs UTM zones (EPSG:32601–32660 and EPSG:32701–32760) out of the box, national grids (such as Polish EPSG:2180) still require calling register(proj4) before [loadMissingProjection]="true" can resolve them.

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.