Overlays and animation · Angular, React and OpenLayers
Animate illustrative flight routes
Animate great-circle flight arcs from Kraków in OpenLayers with the arc library, using shared animation helpers behind Start, Pause and Restart buttons.

What this example shows
Over OpenStreetMap zoomed to Kraków, four great-circle arcs radiate from the Main Market Square toward destinations across the city, each growing progressively as Start, Pause and Restart—page buttons shared by both implementations—drive the animation.
When you need it
Airline route maps, logistics export visualisers, telecommunications backbone diagrams and migration story maps illustrate origin-destination connections through progressively animated great-circle arcs.
Generating spherical great-circle vertices client-side produces realistic curved paths on Web Mercator without querying an external aviation feed.
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.
flight-animation.html<aol-map height="480px" (postRender)="animate($event)"
><aol-control-defaults /><aol-interaction-default /><aol-view [zoom]="13" [maxZoom]="19"
><aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" /></aol-view
><aol-layer-tile><aol-source-osm /></aol-layer-tile
></aol-map>
<div class="example-controls">
<button type="button" (click)="start()" [disabled]="playing()">Start animation</button
><button type="button" (click)="pause()" [disabled]="!playing()">Pause</button
><button type="button" (click)="restart()">Restart</button>
<p class="example-hint">Illustrative routes from Kraków; not live flight data.</p>
</div>flight-animation.shared.tsimport { GreatCircle } from 'arc';
import Feature from 'ol/Feature';
import LineString from 'ol/geom/LineString';
export const DESTINATIONS = [
[19.88, 50.085],
[20.02, 50.075],
[19.99, 50.03],
[19.91, 50.025],
];
export function flightPaths(from: number[], to: number[]): Feature<LineString>[] {
return new GreatCircle({ x: from[0], y: from[1] }, { x: to[0], y: to[1] })
.Arc(100, { offset: 10 })
.geometries.map((section) => {
const full = new LineString(section.coords).transform('EPSG:4326', 'EPSG:3857').getCoordinates();
const f = new Feature(new LineString([]));
f.set('route', full);
return f;
});
}
export function advanceFlight(feature: Feature<LineString>, elapsed: number): boolean {
const route = feature.get('route') as number[][];
const count = Math.min(route.length, Math.max(0, Math.floor(elapsed * 0.02)));
feature.getGeometry()?.setCoordinates(route.slice(0, count));
return count < route.length;
}
export function demoFlights() {
return DESTINATIONS.flatMap((to) => flightPaths([19.9368, 50.0614], to));
}flight-animation.tsimport { AfterViewInit, ChangeDetectionStrategy, Component, OnDestroy, signal, viewChild } from '@angular/core';
import {
MapComponent,
ViewComponent,
CoordinateComponent,
LayerTileComponent,
SourceOsmComponent,
DefaultControlComponent,
DefaultInteractionComponent,
} from 'cc-openlayers';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import Style from 'ol/style/Style';
import Stroke from 'ol/style/Stroke';
import type MapEvent from 'ol/MapEvent';
import { demoFlights, advanceFlight } from './flight-animation.shared';
@Component({
selector: 'app-flight-animation',
imports: [
MapComponent,
ViewComponent,
CoordinateComponent,
LayerTileComponent,
SourceOsmComponent,
DefaultControlComponent,
DefaultInteractionComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './flight-animation.html',
})
export class FlightAnimation implements AfterViewInit, OnDestroy {
private readonly map = viewChild.required(MapComponent);
private readonly features = demoFlights();
private readonly source = new VectorSource({ features: this.features });
private cleanup = () => {};
private started: number | null = null;
private elapsed = 0;
readonly playing = signal(false);
ngAfterViewInit(): void {
const map = this.map().instance,
layer = new VectorLayer({
source: this.source,
style: new Style({ stroke: new Stroke({ color: '#e9d51b', width: 3 }) }),
});
this.features.forEach((f) => advanceFlight(f, Infinity));
map.addLayer(layer);
this.cleanup = () => {
this.started = null;
map.removeLayer(layer);
};
}
ngOnDestroy(): void {
this.cleanup();
}
start(): void {
if (this.started !== null) return;
this.started = Date.now() - this.elapsed;
this.playing.set(true);
this.map().instance.render();
}
pause(): void {
if (this.started !== null) this.elapsed = Date.now() - this.started;
this.started = null;
this.playing.set(false);
}
restart(): void {
this.elapsed = 0;
this.started = null;
this.features.forEach((f) => advanceFlight(f, 0));
this.start();
}
animate(event: MapEvent): void {
if (this.started === null) return;
const elapsed = (event.frameState?.time ?? Date.now()) - this.started;
const active = this.features.map((f, i) => advanceFlight(f, elapsed - i * 150)).some(Boolean);
if (active) event.map.render();
else {
this.started = null;
this.elapsed = 0;
this.playing.set(false);
}
}
} 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.
flight-animation.react.tsximport { useEffect, useRef, useState } from 'react';
import { Map, View, Coordinate, TileLayer, OSMSource, DefaultControls, DefaultInteractions } from 'cc-openlayers/react';
import type OLMap from 'ol/Map';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import Style from 'ol/style/Style';
import Stroke from 'ol/style/Stroke';
import type MapEvent from 'ol/MapEvent';
import { demoFlights, advanceFlight } from './flight-animation.shared';
export function FlightAnimation() {
const [map, setMap] = useState<OLMap | null>(null);
const [features] = useState(demoFlights);
const [source] = useState(() => new VectorSource({ features }));
const clock = useRef({ started: null as number | null, elapsed: 0 });
const [playing, setPlaying] = useState(false);
useEffect(() => {
if (!map) return;
const animationClock = clock.current;
const layer = new VectorLayer({ source, style: new Style({ stroke: new Stroke({ color: '#e9d51b', width: 3 }) }) });
features.forEach((f) => advanceFlight(f, Infinity));
map.addLayer(layer);
return () => {
animationClock.started = null;
map.removeLayer(layer);
};
}, [map, features, source]);
function start() {
if (clock.current.started !== null) return;
clock.current.started = Date.now() - clock.current.elapsed;
setPlaying(true);
map?.render();
}
function animate(event: MapEvent) {
if (clock.current.started === null) return;
const elapsed = (event.frameState?.time ?? Date.now()) - clock.current.started;
const active = features.map((f, i) => advanceFlight(f, elapsed - i * 150)).some(Boolean);
if (active) event.map.render();
else {
clock.current.started = null;
clock.current.elapsed = 0;
setPlaying(false);
}
}
return (
<>
<Map ref={setMap} height="480px" onPostRender={animate}>
<DefaultControls />
<DefaultInteractions />
<View zoom={13} maxZoom={19}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
</Map>
<div className="example-controls">
<button type="button" onClick={start} disabled={playing}>
Start animation
</button>
<button
type="button"
disabled={!playing}
onClick={() => {
if (clock.current.started !== null) clock.current.elapsed = Date.now() - clock.current.started;
clock.current.started = null;
setPlaying(false);
}}
>
Pause
</button>
<button
type="button"
onClick={() => {
clock.current.elapsed = 0;
clock.current.started = null;
features.forEach((f) => advanceFlight(f, 0));
start();
}}
>
Restart
</button>
<p className="example-hint">Illustrative routes from Kraków; not live flight data.</p>
</div>
</>
);
}flight-animation.shared.tsimport { GreatCircle } from 'arc';
import Feature from 'ol/Feature';
import LineString from 'ol/geom/LineString';
export const DESTINATIONS = [
[19.88, 50.085],
[20.02, 50.075],
[19.99, 50.03],
[19.91, 50.025],
];
export function flightPaths(from: number[], to: number[]): Feature<LineString>[] {
return new GreatCircle({ x: from[0], y: from[1] }, { x: to[0], y: to[1] })
.Arc(100, { offset: 10 })
.geometries.map((section) => {
const full = new LineString(section.coords).transform('EPSG:4326', 'EPSG:3857').getCoordinates();
const f = new Feature(new LineString([]));
f.set('route', full);
return f;
});
}
export function advanceFlight(feature: Feature<LineString>, elapsed: number): boolean {
const route = feature.get('route') as number[][];
const count = Math.min(route.length, Math.max(0, Math.floor(elapsed * 0.02)));
feature.getGeometry()?.setCoordinates(route.slice(0, count));
return count < route.length;
}
export function demoFlights() {
return DESTINATIONS.flatMap((to) => flightPaths([19.9368, 50.0614], to));
}How the React version works
Animate great-circle routes starting in Kraków with controls to start, pause and restart.
What both versions share
arc constructs the great-circle lines. The animation advances through their coordinates and requests new map frames.
From Angular to React
| Angular | React |
|---|---|
| Lifecycle hooks bind a map and the buttons call the animation controller. | An effect binds the map and button handlers call the same controller. |
| An external Angular template declares the example. | JSX declares the example and its controls. |
| The Angular lifecycle releases the mounted resources. | Effect or subscription cleanup releases the mounted resources. |
Who creates, updates and disposes
The shared controller draws progressive great-circle routes. Cleanup removes its listener and layers, stopping further animation work.
Architecture and OpenLayers mechanics
The shared helper builds one great-circle arc per destination with the arc library from the Main Market Square coordinate, then playback updates each LineString feature in place with setCoordinates(route.slice(0, count)) on a vector layer, advancing the count per frame and stopping on pause, restart or unmount.
How it works
- Great-circle coordinate paths are generated with arc, advancing progressively per animation frame under Start, Pause and Restart controls.
Pitfalls
- Routes and travel speeds in this example are illustrative geometric demonstrations rather than real commercial airline timetables or live ADS-B flight telemetry.
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.