Raster, GeoTIFF and WebGL · Angular, React and OpenLayers

Tremors filtered by year on the GPU

Filter 1,130 pulsing seismic points by year range live on the GPU in OpenLayers using WebGL style variables and between filter expressions.

Esri's light grey map of southern Poland with tremors as pulsing yellow and orange circles, densest over Upper Silesia and Karviná, and the year sliders below.
A screenshot of the example. Seismic events: U.S. Geological Survey. Base map: Esri World Light Gray (Esri, HERE, Garmin, OpenStreetMap contributors and the GIS user community).

What this example shows

Over Esri’s World Light Gray basemap across Upper Silesia, Kraków and Karviná, 1,130 seismic events loaded from assets/krakow/tremors.csv pulse out of phase as magnitude-sized yellow-to-red circles while two range sliders (minYear and maxYear) filter visible decades instantaneously at 60 fps.

When you need it

Historical incident explorers, real-estate transaction maps, epidemiological timelines and crime atlases let analysts scrub start-and-end date sliders across tens of thousands of points.

Evaluating between filters in the WebGL vertex shader via uniform variables hides and reveals thousands of points per millisecond without touching the JavaScript feature array.

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-points-webgl.shared.ts
import Feature from 'ol/Feature.js';
import Point from 'ol/geom/Point.js';
import { fromLonLat } from 'ol/proj.js';
import type { ExpressionValue } from 'ol/expr/expression.js';
import type { FlatStyle, Rule } from 'ol/style/flat.js';

const oldColor = 'rgba(242,56,22,0.61)';
const newColor = '#ffe52c';
const period = 12; // animation period in seconds
const animRatio: ExpressionValue = [
  '^',
  ['/', ['%', ['+', ['time'], ['interpolate', ['linear'], ['get', 'year'], 1975, 0, 2026, period]], period], period],
  0.5,
];

const style: FlatStyle = {
  'circle-radius': [
    '*',
    ['interpolate', ['linear'], ['get', 'magnitude'], 2, 4, 5, 13],
    ['-', 1.75, ['*', animRatio, 0.75]],
  ],
  'circle-fill-color': ['interpolate', ['linear'], animRatio, 0, newColor, 1, oldColor],
  'circle-opacity': ['-', 1.0, ['*', animRatio, 0.75]],
};

/** The tremors of a CSV file of id, magnitude, year, latitude and longitude, one per line after the header. */
export function readTremors(csv: string): Feature[] {
  const features: Feature[] = [];
  for (const row of csv.split('\n').slice(1)) {
    const line = row.split(',');
    const coords = fromLonLat([parseFloat(line[4]), parseFloat(line[3])]);
    if (isNaN(coords[0]) || isNaN(coords[1])) {
      // guard against bad data
      continue;
    }
    features.push(
      new Feature({
        magnitude: parseFloat(line[1]) || 0,
        year: parseInt(line[2]) || 0,
        geometry: new Point(coords),
      })
    );
  }
  return features;
}

/** The rule that draws the tremors whose year lies between the style variables `minYear` and `maxYear`. */
export const pointsStyle: Rule[] = [
  {
    style,
    filter: ['between', ['get', 'year'], ['var', 'minYear'], ['var', 'maxYear']],
  },
];
filter-points-webgl.ts
import {
  afterNextRender,
  ChangeDetectionStrategy,
  Component,
  DestroyRef,
  inject,
  signal,
  viewChild,
} from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerTileComponent,
  MapComponent,
  SourceImageTileComponent,
  SourceVectorComponent,
  ViewComponent,
} from 'cc-openlayers';
import { LayerWebGLVectorComponent } from 'cc-openlayers/webgl';
import { pointsStyle, readTremors } from './filter-points-webgl.shared';

/**
 * The seismic events around Kraków since 1978 drawn by a WebGL vector layer that filters them by year: the sliders
 * change the style variables of the filter, a circle's size follows the magnitude, and a pulse offset by the year
 * animates the points, the map rendering on every animation frame.
 */
@Component({
  selector: 'app-filter-points-webgl',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerTileComponent,
    LayerWebGLVectorComponent,
    MapComponent,
    SourceImageTileComponent,
    SourceVectorComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="9">
        <aol-coordinate [x]="19.25" [y]="50.15" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-tile>
        <aol-source-imagetile
          url="https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}"
          [maxZoom]="16"
          attributions="Tiles © Esri — Esri, HERE, Garmin, © OpenStreetMap contributors, and the GIS user community"
        />
      </aol-layer-tile>
      <aol-layer-webglvector [style]="pointsStyle" [variables]="years()" [disableHitDetection]="true">
        <aol-source-vector attributions="Seismic events: U.S. Geological Survey" />
      </aol-layer-webglvector>
      <aol-layer-tile>
        <aol-source-imagetile
          url="https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Reference/MapServer/tile/{z}/{y}/{x}"
          [maxZoom]="16"
        />
      </aol-layer-tile>
    </aol-map>
    <div class="example-controls">
      <p>Show tremors between {{ years().minYear }} and {{ years().maxYear }}</p>
      <label>
        Minimum year:
        <input
          name="min-year"
          type="range"
          min="1975"
          max="2026"
          step="1"
          [value]="years().minYear"
          (input)="set('minYear', $event)"
        />
      </label>
      <label>
        Maximum year:
        <input
          name="max-year"
          type="range"
          min="1975"
          max="2026"
          step="1"
          [value]="years().maxYear"
          (input)="set('maxYear', $event)"
        />
      </label>
    </div>
  `,
})
export class FilterPointsWebgl {
  readonly years = signal({ minYear: 1975, maxYear: 2026 });
  protected readonly pointsStyle = pointsStyle;
  private readonly map = viewChild.required(MapComponent);
  private readonly source = viewChild.required(SourceVectorComponent);

  constructor() {
    // load data
    let destroyed = false;
    inject(DestroyRef).onDestroy(() => (destroyed = true));
    afterNextRender(async () => {
      try {
        const csv = await (await fetch('assets/krakow/tremors.csv')).text();
        if (!destroyed) this.source().instance.addFeatures(readTremors(csv));
      } catch (error) {
        console.error('The tremors could not be loaded', error);
      }
    });

    // animate the map
    let frame = 0;
    const animate = () => {
      this.map().instance.render();
      frame = window.requestAnimationFrame(animate);
    };
    afterNextRender(animate);
    inject(DestroyRef).onDestroy(() => window.cancelAnimationFrame(frame));
  }

  protected set(bound: 'minYear' | 'maxYear', event: Event): void {
    const year = parseInt((event.target as HTMLInputElement).value);
    this.years.update((years) => ({ ...years, [bound]: year }));
  }
}

Architecture and OpenLayers mechanics

readTremors parses assets/krakow/tremors.csv into Point features carrying numeric magnitude and year attributes. On the WebGL layer, the style rule’s filter checks year between ['var', 'minYear'] and ['var', 'maxYear'], updated without shader recompilation through [variables]="years()".

Circle radius (circle-radius) scales from 4 px (magnitude 2) to 13 px (magnitude 5) modulated by animRatio—a ['time'] wave offset per event’s year driven by animate—with [disableHitDetection]="true" skipping off-screen hit-buffer rendering.

How it works

  • A GPU filter expression keeps points whose year lies between ['var', 'minYear'] and ['var', 'maxYear'], fed by [variables]="years()".
  • circle-radius scales with magnitude (4 px at M2 to 13 px at M5) and pulses via animRatio.
  • animRatio combines ['time'] with each event’s year so circles pulse out of sync across animation frames driven by animate.
  • readTremors parses assets/krakow/tremors.csv into Point features with numeric magnitude and year fields.

Pitfalls

  • Setting [disableHitDetection]="true" saves GPU memory and frame time on pure-visual layers, but calling forEachFeatureAtPixel against that layer will throw an error—leave hit detection enabled whenever click/hover inspection is needed.
  • Reference ['var', 'minYear'] inside a static filter rather than rebuilding the filter array on slider input so shaders compile only once.

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.