Raster, GeoTIFF and WebGL · Angular, React and OpenLayers
Point styles edited as JSON
Render 1,027 Polish towns on the GPU in OpenLayers and edit live JSON flat point styles—circles, icons and time-animated bars—with hover state.

What this example shows
Across Poland over OpenStreetMap, 1,027 towns render on the GPU through seven selectable preset styles—from population-scaled circles and custom icons to continuously rotating bars driven by ['time']—paired with an editable <textarea> where typing valid JSON updates the live WebGL shader immediately and hovering highlights towns in red in the circle presets.
When you need it
No-code GIS style editors, IoT sensor dashboards and massive point clouds require GPU point throughput combined with plain JSON style definitions that users or CMS backends can edit at runtime.
Testing seven distinct flat-style idioms side by side demonstrates static sizing, attribute interpolation, sprite icons and time-based GPU animation.
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-points-layer.shared.tsimport type { FlatStyleLike } from 'ol/style/flat.js';
/**
* The predefined styles of the original, for Poland's towns: the population stops are the original's, the latitude
* stops span Poland from south to north, the labels read a town's `name`, and the icon is the gallery's own pin.
*/
export const STYLES = {
icons: {
'icon-src': 'assets/krakow/pin.svg',
'icon-width': 18,
'icon-height': 28,
'icon-color': 'lightyellow',
'icon-rotate-with-view': false,
'icon-displacement': [0, 9],
},
triangles: {
'shape-points': 3,
'shape-radius': 9,
'shape-fill-color': ['interpolate', ['linear'], ['get', 'population'], 20000, '#5aca5b', 300000, '#ff6a19'],
'shape-rotate-with-view': true,
},
'triangles-latitude': {
'shape-points': 3,
'shape-radius': ['interpolate', ['linear'], ['get', 'population'], 40000, 6, 2000000, 12],
'shape-fill-color': [
'interpolate',
['linear'],
['get', 'latitude'],
49,
'#ff14c3',
51,
'#ff621d',
53,
'#ffed02',
55,
'#00ff67',
],
'shape-opacity': 0.95,
},
circles: {
'circle-radius': ['interpolate', ['linear'], ['get', 'population'], 40000, 4, 2000000, 14],
'circle-fill-color': ['match', ['get', 'hover'], 1, '#ff3f3f', '#006688'],
'circle-rotate-with-view': false,
'circle-displacement': [0, 0],
'circle-opacity': ['interpolate', ['linear'], ['get', 'population'], 40000, 0.6, 2000000, 0.92],
},
'circles-zoom': {
// by using an exponential interpolation with a base of 2 we can make it so that circles will have a fixed size
// in world coordinates between zoom level 5 and 15
'circle-radius': ['interpolate', ['exponential', 2], ['zoom'], 5, 1.5, 15, 1.5 * Math.pow(2, 10)],
'circle-fill-color': ['match', ['get', 'hover'], 1, '#ff3f3f', '#006688'],
'circle-displacement': [0, 0],
'circle-opacity': 0.95,
},
'circles-text': {
'text-value': ['get', 'name'],
'text-font': 'bold 11px "Open Sans", "Arial Unicode MS", sans-serif',
'text-fill-color': '#334',
'text-stroke-color': 'rgba(255,255,255,0.8)',
'text-stroke-width': 2,
'text-offset-y': -12,
'circle-radius': 4,
'circle-fill-color': ['match', ['get', 'hover'], 1, '#ff3f3f', '#006688'],
'circle-rotate-with-view': false,
},
'rotating-bars': {
'shape-rotation': ['*', ['time'], 0.13],
'shape-points': 4,
'shape-radius': 4,
'shape-radius2': 4 * Math.sqrt(2),
'shape-scale': ['array', 1, ['interpolate', ['linear'], ['get', 'population'], 20000, 1, 300000, 7]],
'shape-fill-color': ['interpolate', ['linear'], ['get', 'population'], 20000, '#ffdc00', 300000, '#ff5b19'],
'shape-displacement': ['array', 0, ['interpolate', ['linear'], ['get', 'population'], 20000, 2, 300000, 14]],
},
} satisfies Record<string, FlatStyleLike>;
/** The name of a predefined style. */
export type StyleName = keyof typeof STYLES;
/** The predefined styles in the order the list offers them, with their labels. */
export const CHOICES: { value: StyleName; label: string }[] = [
{ value: 'icons', label: 'Icons' },
{ value: 'triangles', label: 'Triangles, color related to population' },
{ value: 'triangles-latitude', label: 'Triangles, color related to latitude' },
{ value: 'circles', label: 'Circles, size related to population' },
{ value: 'circles-zoom', label: 'Circles, size related to zoom' },
{ value: 'circles-text', label: 'Circles with label' },
{ value: 'rotating-bars', label: 'Rotating bars' },
];webgl-points-layer.tsimport {
afterNextRender,
ChangeDetectionStrategy,
Component,
DestroyRef,
inject,
signal,
viewChild,
} from '@angular/core';
import type Feature from 'ol/Feature';
import GeoJSON from 'ol/format/GeoJSON';
import type MapBrowserEvent from 'ol/MapBrowserEvent';
import type { FlatStyleLike } from 'ol/style/flat';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
} from 'cc-openlayers';
import { LayerWebGLVectorComponent } from 'cc-openlayers/webgl';
import { CHOICES, STYLES, type StyleName } from './webgl-points-layer.shared';
/**
* Poland's towns drawn with WebGL in a style chosen from a list or edited as JSON; the town under the pointer is
* marked `hover`, which the circle styles colour red, and the map renders every frame for the time-based style.
*/
@Component({
selector: 'app-webgl-points-layer',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerWebGLVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px" (pointerMove)="hover($event)">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="7">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-webglvector [style]="style()">
<aol-source-vector
url="assets/poland/towns.geojson"
[format]="format"
[wrapX]="true"
attributions='Towns © <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
/>
</aol-layer-webglvector>
</aol-map>
<div class="example-controls">
<p class="example-hint">Choose a predefined style from the list below or edit it as JSON manually.</p>
<select aria-label="Predefined style" (change)="choose($event)">
@for (choice of choices; track choice.value) {
<option [value]="choice.value" [selected]="choice.value === 'circles'">{{ choice.label }}</option>
}
</select>
<textarea aria-label="Style as JSON" [value]="text()" (input)="edit($event)"></textarea>
<small class="style-status">
@if (status() === 'valid') {
<span class="style-valid">✓ style is valid</span>
} @else if (status()) {
<span class="style-invalid">✗ {{ status() }}</span>
}
</small>
</div>
`,
})
export class WebglPointsLayer {
protected readonly choices = CHOICES;
protected readonly format = new GeoJSON();
protected readonly style = signal<FlatStyleLike>(STYLES.circles);
protected readonly text = signal(JSON.stringify(STYLES.circles, null, 2));
/** 'valid' once an edited style parses, the parser's message while it does not, empty for a predefined style. */
protected readonly status = signal('');
private readonly map = viewChild.required(MapComponent);
private selected: Feature | null = null;
constructor() {
// 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 choose(event: Event): void {
const style = STYLES[(event.target as HTMLSelectElement).value as StyleName];
this.text.set(JSON.stringify(style, null, 2));
this.style.set(style);
this.status.set('');
}
protected edit(event: Event): void {
const text = (event.target as HTMLTextAreaElement).value;
try {
const style = JSON.parse(text) as FlatStyleLike;
if (JSON.stringify(style) !== JSON.stringify(this.style())) this.style.set(style);
this.status.set('valid');
} catch (error) {
this.status.set((error as Error).message);
}
}
protected hover(event: MapBrowserEvent): void {
if (this.selected !== null) {
this.selected.set('hover', 0);
this.selected = null;
}
this.map().instance.forEachFeatureAtPixel(event.pixel, (feature) => {
this.selected = feature as Feature;
this.selected.set('hover', 1);
return true;
});
}
} 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-points-layer.react.tsximport { useEffect, useRef, useState, type ChangeEvent } from 'react';
import type Feature from 'ol/Feature.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import type OLMap from 'ol/Map.js';
import type MapBrowserEvent from 'ol/MapBrowserEvent.js';
import type { FlatStyleLike } from 'ol/style/flat.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
TileLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
import { WebGLVectorLayer } from 'cc-openlayers/react/webgl';
import { CHOICES, STYLES, type StyleName } from './webgl-points-layer.shared';
const format = new GeoJSON();
/**
* Poland's towns drawn with WebGL in a style chosen from a list or edited as JSON; the town under the pointer is
* marked `hover`, which the circle styles colour red, and the map renders every frame for the time-based style.
*/
export function WebglPointsLayer() {
const [style, setStyle] = useState<FlatStyleLike>(STYLES.circles);
const [text, setText] = useState(JSON.stringify(STYLES.circles, null, 2));
/** 'valid' once an edited style parses, the parser's message while it does not, empty for a predefined style. */
const [status, setStatus] = useState('');
const map = useRef<OLMap>(null);
const selected = useRef<Feature | null>(null);
useEffect(() => {
// animate the map
let frame = 0;
const animate = () => {
map.current?.render();
frame = window.requestAnimationFrame(animate);
};
frame = window.requestAnimationFrame(animate);
return () => window.cancelAnimationFrame(frame);
}, []);
const choose = (event: ChangeEvent<HTMLSelectElement>) => {
const chosen = STYLES[event.target.value as StyleName];
setText(JSON.stringify(chosen, null, 2));
setStyle(chosen);
setStatus('');
};
const edit = (event: ChangeEvent<HTMLTextAreaElement>) => {
const value = event.target.value;
setText(value);
try {
const parsed = JSON.parse(value) as FlatStyleLike;
if (JSON.stringify(parsed) !== JSON.stringify(style)) setStyle(parsed);
setStatus('valid');
} catch (error) {
setStatus((error as Error).message);
}
};
const hover = (event: MapBrowserEvent) => {
if (selected.current !== null) {
selected.current.set('hover', 0);
selected.current = null;
}
map.current?.forEachFeatureAtPixel(event.pixel, (feature) => {
selected.current = feature as Feature;
selected.current.set('hover', 1);
return true;
});
};
return (
<>
<Map ref={map} height="480px" onPointerMove={hover}>
<DefaultInteractions />
<DefaultControls />
<View zoom={7}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<WebGLVectorLayer style={style}>
<VectorSource
url="assets/poland/towns.geojson"
format={format}
wrapX
attributions='Towns © <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
/>
</WebGLVectorLayer>
</Map>
<div className="example-controls">
<p className="example-hint">Choose a predefined style from the list below or edit it as JSON manually.</p>
<select aria-label="Predefined style" defaultValue="circles" onChange={choose}>
{CHOICES.map((choice) => (
<option key={choice.value} value={choice.value}>
{choice.label}
</option>
))}
</select>
<textarea aria-label="Style as JSON" value={text} onChange={edit}></textarea>
<small className="style-status">
{status === 'valid' ? (
<span className="style-valid">✓ style is valid</span>
) : (
status && <span className="style-invalid">✗ {status}</span>
)}
</small>
</div>
</>
);
}webgl-points-layer.shared.tsimport type { FlatStyleLike } from 'ol/style/flat.js';
/**
* The predefined styles of the original, for Poland's towns: the population stops are the original's, the latitude
* stops span Poland from south to north, the labels read a town's `name`, and the icon is the gallery's own pin.
*/
export const STYLES = {
icons: {
'icon-src': 'assets/krakow/pin.svg',
'icon-width': 18,
'icon-height': 28,
'icon-color': 'lightyellow',
'icon-rotate-with-view': false,
'icon-displacement': [0, 9],
},
triangles: {
'shape-points': 3,
'shape-radius': 9,
'shape-fill-color': ['interpolate', ['linear'], ['get', 'population'], 20000, '#5aca5b', 300000, '#ff6a19'],
'shape-rotate-with-view': true,
},
'triangles-latitude': {
'shape-points': 3,
'shape-radius': ['interpolate', ['linear'], ['get', 'population'], 40000, 6, 2000000, 12],
'shape-fill-color': [
'interpolate',
['linear'],
['get', 'latitude'],
49,
'#ff14c3',
51,
'#ff621d',
53,
'#ffed02',
55,
'#00ff67',
],
'shape-opacity': 0.95,
},
circles: {
'circle-radius': ['interpolate', ['linear'], ['get', 'population'], 40000, 4, 2000000, 14],
'circle-fill-color': ['match', ['get', 'hover'], 1, '#ff3f3f', '#006688'],
'circle-rotate-with-view': false,
'circle-displacement': [0, 0],
'circle-opacity': ['interpolate', ['linear'], ['get', 'population'], 40000, 0.6, 2000000, 0.92],
},
'circles-zoom': {
// by using an exponential interpolation with a base of 2 we can make it so that circles will have a fixed size
// in world coordinates between zoom level 5 and 15
'circle-radius': ['interpolate', ['exponential', 2], ['zoom'], 5, 1.5, 15, 1.5 * Math.pow(2, 10)],
'circle-fill-color': ['match', ['get', 'hover'], 1, '#ff3f3f', '#006688'],
'circle-displacement': [0, 0],
'circle-opacity': 0.95,
},
'circles-text': {
'text-value': ['get', 'name'],
'text-font': 'bold 11px "Open Sans", "Arial Unicode MS", sans-serif',
'text-fill-color': '#334',
'text-stroke-color': 'rgba(255,255,255,0.8)',
'text-stroke-width': 2,
'text-offset-y': -12,
'circle-radius': 4,
'circle-fill-color': ['match', ['get', 'hover'], 1, '#ff3f3f', '#006688'],
'circle-rotate-with-view': false,
},
'rotating-bars': {
'shape-rotation': ['*', ['time'], 0.13],
'shape-points': 4,
'shape-radius': 4,
'shape-radius2': 4 * Math.sqrt(2),
'shape-scale': ['array', 1, ['interpolate', ['linear'], ['get', 'population'], 20000, 1, 300000, 7]],
'shape-fill-color': ['interpolate', ['linear'], ['get', 'population'], 20000, '#ffdc00', 300000, '#ff5b19'],
'shape-displacement': ['array', 0, ['interpolate', ['linear'], ['get', 'population'], 20000, 2, 300000, 14]],
},
} satisfies Record<string, FlatStyleLike>;
/** The name of a predefined style. */
export type StyleName = keyof typeof STYLES;
/** The predefined styles in the order the list offers them, with their labels. */
export const CHOICES: { value: StyleName; label: string }[] = [
{ value: 'icons', label: 'Icons' },
{ value: 'triangles', label: 'Triangles, color related to population' },
{ value: 'triangles-latitude', label: 'Triangles, color related to latitude' },
{ value: 'circles', label: 'Circles, size related to population' },
{ value: 'circles-zoom', label: 'Circles, size related to zoom' },
{ value: 'circles-text', label: 'Circles with label' },
{ value: 'rotating-bars', label: 'Rotating bars' },
];How the React version works
Poland's towns drawn by a WebGL vector layer in a style chosen from a list or edited as JSON; invalid JSON is reported, and the map renders on every animation frame so animated styles keep moving.
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 predefined styles and their names from the example's .shared.ts file, so the logic exists once.
From Angular to React
| Angular | React |
|---|---|
<aol-layer-webglvector [style]> | <WebGLVectorLayer style> |
the style list, the JSON editor and signals | useState of the style, the text and the status |
requestAnimationFrame started in afterNextRender and cancelled through DestroyRef | a useEffect that requests frames and cancels the last one in its cleanup |
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
STYLES provides seven flat point style presets (icons through rotating-bars) selectable from a dropdown and mirrored as formatted JSON inside a <textarea>. Handler edit parses user edits via JSON.parse(text) and updates [style]="style()" strictly when valid JSON differs from the active style.
circles scales radius by population (4 px at 40,000 to 14 px at 2,000,000), hover toggles hover (1 vs 0) matched via ['match', ['get', 'hover'], 1, '#ff3f3f', '#006688'], and animate schedules continuous frames for ['time']-driven styles.
How it works
STYLESsupplies seven presets fromiconstorotating-bars, displayed and editable live inside a JSON <textarea>.editvalidates edits withJSON.parse(text)and updates[style]="style()"only when the parsed JSON actually changed.hoversets feature propertyhover(1or0), styled via['match', ['get', 'hover'], 1, '#ff3f3f', '#006688'].circlesinterpolates size bypopulation, whilerotating-barsreads['time']driven by ananimaterender loop.
Pitfalls
- Mutating a feature’s
hoverattribute (feature.set for the hover attribute) triggers WebGL vertex-buffer regeneration across all 1,027 points—fine at 1,000 points, whereas for 100,000+ points prefer matching the feature id against a style variable as shown in webgl-vector-layer. - Every
[style]replacement invokessetStyleand compiles new WebGL shaders—guard against no-op edits and syntax errors before assigning. - Styles referencing
['time']only advance visually when arequestAnimationFrameloop calls map.render().
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.