Raster, GeoTIFF and WebGL · Angular, React and OpenLayers

A WMS time series animated in WebGL

Animate half-hourly NASA GIBS Storm Boris WMS rainfall in OpenLayers WebGLTileLayers while retaining previous timestamps during tile loads.

OpenTopoMap of central Europe with NASA's precipitation of 14 September 2024 at midnight UTC: heavy rain in red over Czechia, Austria and southern Poland and further east over Ukraine and Romania, and Play and Pause below.
A screenshot of the example. Precipitation: NASA GIBS, GPM IMERG. Map style © OpenTopoMap (CC-BY-SA). Map data © OpenStreetMap contributors. Elevation: SRTM.

What this example shows

Across Central Europe (12°–26° E, 47°–53° N) over OpenTopoMap, Play and Pause buttons step NASA’s half-hourly IMERG_Precipitation_Rate_30min rainfall estimates across 14 September 2024 during Storm Boris—cross-fading each new 30-minute radar frame smoothly on the GPU without flashing empty squares.

When you need it

Animated meteorological WMS loops—precipitation, cloud-top temperature, smoke plumes and ocean currents—look broken if changing TIME clears the screen before replacement tiles finish downloading.

Rendering both the base map and the temporal WMS layer through WebGLTileLayer retains textures from earlier source keys on screen until the new timestamp’s tiles arrive and fade in.

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.

wms-time-webgl.shared.ts
import { transformExtent } from 'ol/proj.js';
import { ATTRIBUTION } from 'ol/source/OSM.js';

/** The first instant of the animation: the start of 14 September 2024 (UTC), in milliseconds. */
export const START = Date.UTC(2024, 8, 14);
/** The end of the animation: the start of 15 September 2024 (UTC), in milliseconds. */
export const END = Date.UTC(2024, 8, 15);
/** The distance between two frames of the data, in milliseconds. */
export const STEP = 30 * 60 * 1000;
/** The animation speed in frames per second. */
export const FRAME_RATE = 0.5;
/** The extent of southern Poland and its surroundings, in Web Mercator. */
export const EXTENT = transformExtent([12, 47, 26, 53], 'EPSG:4326', 'EPSG:3857');
/** The attributions of the OpenTopoMap base layer. */
export const TOPOGRAPHY = [
  'Map style © <a href="https://opentopomap.org/">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)',
  ATTRIBUTION,
];
wms-time-webgl.ts
import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, signal } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  MapComponent,
  SourceTileWMSComponent,
  SourceXYZComponent,
  ViewComponent,
} from 'cc-openlayers';
import { LayerWebGLTileComponent } from 'cc-openlayers/webgl';
import { END, EXTENT, FRAME_RATE, START, STEP, TOPOGRAPHY } from './wms-time-webgl.shared';

/**
 * A WMS with a time dimension, animated, with both layers drawn by WebGL: NASA's half-hourly precipitation estimate
 * (GPM IMERG) of the day Storm Boris reached southern Poland, over OpenTopoMap. Play steps the WMS `TIME` parameter
 * by 30 minutes every two seconds, through the day and again; WebGL reads the tiles' pixels, so both sources ask for
 * them with CORS.
 */
@Component({
  selector: 'app-wms-time-webgl',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerWebGLTileComponent,
    MapComponent,
    SourceTileWMSComponent,
    SourceXYZComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="6">
        <aol-coordinate [x]="19.9373" [y]="50.0617" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-webgltile>
        <aol-source-xyz
          url="https://tile.opentopomap.org/{z}/{x}/{y}.png"
          [maxZoom]="17"
          crossOrigin="anonymous"
          [attributions]="topography"
        />
      </aol-layer-webgltile>
      <aol-layer-webgltile [extent]="extent">
        <aol-source-tilewms
          url="https://gibs.earthdata.nasa.gov/wms/epsg3857/best/wms.cgi"
          [params]="{ LAYERS: 'IMERG_Precipitation_Rate_30min', TIME: time() }"
          crossOrigin="anonymous"
          attributions="Precipitation: NASA GIBS, GPM IMERG"
        />
      </aol-layer-webgltile>
    </aol-map>
    <div class="example-controls" role="group" aria-label="Animation controls">
      <button id="play" type="button" (click)="play()">Play</button>
      <button id="pause" type="button" (click)="stop()">Pause</button>
      <span id="info">{{ time() }}</span>
    </div>
  `,
})
export class WmsTimeWebgl {
  protected readonly extent = EXTENT;
  protected readonly topography = TOPOGRAPHY;
  private readonly wmsTime = signal(START);
  /** The time to the second, as GIBS takes it: without milliseconds. */
  protected readonly time = computed(() => new Date(this.wmsTime()).toISOString().replace('.000Z', 'Z'));
  private animationId: ReturnType<typeof setInterval> | null = null;

  constructor() {
    inject(DestroyRef).onDestroy(() => this.stop());
  }

  protected play(): void {
    this.stop();
    this.animationId = setInterval(() => this.setTime(), 1000 / FRAME_RATE);
  }

  protected stop(): void {
    if (this.animationId !== null) {
      clearInterval(this.animationId);
      this.animationId = null;
    }
  }

  private setTime(): void {
    const next = this.wmsTime() + STEP;
    this.wmsTime.set(next < END ? next : START);
  }
}

Architecture and OpenLayers mechanics

aol-source-tilewms queries IMERG_Precipitation_Rate_30min bounded to [extent]="extent" with reactive TIME: time() inside [params] (replacing the params object, so the source calls setParams, on every step).

Clicking play starts a setInterval (1000 / FRAME_RATE, 2 seconds per step) advancing by STEP (30 minutes) across 14 September 2024, while inject(DestroyRef).onDestroy clears the timer when leaving the page.

How it works

  • aol-source-tilewms binds TIME: time() inside [params] to request IMERG_Precipitation_Rate_30min slices reactively.
  • play runs a two-second setInterval (1000 / FRAME_RATE) advancing STEP (30 minutes) through 14 September 2024.
  • WebGL tile rendering retains textures from previous source keys until replacement timestamp tiles finish loading and fading in.
  • Layer [extent]="extent" restricts WMS tile requests to Central Europe (12°–26° E, 47°–53° N).

Pitfalls

  • Stepping the timer faster than the remote WMS can return a viewport of tiles leaves adjacent squares temporarily showing earlier timestamps—keep frame intervals aligned with server response latency.
  • Always clear playback timers via inject(DestroyRef).onDestroy (or a React cleanup return) so background WMS tile polling stops immediately on navigation.

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.