Vector data · Angular, React and OpenLayers
Flight tracks from IGC
Replay multi-pilot IGC flight logs in OpenLayers using M-coordinate timestamps, getCoordinateAtM time scrubbing and nearest-track snapping.

What this example shows
North of Kraków’s Old Town over OpenStreetMap, three recorded glider/paraglider IGC flight tracks appear in distinct shades of blue. Moving the pointer snaps a red indicator line to the closest point on the nearest flight path—reporting the pilot’s name and the interpolated time at the closest point—while dragging the time slider moves red aircraft markers synchronously along all three trajectories.
When you need it
Soaring competitions, drone-flight debriefings, maritime race replays and multi-vehicle telemetry tools analyse International Gliding Commission (.igc) or time-stamped GPS logs to see where multiple craft were at the exact same second.
Encoding fix timestamps directly inside OpenLayers’ fourth geometry ordinate (M) enables instant linear time interpolation without external array binary searches.
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.
igc.tsimport { ChangeDetectionStrategy, Component, signal, viewChild } from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
} from 'cc-openlayers';
import Feature, { type FeatureLike } from 'ol/Feature';
import type MapBrowserEvent from 'ol/MapBrowserEvent';
import IGC from 'ol/format/IGC';
import LineString from 'ol/geom/LineString';
import Point from 'ol/geom/Point';
import type { FeatureLoader } from 'ol/featureloader';
import { getVectorContext } from 'ol/render';
import type RenderEvent from 'ol/render/Event';
import CircleStyle from 'ol/style/Circle';
import Fill from 'ol/style/Fill';
import Stroke from 'ol/style/Stroke';
import Style from 'ol/style/Style';
const FLIGHTS = [
'assets/samples/sample-flight-a.igc',
'assets/samples/sample-flight-b.igc',
'assets/samples/sample-flight-c.igc',
];
const COLORS: Record<string, string> = {
'Sample pilot A': 'rgba(0, 0, 255, 0.7)',
'Sample pilot B': 'rgba(0, 165, 255, 0.7)',
'Sample pilot C': 'rgba(0, 255, 255, 0.7)',
};
const styleCache: Record<string, Style> = {};
const snapStroke = new Stroke({ color: 'rgba(255,0,0,0.9)', width: 1 });
const snapStyle = new Style({
stroke: snapStroke,
image: new CircleStyle({ radius: 5, fill: undefined, stroke: snapStroke }),
});
/** The closest point of a flight and the line to it from the pointer, drawn over the tracks. */
interface Snap {
point: Point;
line: LineString;
}
/**
* Three sample flights over the north of Kraków read from IGC files: the pointer snaps to the closest track and a
* slider moves a marker along each flight.
*/
@Component({
selector: 'app-igc',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px" (pointerMove)="snap($event)" (olClick)="snap($event)">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="12"><aol-coordinate [x]="19.9182" [y]="50.1011" srid="EPSG:4326" /></aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-vector [style]="trackStyle" [postrender]="drawSnap">
<aol-source-vector #tracks [loader]="load" />
</aol-layer-vector>
<aol-layer-vector [style]="markerStyle"><aol-source-vector #markers /></aol-layer-vector>
</aol-map>
<div class="example-controls">
<label> Time <input type="range" min="0" max="100" value="0" (input)="move(number($event))" /> </label>
<span>
Closest flight <output>{{ info() }}</output>
</span>
</div>
`,
})
export class Igc {
readonly info = signal('–');
protected readonly snapped = signal<Snap | null>(null);
protected readonly trackStyle = (feature: FeatureLike): Style => {
const color = COLORS[feature.get('PLT')];
return (styleCache[color] ??= new Style({ stroke: new Stroke({ color, width: 3 }) }));
};
protected readonly markerStyle = new Style({
image: new CircleStyle({ radius: 5, fill: new Fill({ color: 'rgba(255,0,0,0.9)' }) }),
});
/** Reads the three flight files; the source adds the features the promise resolves to. */
protected readonly load: FeatureLoader<Feature> = async (_extent, _resolution, projection) => {
const format = new IGC();
const texts = await Promise.all(FLIGHTS.map(async (url) => (await fetch(url)).text()));
return texts.flatMap((text) => format.readFeatures(text, { featureProjection: projection }));
};
protected readonly drawSnap = (event: RenderEvent): void => {
const snap = this.snapped();
if (!snap) return;
const context = getVectorContext(event);
context.setStyle(snapStyle);
context.drawGeometry(snap.point);
context.drawGeometry(snap.line);
};
private readonly map = viewChild.required(MapComponent);
private readonly tracks = viewChild.required<SourceVectorComponent>('tracks');
private readonly markers = viewChild.required<SourceVectorComponent>('markers');
protected number(event: Event): number {
return (event.target as HTMLInputElement).valueAsNumber;
}
protected snap(event: MapBrowserEvent): void {
if (event.dragging) return;
const source = this.tracks().instance;
const closest = source.getClosestFeatureToCoordinate(event.coordinate);
if (!closest) {
this.snapped.set(null);
this.info.set('–');
} else {
const closestPoint = (closest.getGeometry() as LineString).getClosestPoint(event.coordinate);
this.snapped.set({
point: new Point(closestPoint),
line: new LineString([event.coordinate, [closestPoint[0], closestPoint[1]]]),
});
this.info.set(`${closest.get('PLT')} (${new Date(closestPoint[2] * 1000).toUTCString()})`);
}
this.map().instance.render();
}
/** Puts a marker on every flight at `percent` of the time from the first take-off to the last landing. */
protected move(percent: number): void {
const flights = this.tracks().instance.getFeatures();
const lines = flights.map((flight) => flight.getGeometry() as LineString);
const start = Math.min(...lines.map((line) => line.getFirstCoordinate()[2]));
const stop = Math.max(...lines.map((line) => line.getLastCoordinate()[2]));
const moment = start + ((stop - start) * percent) / 100;
const overlay = this.markers().instance;
flights.forEach((flight, index) => {
const coordinate = lines[index].getCoordinateAtM(moment, true);
const marker = flight.get('highlight') as Feature<Point> | undefined;
if (marker) {
marker.getGeometry()?.setCoordinates(coordinate);
} else {
const created = new Feature(new Point(coordinate));
flight.set('highlight', created);
overlay.addFeature(created);
}
});
this.map().instance.render();
}
} 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.
igc.react.tsximport { useCallback, useRef, useState } from 'react';
import type { Coordinate as OLCoordinate } from 'ol/coordinate.js';
import Feature, { type FeatureLike } from 'ol/Feature.js';
import type OLMap from 'ol/Map.js';
import type MapBrowserEvent from 'ol/MapBrowserEvent.js';
import IGC from 'ol/format/IGC.js';
import LineString from 'ol/geom/LineString.js';
import Point from 'ol/geom/Point.js';
import type { FeatureLoader } from 'ol/featureloader.js';
import { getVectorContext } from 'ol/render.js';
import type RenderEvent from 'ol/render/Event.js';
import type OLVectorSource from 'ol/source/Vector.js';
import CircleStyle from 'ol/style/Circle.js';
import Fill from 'ol/style/Fill.js';
import Stroke from 'ol/style/Stroke.js';
import Style from 'ol/style/Style.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
const FLIGHTS = [
'assets/samples/sample-flight-a.igc',
'assets/samples/sample-flight-b.igc',
'assets/samples/sample-flight-c.igc',
];
const COLORS: Record<string, string> = {
'Sample pilot A': 'rgba(0, 0, 255, 0.7)',
'Sample pilot B': 'rgba(0, 165, 255, 0.7)',
'Sample pilot C': 'rgba(0, 255, 255, 0.7)',
};
const styleCache: Record<string, Style> = {};
const snapStroke = new Stroke({ color: 'rgba(255,0,0,0.9)', width: 1 });
const snapStyle = new Style({
stroke: snapStroke,
image: new CircleStyle({ radius: 5, fill: undefined, stroke: snapStroke }),
});
/** The closest point of a flight and the line to it from the pointer, drawn over the tracks. */
interface Snap {
point: Point;
line: LineString;
}
const trackStyle = (feature: FeatureLike): Style => {
const color = COLORS[feature.get('PLT')];
return (styleCache[color] ??= new Style({ stroke: new Stroke({ color, width: 3 }) }));
};
const markerStyle = new Style({
image: new CircleStyle({ radius: 5, fill: new Fill({ color: 'rgba(255,0,0,0.9)' }) }),
});
/** Reads the three flight files; the source adds the features the promise resolves to. */
const load: FeatureLoader<Feature> = async (_extent, _resolution, projection) => {
const format = new IGC();
const texts = await Promise.all(FLIGHTS.map(async (url) => (await fetch(url)).text()));
return texts.flatMap((text) => format.readFeatures(text, { featureProjection: projection }));
};
/**
* Three sample flights over the north of Kraków read from IGC files: the pointer snaps to the closest track and a
* slider moves a marker along each flight.
*/
export function Igc() {
const [info, setInfo] = useState('–');
const snapped = useRef<Snap | null>(null);
const map = useRef<OLMap>(null);
const tracks = useRef<OLVectorSource>(null);
const markers = useRef<OLVectorSource>(null);
const drawSnap = useCallback((event: RenderEvent): void => {
const snap = snapped.current;
if (!snap) return;
const context = getVectorContext(event);
context.setStyle(snapStyle);
context.drawGeometry(snap.point);
context.drawGeometry(snap.line);
}, []);
const snap = (event: MapBrowserEvent): void => {
if (event.dragging) return;
const source = tracks.current;
const closest = source?.getClosestFeatureToCoordinate(event.coordinate);
if (!closest) {
snapped.current = null;
setInfo('–');
} else {
const closestPoint = (closest.getGeometry() as LineString).getClosestPoint(event.coordinate);
snapped.current = {
point: new Point(closestPoint),
line: new LineString([event.coordinate, [closestPoint[0], closestPoint[1]]]),
};
setInfo(`${closest.get('PLT')} (${new Date(closestPoint[2] * 1000).toUTCString()})`);
}
map.current?.render();
};
/** Puts a marker on every flight at `percent` of the time from the first take-off to the last landing. */
const move = (percent: number): void => {
const flights = tracks.current?.getFeatures() ?? [];
const lines = flights.map((flight) => flight.getGeometry() as LineString);
const start = Math.min(...lines.map((line) => line.getFirstCoordinate()[2]));
const stop = Math.max(...lines.map((line) => line.getLastCoordinate()[2]));
const moment = start + ((stop - start) * percent) / 100;
const overlay = markers.current;
flights.forEach((flight, index) => {
const coordinate = lines[index].getCoordinateAtM(moment, true) as OLCoordinate;
const marker = flight.get('highlight') as Feature<Point> | undefined;
if (marker) {
marker.getGeometry()?.setCoordinates(coordinate);
} else {
const created = new Feature(new Point(coordinate));
flight.set('highlight', created);
overlay?.addFeature(created);
}
});
map.current?.render();
};
return (
<>
<Map ref={map} height="480px" onPointerMove={snap} onClick={snap}>
<DefaultInteractions />
<DefaultControls />
<View zoom={12}>
<Coordinate x={19.9182} y={50.1011} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<VectorLayer style={trackStyle} onPostRender={drawSnap}>
<VectorSource ref={tracks} loader={load} />
</VectorLayer>
<VectorLayer style={markerStyle}>
<VectorSource ref={markers} />
</VectorLayer>
</Map>
<div className="example-controls">
<label>
{' '}
Time{' '}
<input
type="range"
min="0"
max="100"
defaultValue="0"
onInput={(event) => move(event.currentTarget.valueAsNumber)}
/>{' '}
</label>
<span>
Closest flight <output>{info}</output>
</span>
</div>
</>
);
}How the React version works
Three IGC flights north of the Old Town: the cursor snaps to the nearest flight and shows its pilot and time, and a slider moves markers along the flights' time.
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.
From Angular to React
| Angular | React |
|---|---|
| a source loader that reads the three files | <VectorSource loader={load}> with a module function |
the slider's (input) | onInput and useState |
(postrender) drawing the snapped point | onPostRender with the snap in a useRef, because it is only drawn |
(pointerMove) and viewChild of the map | onPointerMove (and onClick) on Map with useRef<OLMap>; the reading in useState |
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
An asynchronous source loader fetches all three .igc files in parallel. OpenLayers’ IGC parser stores each fix’s UTC epoch seconds inside the line’s M coordinate and extracts the header’s pilot name into the PLT property used for colour coding.
On pointer motion, getClosestFeatureToCoordinate and getClosestPoint locate the closest point on the nearest track, interpolating its time—drawing a transient snap vector in postrender via getVectorContext and render()—while scrubbing the time slider calls getCoordinateAtM(moment, true) to interpolate each flight’s position clamped cleanly between take-off and landing.
How it works
- A custom promise-based loader fetches all three IGC logs and adds the decoded flight features to the vector source.
IGCstores fix timestamps (seconds) in the line’s M ordinate and exposes the header pilot name underPLTfor per-pilot styling.getClosestFeatureToCoordinateandgetClosestPointresolve the nearest trajectory point and read back its M timestamp under the cursor.getCoordinateAtM(moment, true)interpolates each aircraft marker along its track for the slider’s timestamp, clamping before take-off and after landing.- Transient snap lines paint cleanly inside
postrenderusinggetVectorContexttriggered byrender().
Pitfalls
- By default
new IGC()omits Z altitude coordinates (XYM layout); pass an explicit altitudeMode (barometric or gps) if your analysis also needs elevation profiles in XYZ / XYZM. getClosestFeatureToCoordinatesearches across the entire source without a maximum radius—add a pixel distance check if you only want snapping when the cursor is close to a track.
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.