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.

A gray square spiral of thin lines centred on Kraków at zoom 8 over OpenStreetMap of southern Poland.
A screenshot of the example. Map data © OpenStreetMap contributors.

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.ts
import { 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;
}

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

  • spiral constructs 10,000 diagonal segments, each reaching 2,500 projection units farther out than the previous one.
  • Bulk insertion via addFeatures indexes all 10,000 features into the spatial R-tree in a single pass.
  • One shared 1-pixel grey aol-style-stroke renders 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.

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.