Tile and image services · Angular, React and OpenLayers
Animate a WMS by its time dimension
Animate half-hourly NASA GPM IMERG Storm Boris precipitation over southern Poland in OpenLayers by stepping the WMS TIME dimension parameter.

What this example shows
Over an OpenTopoMap relief backdrop showing the Sudetes and Carpathian mountain arc, NASA GIBS half-hourly satellite rain-rate estimates (GPM IMERG) from 14 September 2024—the peak of Storm Boris across Czechia and southern Poland—step forward in 30-minute increments.
Play and Pause controls below the map advance the UTC timestamp smoothly across all 48 half-hour slots of the day while keeping the previous frame visible until each new slice fades in.
When you need it
Meteorological radars, ocean-current models, air-quality forecasts and multi-temporal earth-observation archives publish one OGC WMS layer parameterised by a TIME dimension rather than thousands of separate layers.
Driving TIME reactively from an Angular signal or React state hook turns a standard tiled WMS layer into an interactive weather-radar player.
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.tsimport { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, signal } from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceTileWMSComponent,
SourceXYZComponent,
ViewComponent,
} from 'cc-openlayers';
import { transformExtent } from 'ol/proj';
import { ATTRIBUTION } from 'ol/source/OSM';
/** Storm Boris over southern Poland: the rain of 14 September 2024 (UTC). */
const start = Date.UTC(2024, 8, 14);
const end = Date.UTC(2024, 8, 15);
const step = 30 * 60 * 1000;
const frameRate = 0.5; // frames per second
const extent = transformExtent([12, 47, 26, 53], 'EPSG:4326', 'EPSG:3857');
/**
* A WMS with a time dimension, animated: NASA's half-hourly precipitation estimate (GPM IMERG) of 14 September 2024,
* when Storm Boris brought rain to southern Poland, over OpenTopoMap. Play steps the WMS `TIME` parameter by 30
* minutes every two seconds, through the day and again.
*/
@Component({
selector: 'app-wms-time',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
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-tile>
<aol-source-xyz url="https://tile.opentopomap.org/{z}/{x}/{y}.png" [maxZoom]="17" [attributions]="topography" />
</aol-layer-tile>
<aol-layer-tile [extent]="extent">
<aol-source-tilewms
url="https://gibs.earthdata.nasa.gov/wms/epsg3857/best/wms.cgi"
[params]="{ LAYERS: 'IMERG_Precipitation_Rate_30min', TIME: time() }"
attributions="Precipitation: NASA GIBS, GPM IMERG"
/>
</aol-layer-tile>
</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 WmsTime {
protected readonly extent = extent;
protected readonly 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,
];
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 / frameRate);
}
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.react.tsximport { useEffect, useMemo, useRef, useState } from 'react';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
TileLayer,
TileWMSSource,
View,
XYZSource,
} from 'cc-openlayers/react';
import { transformExtent } from 'ol/proj.js';
import { ATTRIBUTION } from 'ol/source/OSM.js';
/** Storm Boris over southern Poland: the rain of 14 September 2024 (UTC). */
const start = Date.UTC(2024, 8, 14);
const end = Date.UTC(2024, 8, 15);
const step = 30 * 60 * 1000;
const frameRate = 0.5; // frames per second
const extent = transformExtent([12, 47, 26, 53], 'EPSG:4326', 'EPSG:3857');
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,
];
/**
* A WMS with a time dimension, animated: NASA's half-hourly precipitation estimate (GPM IMERG) of 14 September 2024,
* when Storm Boris brought rain to southern Poland, over OpenTopoMap. Play steps the WMS `TIME` parameter by 30
* minutes every two seconds, through the day and again.
*/
export function WmsTime() {
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 / frameRate
);
};
useEffect(() => stop, []);
return (
<>
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={6}>
<Coordinate x={19.9373} y={50.0617} srid="EPSG:4326" />
</View>
<TileLayer>
<XYZSource url="https://tile.opentopomap.org/{z}/{x}/{y}.png" maxZoom={17} attributions={topography} />
</TileLayer>
<TileLayer extent={extent}>
<TileWMSSource
url="https://gibs.earthdata.nasa.gov/wms/epsg3857/best/wms.cgi"
params={params}
attributions="Precipitation: NASA GIBS, GPM IMERG"
/>
</TileLayer>
</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>
</>
);
}How the React version works
Rainfall from storm Boris on 14 September 2024 (NASA GIBS) over OpenTopoMap: “Play” moves the TIME parameter by 30 minutes every two seconds, round the clock in a loop.
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. The time steps and the format without milliseconds are the same in both versions.
From Angular to React
| Angular | React |
|---|---|
setInterval in a class field and DestroyRef.onDestroy(() => stop()) | useRef with the id and useEffect(() => stop, []) |
a signal with the time and a computed of the parameters | useState and useMemo for params |
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
Binding TIME inside [params] on the tiled WMS source pushes updated ISO-8601 timestamps (formatted to whole seconds via toISOString without milliseconds, as NASA GIBS expects) through the wrapper’s params replacement, which calls setParams on the source.
Every two seconds during playback, the timer advances the signal by 30 minutes from 00:00 to 23:30 UTC and loops; OpenLayers retains the previous timestamp’s tiles on screen while the next timestamp’s tiles download and cross-fade.
How it works
- Binding
TIMEinside[params]updates the WMS tile source reactively whenever the active timestamp signal advances. - Play steps forward by 30 minutes every two seconds across 14 September 2024 (00:00–23:30 UTC), while Pause halts the interval cleanly.
- Retaining outgoing tiles until replacement tiles finish loading prevents blank flashes between weather frames.
- Timestamps strip milliseconds from
toISOStringto match NASA GIBS’s strict ISO-8601 YYYY-MM-DDTHH:mm:ssZ format.
Pitfalls
- WMS servers validate
TIMEagainst the intervals advertised in GetCapabilities—sending unsupported timestamps or unstripped.000Zmilliseconds can return OGC InvalidDimensionValue XML errors. - Advancing the animation timer faster than the server and network can deliver a viewport of tiles leaves intermediate frames partially loaded—size your step interval to realistic network latency or pre-warm frames.
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.