Raster, GeoTIFF and WebGL · Angular, React and OpenLayers

Raster tiles drawn with WebGL

Render standard OpenStreetMap XYZ raster tiles on the GPU in OpenLayers using WebGLTileLayer and CORS-enabled ImageTile sources as a baseline.

OpenStreetMap of Kraków drawn with WebGL, from Bronowice and Balice airport in the west to Nowa Huta in the east, with the Vistula through the middle.
A screenshot of the example. Map data © OpenStreetMap contributors.

What this example shows

Spanning Kraków from Balice airport and Bronowice in the west to Nowa Huta in the east along the Vistula, standard OpenStreetMap {z}/{x}/{y}.png tiles are uploaded as GPU textures and rendered through OpenLayers’ WebGL tile pipeline rather than the classic 2D Canvas renderer.

When you need it

Migrating a raster tile layer from 2D Canvas to WebGLTileLayer is the architectural foundation for GPU colour grading, multi-band GeoTIFF math, smooth cross-fades and compositing many heavy raster layers on one GPU canvas.

Keeping WebGL components in a dedicated secondary entry point (cc-openlayers/webgl) also ensures pages that only need simple 2D maps pay zero WebGL bundle cost.

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.

webgl-tiles.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  MapComponent,
  SourceImageTileComponent,
  ViewComponent,
} from 'cc-openlayers';
import { LayerWebGLTileComponent } from 'cc-openlayers/webgl';

/** OpenStreetMap's raster tiles of Kraków drawn by a WebGL tile layer. */
@Component({
  selector: 'app-webgl-tiles',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerWebGLTileComponent,
    MapComponent,
    SourceImageTileComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="12">
        <aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-webgltile>
        <aol-source-imagetile
          url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
          attributions='© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors.'
        />
      </aol-layer-webgltile>
    </aol-map>
  `,
})
export class WebglTiles {}

Architecture and OpenLayers mechanics

Importing aol-layer-webgltile from cc-openlayers/webgl and pairing it with aol-source-imagetile pointed at https://tile.openstreetmap.org/{z}/{x}/{y}.png renders standard raster tiles directly on the GPU with default identity styling.

How it works

  • aol-layer-webgltile from cc-openlayers/webgl renders tiles from aol-source-imagetile as WebGL textures on the GPU.
  • Splitting cc-openlayers/webgl into its own entry point keeps WebGL shader/renderer code tree-shaken out of 2D-only pages.
  • aol-source-imagetile fetches https://tile.openstreetmap.org/{z}/{x}/{y}.png with CORS enabled by default.

Pitfalls

  • WebGL strictly forbids uploading cross-origin images without CORS clearance as GPU textures (texImage2D SecurityError)—always ensure your tile server returns Access-Control-Allow-Origin headers.

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.