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.

Animate great-circle routes starting in Kraków with controls to start, pause and restart.
A screenshot of the example. Map data © OpenStreetMap contributors.

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.ts
import { 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.ts
import { 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);
    }
  }
}

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.

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.