Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
Flight tracks shown up to a time
Trim and colour IGC glider flight tracks dynamically by time on the GPU in OpenLayers WebGLVectorLayer using interpolated line-metric M values.

What this example shows
Over north-western Kraków around Bronowice and Prądnik Biały at zoom 12, three glider trajectories loaded from IGC logs transition smoothly in colour from purple at take-off (START) to orange at landing (END).
Dragging the Current time shown slider trims all three tracks simultaneously on the GPU—displaying strictly the flight path completed up to the selected UTC timestamp without mutating a single feature geometry.
When you need it
Aviation replay tools, fleet route scrubbers, marathon trackers and storm-track visualisers need users to scrub a timeline back and forth across multi-hour trajectories at 60 fps.
Evaluating ['line-metric'] inside a WebGL fragment shader clips and colours polylines continuously along each segment without slicing LineString geometries on the CPU.
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.
filter-webgl-line.shared.tsimport type Feature from 'ol/Feature.js';
import IGC from 'ol/format/IGC.js';
import type { Rule } from 'ol/style/flat.js';
/** The sample IGC files of the three flights. */
export const IGC_URLS = [
'assets/samples/sample-flight-a.igc',
'assets/samples/sample-flight-b.igc',
'assets/samples/sample-flight-c.igc',
];
/** The first fix of the flights, in seconds since 1970. */
export const START = 1789898700;
/** The last fix of the flights, in seconds since 1970. */
export const END = 1789903790;
/** The rule that colours the tracks by their time and draws only the part up to the style variable `timestamp`. */
export const FLIGHT_STYLE: Rule[] = [
{
style: {
'stroke-width': 4,
'stroke-color': ['interpolate', ['linear'], ['line-metric'], START, 'hsl(312,100%,39%)', END, 'hsl(36,100%,45%)'],
},
filter: ['<=', ['line-metric'], ['var', 'timestamp']],
},
];
/**
* Fetches the flights and hands each one's features to `add`, unless `isCurrent` says the example went away in the
* meantime; a flight that cannot be loaded is logged.
*/
export function loadFlights(isCurrent: () => boolean, add: (features: Feature[]) => void): void {
const format = new IGC();
for (const url of IGC_URLS) {
fetch(url)
.then((resp) => resp.text())
.then((data) => {
if (!isCurrent()) return;
add(format.readFeatures(data, { featureProjection: 'EPSG:3857' }));
})
.catch((error) => console.error('The flight could not be loaded', error));
}
}filter-webgl-line.tsimport {
afterNextRender,
ChangeDetectionStrategy,
Component,
computed,
DestroyRef,
inject,
signal,
viewChild,
} from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
} from 'cc-openlayers';
import { LayerWebGLVectorComponent } from 'cc-openlayers/webgl';
import { END, FLIGHT_STYLE, loadFlights, START } from './filter-webgl-line.shared';
/**
* Three sample glider flights over Kraków drawn by a WebGL vector layer: IGC keeps each fix's time as the measure (M)
* of the track's XYM coordinates, `['line-metric']` colours the tracks by it, and a filter on the slider's time shows
* how far each flight had come.
*/
@Component({
selector: 'app-filter-webgl-line',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerWebGLVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="12">
<aol-coordinate [x]="19.92" [y]="50.1" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-webglvector [style]="style" [variables]="{ timestamp: timestamp() }">
<aol-source-vector />
</aol-layer-webglvector>
</aol-map>
<div class="example-controls">
<label>
Current time shown:
<input
name="maxT"
type="range"
[min]="start"
[max]="end"
[value]="timestamp()"
(input)="timestamp.set(read($event))"
/>
<output>{{ time() }}</output>
</label>
</div>
`,
})
export class FilterWebglLine {
readonly timestamp = signal(END);
protected readonly time = computed(() => new Date(this.timestamp() * 1000).toUTCString());
protected readonly start = START;
protected readonly end = END;
protected readonly style = FLIGHT_STYLE;
private readonly source = viewChild.required(SourceVectorComponent);
constructor() {
let destroyed = false;
inject(DestroyRef).onDestroy(() => (destroyed = true));
afterNextRender(() =>
loadFlights(
() => !destroyed,
(features) => this.source().instance.addFeatures(features)
)
);
}
protected read(event: Event): number {
return parseFloat((event.target as HTMLInputElement).value);
}
} 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.
filter-webgl-line.react.tsximport { useEffect, useState, type ChangeEvent } from 'react';
import type OLVectorSource from 'ol/source/Vector.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
TileLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
import { WebGLVectorLayer } from 'cc-openlayers/react/webgl';
import { END, FLIGHT_STYLE, loadFlights, START } from './filter-webgl-line.shared';
/**
* Three sample glider flights over Kraków drawn by a WebGL vector layer: IGC keeps each fix's time as the measure (M)
* of the track's XYM coordinates, `['line-metric']` colours the tracks by it, and a filter on the slider's time shows
* how far each flight had come.
*/
export function FilterWebglLine() {
const [timestamp, setTimestamp] = useState(END);
const time = new Date(timestamp * 1000).toUTCString();
// The source is made after the first commit, so the state carries it to the effect that loads the data.
const [source, setSource] = useState<OLVectorSource | null>(null);
useEffect(() => {
if (!source) return;
let current = true;
loadFlights(
() => current,
(features) => source.addFeatures(features)
);
return () => {
current = false;
};
}, [source]);
const read = (event: ChangeEvent<HTMLInputElement>) => setTimestamp(parseFloat(event.target.value));
return (
<>
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={12}>
<Coordinate x={19.92} y={50.1} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<WebGLVectorLayer style={FLIGHT_STYLE} variables={{ timestamp }}>
<VectorSource ref={setSource} />
</WebGLVectorLayer>
</Map>
<div className="example-controls">
<label>
Current time shown:
<input name="maxT" type="range" min={START} max={END} value={timestamp} onChange={read} />
<output>{time}</output>
</label>
</div>
</>
);
}filter-webgl-line.shared.tsimport type Feature from 'ol/Feature.js';
import IGC from 'ol/format/IGC.js';
import type { Rule } from 'ol/style/flat.js';
/** The sample IGC files of the three flights. */
export const IGC_URLS = [
'assets/samples/sample-flight-a.igc',
'assets/samples/sample-flight-b.igc',
'assets/samples/sample-flight-c.igc',
];
/** The first fix of the flights, in seconds since 1970. */
export const START = 1789898700;
/** The last fix of the flights, in seconds since 1970. */
export const END = 1789903790;
/** The rule that colours the tracks by their time and draws only the part up to the style variable `timestamp`. */
export const FLIGHT_STYLE: Rule[] = [
{
style: {
'stroke-width': 4,
'stroke-color': ['interpolate', ['linear'], ['line-metric'], START, 'hsl(312,100%,39%)', END, 'hsl(36,100%,45%)'],
},
filter: ['<=', ['line-metric'], ['var', 'timestamp']],
},
];
/**
* Fetches the flights and hands each one's features to `add`, unless `isCurrent` says the example went away in the
* meantime; a flight that cannot be loaded is logged.
*/
export function loadFlights(isCurrent: () => boolean, add: (features: Feature[]) => void): void {
const format = new IGC();
for (const url of IGC_URLS) {
fetch(url)
.then((resp) => resp.text())
.then((data) => {
if (!isCurrent()) return;
add(format.readFeatures(data, { featureProjection: 'EPSG:3857' }));
})
.catch((error) => console.error('The flight could not be loaded', error));
}
}How the React version works
Three glider flights over Kraków drawn by a WebGL vector layer that keeps each fix's time as the measure; a slider draws the tracks only up to the chosen 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. OpenLayers draws the tiles with WebGL; the style expressions run on the GPU in both versions. Both versions import the flight files, the time range, the style and loadFlights, which reads the files and reports a failed load, from the example's .shared.ts file, so the logic exists once.
From Angular to React
| Angular | React |
|---|---|
loading the IGC files into viewChild of the source | ref={setSource} into useState and a useEffect that fetches the files with a flag that drops the answers after unmount |
the slider and the timestamp variable | useState and variables on the layer |
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
new IGC() parses the three logs with featureProjection: 'EPSG:3857', storing each GPS fix’s Unix timestamp (seconds since 1970) in the M ordinate of an XYM line. In the WebGL flat style, stroke-color interpolates ['line-metric'] from START to END, while filter ['<=', ['line-metric'], ['var', 'timestamp']] discards pixels ahead of [variables]="{ timestamp: timestamp() }" (initialised to END).
How it works
new IGC()decodes three tracks intofeatureProjection: 'EPSG:3857'with Unix epoch seconds stored in each vertex’sMcoordinate.stroke-colorinterpolates['line-metric']along segments from purple atSTARTto orange atEND.- Fragment filter
['<=', ['line-metric'], ['var', 'timestamp']]clips each trajectory cleanly at the slider’s time. [variables]="{ timestamp: timestamp() }"starts atENDso the complete flights are visible initially.
Pitfalls
- GPUs store vertex attributes as 32-bit IEEE-754 floats (24-bit mantissa): raw Unix timestamps around 1.79 × 10^9 seconds only resolve multiples of 128 seconds (~2-minute steps)—subtract a reference start epoch from
Mbefore uploading if your production replay needs 1-second precision! - Because
['line-metric']filters evaluate per pixel in the fragment shader rather than per vertex, tracks clip smoothly mid-segment between GPS fixes.
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.