Raster, GeoTIFF and WebGL · Angular, React and OpenLayers

Three COGs in two UTM zones as one layer

Mosaic three Sentinel-2 Cloud Optimized GeoTIFFs across UTM zones 33N and 34N in one OpenLayers WebGLTileLayer with live band-channel selects.

Three Sentinel-2 scenes of southern Poland joined into one true-colour image around Kraków, green and brown fields and dark woods, the western scene's edge slanting on the left, and three channel selects below.
A screenshot of the example. Contains modified Copernicus Sentinel data 2025.

What this example shows

Three adjacent Sentinel-2 scenes acquired on 13 August 2025 across southern Poland—straddling the 18° E meridian boundary between UTM zone 33N (EPSG:32633) and UTM zone 34N (EPSG:32634)—render seamlessly as a single reprojected WebGL mosaic centred on Kraków.

Three dropdown selects below the map (Red channel, Green channel, Blue channel) let you map any of the four loaded spectral bands (visible red, visible green, visible blue, near infrared) into each display channel on the fly.

When you need it

Regional agriculture, forestry and flood assessments routinely span multiple satellite granules and cross adjacent 6-degree UTM zone boundaries.

Passing an array of GeoTIFF sources directly to a single WebGLTileLayer lets OpenLayers reproject each granule from its own UTM zone into EPSG:3857 and style the entire mosaic with one unified shader and shared style variables.

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.

multiple-cogs.shared.ts
import { createEmpty, extend, type Extent } from 'ol/extent.js';
import type { Style } from 'ol/layer/WebGLTile.js';
import { transformExtent } from 'ol/proj.js';
import GeoTIFF from 'ol/source/GeoTIFF.js';
import type { ViewOptions } from 'ol/View.js';

const ARCHIVE = 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs';

/** Three Sentinel-2 scenes of one pass over Kraków, on both sides of the edge of UTM zones 33 and 34. */
const SCENES = [
  '33/U/YR/2025/8/S2A_33UYR_20250813_0_L2A',
  '34/U/CA/2025/8/S2A_34UCA_20250813_0_L2A',
  '34/U/DA/2025/8/S2A_34UDA_20250813_0_L2A',
];

/** The visible red, green and blue bands and the near infrared one, as bands 1 to 4 of each source. */
const BANDS = ['B04', 'B03', 'B02', 'B08'];

export const CHANNELS = ['red', 'green', 'blue'] as const;
export type Channel = (typeof CHANNELS)[number];

export const BAND_OPTIONS = ['visible red', 'visible green', 'visible blue', 'near infrared'].map((label, index) => ({
  value: index + 1,
  label,
}));

export const STYLE: Style = {
  color: [
    'array',
    ['band', ['var', 'red']],
    ['band', ['var', 'green']],
    ['band', ['var', 'blue']],
    // The alpha band OpenLayers adds after the four from the files' no-data value: clear outside the scenes.
    ['band', 5],
  ],
};

/** One GeoTIFF source for each scene; each starts reading its files at creation. */
export function createSources(): GeoTIFF[] {
  return SCENES.map(
    (scene) =>
      new GeoTIFF({
        sources: BANDS.map((band) => ({ url: `${ARCHIVE}/${scene}/${band}.tif`, max: 3000 })),
        attributions: 'Contains modified Copernicus Sentinel data 2025',
      })
  );
}

/**
 * Reads the grids of the sources' files and returns the scenes together in Spherical Mercator. The files name
 * their projections by code, EPSG:32633 and EPSG:32634: OpenLayers builds the UTM zones itself.
 */
export async function sceneExtent(sources: GeoTIFF[]): Promise<Extent> {
  const views: ViewOptions[] = await Promise.all(sources.map((source) => source.getView()));
  const extent = createEmpty();
  for (const { extent: scene, projection } of views) {
    if (scene && projection) extend(extent, transformExtent(scene, projection, 'EPSG:3857'));
  }
  return extent;
}
multiple-cogs.ts
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { DefaultControlComponent, DefaultInteractionComponent, MapComponent, ViewComponent } from 'cc-openlayers';
import { LayerWebGLTileComponent } from 'cc-openlayers/webgl';
import type { Extent } from 'ol/extent';
import { fromLonLat } from 'ol/proj';
import { BAND_OPTIONS, type Channel, CHANNELS, createSources, sceneExtent, STYLE } from './multiple-cogs.shared';

/**
 * Three Sentinel-2 COGs of 13 August 2025, each with its visible red, green and blue bands and the near infrared
 * one. The scenes lie on both sides of the edge of UTM zones 33 and 34, so they are reprojected onto one map; the
 * selects choose which band each colour channel shows.
 */
@Component({
  selector: 'app-multiple-cogs',
  imports: [DefaultControlComponent, DefaultInteractionComponent, LayerWebGLTileComponent, MapComponent, ViewComponent],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      @if (extent(); as extent) {
        <aol-view projection="EPSG:3857" [center]="krakow" [zoom]="9" [extent]="extent" />
      }
      <aol-layer-webgltile [sources]="sources" [style]="style" [variables]="variables()" />
    </aol-map>
    <form class="example-controls">
      @for (channel of channels; track channel) {
        <label>
          {{ channel === 'red' ? 'Red' : channel === 'green' ? 'Green' : 'Blue' }} channel
          <select [id]="channel" (change)="choose(channel, $event)">
            @for (band of bands; track band.value) {
              <option [value]="band.value" [selected]="band.value === variables()[channel]">{{ band.label }}</option>
            }
          </select>
        </label>
      }
    </form>
  `,
})
export class MultipleCogs {
  protected readonly krakow = fromLonLat([19.9373, 50.0617]);
  protected readonly channels = CHANNELS;
  protected readonly bands = BAND_OPTIONS;
  protected readonly style = STYLE;

  protected readonly sources = createSources();
  /** The scenes together in Spherical Mercator, read from their files. */
  protected readonly extent = signal<Extent | undefined>(undefined);
  /** The band each colour channel shows. */
  protected readonly variables = signal<Record<Channel, number>>({ red: 1, green: 2, blue: 3 });

  constructor() {
    void sceneExtent(this.sources).then(
      (extent) => this.extent.set(extent),
      (error: unknown) => console.error('The scenes could not be read', error)
    );
  }

  protected choose(channel: Channel, event: Event): void {
    const band = Number((event.target as HTMLSelectElement).value);
    this.variables.update((bands) => ({ ...bands, [channel]: band }));
  }
}

Architecture and OpenLayers mechanics

In multiple-cogs.shared.ts, SCENES lists one EPSG:32633 scene (33UYR) and two EPSG:32634 scenes (34UCA, 34UDA), each instantiated as a new GeoTIFF over four single-band COG files (B04, B03, B02 and B08 with max: 3000). Helper sceneExtent awaits Promise.all across all three source.getView() promises and merges each transformExtent(scene, projection, 'EPSG:3857') box before @if (extent(); as extent) mounts aol-view fenced to [extent]="extent".

One aol-layer-webgltile binds [sources]="sources", [style]="style" and [variables]="variables()". Its RGBA array expression reads ['band', ['var', 'red']], green and blue alongside ['band', 5] for alpha, so changing any <select> updates variables without replacing the compiled style.

How it works

  • SCENES creates three new GeoTIFF instances (13 August 2025), each combining B04, B03, B02 and B08 with max: 3000.
  • A single aol-layer-webgltile renders all three sources via [sources]="sources", mapping red, green and blue style variables to bands 1–4 and using ['band', 5] for transparency outside swath edges.
  • Promise.all reads all three headers and merges transformExtent(scene, projection, 'EPSG:3857') into the constraining extent of aol-view.
  • Channel <select> controls mutate variables, updating WebGL uniforms live rather than rebuilding [style].

Pitfalls

  • OpenLayers appends the automatic nodata alpha channel after all data bands of a GeoTIFF source: with four single-band TIFFs (B04, B03, B02, B08), alpha is ['band', 5], without which one scene’s black nodata collar would paint opaque black over its neighbour.
  • Both EPSG:32633 (UTM 33N) and EPSG:32634 (UTM 34N) are built into OpenLayers natively, so cross-zone UTM mosaicking requires zero external proj4 definitions.

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.