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.

OpenStreetMap of north-western Kraków with three glider tracks circling over Bronowice and Prądnik Biały in purple to red, cut at 10:47:25 GMT on 20 September 2026 by the slider below.
A screenshot of the example. Flights: three synthetic sample tracks. Map data © OpenStreetMap contributors.

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

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 into featureProjection: 'EPSG:3857' with Unix epoch seconds stored in each vertex’s M coordinate.
  • stroke-color interpolates ['line-metric'] along segments from purple at START to orange at END.
  • Fragment filter ['<=', ['line-metric'], ['var', 'timestamp']] clips each trajectory cleanly at the slider’s time.
  • [variables]="{ timestamp: timestamp() }" starts at END so 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 M before 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.

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.