Vector data · Angular, React and OpenLayers
A spiral of ten thousand lines
Benchmark OpenLayers vector rendering on a 10,000-segment square spiral around Kraków indexed in one pass via addFeatures with wrapX disabled.

What this example shows
Starting in central Kraków at zoom 8 over OpenStreetMap, a continuous geometric square spiral built from 10,000 individual diagonal line segments winds outward across southern Poland and beyond—testing bulk vector indexing and thin-stroke rendering.
When you need it
Electrical distribution grids, fibre-optic duct networks, road graphs and contour maps frequently load tens of thousands of individual LineString segments into a single vector layer.
Validating frame rates on a deterministic 10,000-segment synthetic geometry lets teams test styling and bulk-load patterns before connecting production utility databases.
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.
synthetic-lines.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import Feature from 'ol/Feature';
import LineString from 'ol/geom/LineString';
import type { Coordinate } from 'ol/coordinate';
import { fromLonLat } from 'ol/proj';
import type VectorSource from 'ol/source/Vector';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
StyleComponent,
StyleStrokeComponent,
ViewComponent,
} from 'cc-openlayers';
/**
* A square spiral of 10,000 line segments starting in Kraków, drawn from one vector source over OpenStreetMap. The map
* starts at zoom 8, where the turns lie about 16 pixels apart; zoomed out, the spiral closes into a solid block.
*/
@Component({
selector: 'app-synthetic-lines',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
StyleComponent,
StyleStrokeComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="8">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-vector>
<aol-style><aol-style-stroke color="#666666" [width]="1" /></aol-style>
<aol-source-vector [wrapX]="false" [loader]="loadSpiral" />
</aol-layer-vector>
</aol-map>
`,
})
export class SyntheticLines {
protected readonly loadSpiral = function (this: VectorSource): void {
this.addFeatures(spiral(10000, fromLonLat([19.9368, 50.0614])));
};
}
/**
* Segments of a square spiral standing on a corner: each one runs diagonally, 2,500 units of the projection further
* along each axis than the one before (Web Mercator metres, about 1.6 km on the ground at Kraków's latitude).
*/
function spiral(count: number, start: Coordinate): Feature<LineString>[] {
const features: Feature<LineString>[] = [];
let from = start;
let signX = 1;
let signY = -1;
for (let i = 0; i < count; i++) {
const delta = (i + 1) * 2500;
if (i % 2 === 0) {
signY *= -1;
} else {
signX *= -1;
}
const to = [from[0] + delta * signX, from[1] + delta * signY];
features.push(new Feature(new LineString([from, to])));
from = to;
}
return features;
} 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.
synthetic-lines.react.tsximport Feature from 'ol/Feature.js';
import LineString from 'ol/geom/LineString.js';
import type { Coordinate as OLCoordinate } from 'ol/coordinate.js';
import { fromLonLat } from 'ol/proj.js';
import type OLVectorSource from 'ol/source/Vector.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
Stroke,
Style,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
/**
* Segments of a square spiral standing on a corner: each one runs diagonally, 2,500 units of the projection further
* along each axis than the one before (Web Mercator metres, about 1.6 km on the ground at Kraków's latitude).
*/
function spiral(count: number, start: OLCoordinate): Feature<LineString>[] {
const features: Feature<LineString>[] = [];
let from = start;
let signX = 1;
let signY = -1;
for (let i = 0; i < count; i++) {
const delta = (i + 1) * 2500;
if (i % 2 === 0) {
signY *= -1;
} else {
signX *= -1;
}
const to = [from[0] + delta * signX, from[1] + delta * signY];
features.push(new Feature(new LineString([from, to])));
from = to;
}
return features;
}
const loadSpiral = function (this: OLVectorSource): void {
this.addFeatures(spiral(10000, fromLonLat([19.9368, 50.0614])));
};
/**
* A square spiral of 10,000 line segments starting in Kraków, drawn from one vector source over OpenStreetMap. The map
* starts at zoom 8, where the turns lie about 16 pixels apart; zoomed out, the spiral closes into a solid block.
*/
export function SyntheticLines() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={8}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<VectorLayer>
<Style>
<Stroke color="#666666" width={1} />
</Style>
<VectorSource wrapX={false} loader={loadSpiral} />
</VectorLayer>
</Map>
);
}How the React version works
A spiral of 10,000 connected segments starting in Kraków, drawn with a grey line.
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 |
|---|---|
a source loader and [wrapX]="false" | <VectorSource loader wrapX={false}> |
<aol-style> with <aol-style-stroke> | <Style> with <Stroke> |
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
spiral generates 10,000 diagonal line features where each turn steps 2,500 Web Mercator projection units farther outward along each axis, then inserts the entire array in a single addFeatures batch call so OpenLayers builds its R-tree spatial index in one bulk pass rather than 10,000 incremental insertions.
A single declarative 1-pixel grey aol-style-stroke styles every segment uniformly, and [wrapX]="false" prevents the world-spanning outer turns from wrapping back over themselves.
How it works
spiralconstructs 10,000 diagonal segments, each reaching 2,500 projection units farther out than the previous one.- Bulk insertion via
addFeaturesindexes all 10,000 features into the spatial R-tree in a single pass. - One shared 1-pixel grey
aol-style-strokerenders the entire network without per-feature style callbacks. - At zoom 8 adjacent turns sit roughly 16 pixels apart, while zooming all the way out reveals the full spiral, roughly 50,000 km wide with about 25,000 km on either side of Kraków.
Pitfalls
- Keep
[wrapX]="false"on datasets wider than 40,075 km in Web Mercator, otherwise horizontal world wrapping folds outer segments back across neighbouring worlds on top of the centre. - Remember that 2,500 Web Mercator projection units equal roughly 1.6 km on the ground at Kraków’s 50° N latitude rather than 2.5 true kilometres.
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.