Vector data · Angular, React and OpenLayers
Points drawn in every frame
Animate 200 moving points at 60 fps directly on an OpenLayers tile-layer canvas in postrender using getVectorContext and frameState timestamps.

What this example shows
Across Poland at zoom 5 over OpenStreetMap, a sinuous chain of 200 yellow-and-red points led by a black head marker orbits smoothly around Kraków once every 30 seconds at full display refresh rate—drawn with zero VectorLayer or Feature instances.
When you need it
High-frequency telemetry streams—radar sweeps, particle animations, drone swarms or simulated traffic—update coordinates on every 16 ms animation frame where mutating Feature objects and rebuilding spatial indices would waste CPU and memory.
When animated markers only need visual rendering without Feature selection or attribute popups, immediate postrender vector drawing delivers maximum throughput.
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.
dynamic-data.tsimport { ChangeDetectionStrategy, Component, viewChild } from '@angular/core';
import type { Coordinate } from 'ol/coordinate';
import MultiPoint from 'ol/geom/MultiPoint';
import Point from 'ol/geom/Point';
import { fromLonLat } from 'ol/proj';
import { getVectorContext } from 'ol/render';
import type RenderEvent from 'ol/render/Event';
import CircleStyle from 'ol/style/Circle';
import Fill from 'ol/style/Fill';
import Stroke from 'ol/style/Stroke';
import Style from 'ol/style/Style';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
ViewComponent,
} from 'cc-openlayers';
const POINTS = 200;
/** Rotation period in ms. */
const PERIOD = 30000;
/**
* The radii of the curve in Web Mercator metres, a tenth of the original's: up to 1,100 km of the projection from
* Kraków, the curve circles Poland and fits the map at zoom 5.
*/
const BIG_RADIUS = 7e5;
const SMALL_RADIUS = 2e5;
const OFFSET = 2e5;
const CENTER = fromLonLat([19.9368, 50.0614]);
const dot = new Style({
image: new CircleStyle({
radius: 5,
fill: new Fill({ color: 'yellow' }),
stroke: new Stroke({ color: 'red', width: 1 }),
}),
});
const headInner = new Style({ image: new CircleStyle({ radius: 2, fill: new Fill({ color: 'blue' }) }) });
const headOuter = new Style({ image: new CircleStyle({ radius: 5, fill: new Fill({ color: 'black' }) }) });
/** The 200 points of the curve at a time in ms; the last one is the head. */
export function curveAt(time: number): Coordinate[] {
const theta = (2 * Math.PI * time) / PERIOD;
return Array.from({ length: POINTS }, (_, index) => {
const t = theta + (2 * Math.PI * index) / POINTS;
const x =
(BIG_RADIUS + SMALL_RADIUS) * Math.cos(t) + OFFSET * Math.cos(((BIG_RADIUS + SMALL_RADIUS) * t) / SMALL_RADIUS);
const y =
(BIG_RADIUS + SMALL_RADIUS) * Math.sin(t) + OFFSET * Math.sin(((BIG_RADIUS + SMALL_RADIUS) * t) / SMALL_RADIUS);
return [CENTER[0] + x, CENTER[1] + y];
});
}
/** Points that move along a curve, drawn straight onto the tile layer's canvas after each render. */
@Component({
selector: 'app-dynamic-data',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="5">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile [postrender]="postrender"><aol-source-osm /></aol-layer-tile>
</aol-map>
`,
})
export class DynamicData {
private readonly map = viewChild.required(MapComponent);
protected readonly postrender = (event: RenderEvent): void => {
const context = getVectorContext(event);
const coordinates = curveAt(event.frameState?.time ?? 0);
context.setStyle(dot);
context.drawGeometry(new MultiPoint(coordinates));
const head = new Point(coordinates[coordinates.length - 1]);
context.setStyle(headOuter);
context.drawGeometry(head);
context.setStyle(headInner);
context.drawGeometry(head);
// The next frame is requested at once, so the points keep moving.
this.map().instance.render();
};
} 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.
dynamic-data.react.tsximport { useRef } from 'react';
import type { Coordinate as OLCoordinate } from 'ol/coordinate.js';
import MultiPoint from 'ol/geom/MultiPoint.js';
import Point from 'ol/geom/Point.js';
import type OLMap from 'ol/Map.js';
import { fromLonLat } from 'ol/proj.js';
import { getVectorContext } from 'ol/render.js';
import type RenderEvent from 'ol/render/Event.js';
import CircleStyle from 'ol/style/Circle.js';
import Fill from 'ol/style/Fill.js';
import Stroke from 'ol/style/Stroke.js';
import Style from 'ol/style/Style.js';
import { Coordinate, DefaultControls, DefaultInteractions, Map, OSMSource, TileLayer, View } from 'cc-openlayers/react';
const POINTS = 200;
/** Rotation period in ms. */
const PERIOD = 30000;
/**
* The radii of the curve in Web Mercator metres, a tenth of the original's: up to 1,100 km of the projection from
* Kraków, the curve circles Poland and fits the map at zoom 5.
*/
const BIG_RADIUS = 7e5;
const SMALL_RADIUS = 2e5;
const OFFSET = 2e5;
const CENTER = fromLonLat([19.9368, 50.0614]);
const dot = new Style({
image: new CircleStyle({
radius: 5,
fill: new Fill({ color: 'yellow' }),
stroke: new Stroke({ color: 'red', width: 1 }),
}),
});
const headInner = new Style({ image: new CircleStyle({ radius: 2, fill: new Fill({ color: 'blue' }) }) });
const headOuter = new Style({ image: new CircleStyle({ radius: 5, fill: new Fill({ color: 'black' }) }) });
/** The 200 points of the curve at a time in ms; the last one is the head. */
export function curveAt(time: number): OLCoordinate[] {
const theta = (2 * Math.PI * time) / PERIOD;
return Array.from({ length: POINTS }, (_, index) => {
const t = theta + (2 * Math.PI * index) / POINTS;
const x =
(BIG_RADIUS + SMALL_RADIUS) * Math.cos(t) + OFFSET * Math.cos(((BIG_RADIUS + SMALL_RADIUS) * t) / SMALL_RADIUS);
const y =
(BIG_RADIUS + SMALL_RADIUS) * Math.sin(t) + OFFSET * Math.sin(((BIG_RADIUS + SMALL_RADIUS) * t) / SMALL_RADIUS);
return [CENTER[0] + x, CENTER[1] + y];
});
}
/** Points that move along a curve, drawn straight onto the tile layer's canvas after each render. */
export function DynamicData() {
const map = useRef<OLMap>(null);
const postrender = (event: RenderEvent): void => {
const context = getVectorContext(event);
const coordinates = curveAt(event.frameState?.time ?? 0);
context.setStyle(dot);
context.drawGeometry(new MultiPoint(coordinates));
const head = new Point(coordinates[coordinates.length - 1]);
context.setStyle(headOuter);
context.drawGeometry(head);
context.setStyle(headInner);
context.drawGeometry(head);
// The next frame is requested at once, so the points keep moving.
map.current?.render();
};
return (
<Map ref={map} height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={5}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer onPostRender={postrender}>
<OSMSource />
</TileLayer>
</Map>
);
}How the React version works
In the tile layer's postrender event, the example draws 200 points of a curve that circles Poland and its head, then asks the map for the next frame.
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.
From Angular to React
| Angular | React |
|---|---|
[postrender] on aol-layer-tile and viewChild of the map | onPostRender on TileLayer and useRef<OLMap> for render() |
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
Inside the base tile layer’s postrender event, curveAt evaluates the parametric positions of all 200 points from frameState’s authoritative render timestamp—keeping angular speed independent of monitor refresh rate (60 Hz vs 120 Hz).
Calling getVectorContext obtains an immediate canvas renderer that paints all 200 coordinates in a single MultiPoint draw call followed by the black lead point, and calling render() schedules the next animation frame continuously.
How it works
curveAtcomputes 200 parametric coordinates completing one full orbit every 30 seconds up to 1,100 projection km around Kraków.- In the tile layer’s
postrenderlistener,getVectorContextdraws all 200 points as oneMultiPointplus the leading point. - Driving positions from
frameStatetime keeps motion smooth and frame-rate-independent. - Calling
render()at the end of each pass requests the next animation frame.
Pitfalls
- Calling
render()unconditionally insidepostrenderruns a continuous 60+ fps GPU/CPU loop—pause the loop whenever animation stops, the tab hides or the component unmounts to save laptop and mobile battery. - Shapes painted via
getVectorContextare transient pixels rather than retained Features, so forEachFeatureAtPixel and Select interactions will not detect them.
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.