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.

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.tsimport { 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 {} 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.
webgl-tiles.react.tsximport { Coordinate, DefaultControls, DefaultInteractions, ImageTileSource, Map, View } from 'cc-openlayers/react';
import { WebGLTileLayer } from 'cc-openlayers/react/webgl';
/** OpenStreetMap's raster tiles of Kraków drawn by a WebGL tile layer. */
export function WebglTiles() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={12}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<WebGLTileLayer>
<ImageTileSource
url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
attributions='© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors.'
/>
</WebGLTileLayer>
</Map>
);
}How the React version works
OpenStreetMap's raster tiles of Kraków drawn by a WebGL tile layer instead of the canvas one.
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.
From Angular to React
| Angular | React |
|---|---|
<aol-layer-webgltile> with <aol-source-imagetile> | <WebGLTileLayer> with <ImageTileSource> |
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
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-webgltilefromcc-openlayers/webglrenders tiles fromaol-source-imagetileas WebGL textures on the GPU.- Splitting
cc-openlayers/webglinto its own entry point keeps WebGL shader/renderer code tree-shaken out of 2D-only pages. aol-source-imagetilefetcheshttps://tile.openstreetmap.org/{z}/{x}/{y}.pngwith 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.
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.