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.

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.tsimport { 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.tsimport { 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);
}
} The React version uses the library's React adapter, cc-openlayers/react: each component creates the OpenLayers object it names when it mounts, updates it from its props and disposes of it when it unmounts.
wms-time-webgl.react.tsximport { useEffect, useMemo, useRef, useState } from 'react';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
TileWMSSource,
View,
XYZSource,
} from 'cc-openlayers/react';
import { WebGLTileLayer } from 'cc-openlayers/react/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.
*/
export function WmsTimeWebgl() {
const [wmsTime, setWmsTime] = useState(START);
const animationId = useRef<ReturnType<typeof setInterval> | null>(null);
/** The time to the second, as GIBS takes it: without milliseconds. */
const time = new Date(wmsTime).toISOString().replace('.000Z', 'Z');
const params = useMemo(() => ({ LAYERS: 'IMERG_Precipitation_Rate_30min', TIME: time }), [time]);
const stop = () => {
if (animationId.current !== null) {
clearInterval(animationId.current);
animationId.current = null;
}
};
const play = () => {
stop();
animationId.current = setInterval(
() => setWmsTime((current) => (current + STEP < END ? current + STEP : START)),
1000 / FRAME_RATE
);
};
useEffect(() => stop, []);
return (
<>
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={6}>
<Coordinate x={19.9373} y={50.0617} srid="EPSG:4326" />
</View>
<WebGLTileLayer>
<XYZSource
url="https://tile.opentopomap.org/{z}/{x}/{y}.png"
maxZoom={17}
crossOrigin="anonymous"
attributions={TOPOGRAPHY}
/>
</WebGLTileLayer>
<WebGLTileLayer extent={EXTENT}>
<TileWMSSource
url="https://gibs.earthdata.nasa.gov/wms/epsg3857/best/wms.cgi"
params={params}
crossOrigin="anonymous"
attributions="Precipitation: NASA GIBS, GPM IMERG"
/>
</WebGLTileLayer>
</Map>
<div className="example-controls" role="group" aria-label="Animation controls">
<button id="play" type="button" onClick={play}>
Play
</button>
<button id="pause" type="button" onClick={stop}>
Pause
</button>
<span id="info">{time}</span>
</div>
</>
);
}wms-time-webgl.shared.tsimport { 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,
];How the React version works
NASA's half-hourly precipitation estimate from a WMS with a time dimension, animated 30 minutes every two seconds over a WebGL base map; Play and Pause control it.
What both versions share
OpenLayers renders the map and handles the interactions; the cc-openlayers/core layer gives both adapters the same view binding (MapViewBinding) and the same conversion of coordinates from EPSG:4326 to the map's projection. OpenLayers draws the tiles with WebGL; the style expressions run on the GPU in both versions. Both versions import the time range, the step, the pace and the extent from the example's .shared.ts file, so the logic exists once.
From Angular to React
| Angular | React |
|---|---|
<aol-layer-webgltile> with <aol-source-tilewms [params]> | <WebGLTileLayer> with <TileWMSSource params>, the params made in useMemo from the time |
a timer started by Play and cleared through DestroyRef | setInterval in a useRef, cleared on Pause and in a useEffect cleanup |
Who creates, updates and disposes
Map creates the ol/Map in useLayoutEffect and disposes of it on unmount; each layer, source and interaction component adds its object to the parent it gets from context and removes it in its effect's cleanup, as ngOnDestroy does in Angular.
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-tilewmsbindsTIME: time()inside[params]to requestIMERG_Precipitation_Rate_30minslices reactively.playruns a two-secondsetInterval(1000 / FRAME_RATE) advancingSTEP(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.
Related examples
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.