Projections · Angular, React and OpenLayers

A scale line in the Polish 2000 grid

Reproject OpenStreetMap into Polish 2000 zone 7 (EPSG:2178) around Kraków with proj4, national extent bounds and a spherical metric ScaleLine.

OpenStreetMap of southern Poland in zone 7 of the Polish 2000 grid, from Bytom and Rybnik to Tarnobrzeg and Krosno with Kraków in the middle, and a 20 km scale line in the bottom left corner.
A screenshot of the example. Map data © OpenStreetMap contributors.

What this example shows

Spanning southern Poland from Upper Silesia through Kraków to Tarnobrzeg and Krosno, OpenStreetMap tiles are reprojected live in the browser into zone 7 of the Polish 2000 cadastral grid (EPSG:2178, central meridian 21° E) fenced to Poland’s bounds with a crisp metric scale line.

When you need it

Large-scale surveying, engineering CAD drawings and Polish cadastral parcel borders (EGiB) are measured in narrow 3-degree Gauss–Krüger zones of PUWG 2000 (EPSG:2176–2179) where linear distortion stays within 1 : 10,000 (k = 0.999923).

Reprojecting OpenStreetMap into EPSG:2178 gives surveyors familiar street context directly inside their native cadastral coordinate frame.

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.

scaleline-indiana-east.ts
import { ChangeDetectionStrategy, Component, inject, PendingTasks, signal } from '@angular/core';
import type { Extent } from 'ol/extent';
import { transformExtent } from 'ol/proj';
import {
  ControlScaleLineComponent,
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerTileComponent,
  loadProj4,
  MapComponent,
  registerProjectionDefinitions,
  SourceOsmComponent,
  ViewComponent,
} from 'cc-openlayers';

/**
 * OpenStreetMap reprojected in the browser to zone 7 of the Polish 2000 grid (EPSG:2178, the local grid of Kraków,
 * registered through proj4), with a scale line in metres; the view stays within a box around Poland.
 */
@Component({
  selector: 'app-scaleline-indiana-east',
  imports: [
    ControlScaleLineComponent,
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerTileComponent,
    MapComponent,
    SourceOsmComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    @if (ready()) {
      <aol-map height="480px">
        <aol-interaction-default />
        <aol-control-defaults />
        <aol-control-scaleline units="metric" />
        <aol-view projection="EPSG:2178" [zoom]="9" [minZoom]="6" [extent]="extent">
          <aol-coordinate [x]="19.9373" [y]="50.0617" srid="EPSG:4326" />
        </aol-view>
        <aol-layer-tile><aol-source-osm /></aol-layer-tile>
      </aol-map>
    }
  `,
})
export class ScalelineIndianaEast {
  /** True once EPSG:2178 is known to OpenLayers, which the view needs when it is created. */
  readonly ready = signal(false);
  /** A box around Poland in the grid, which the view keeps within. */
  protected extent: Extent = [];

  constructor() {
    void inject(PendingTasks).run(async () => {
      try {
        registerProjectionDefinitions(await loadProj4(), {
          'EPSG:2178': '+proj=tmerc +lat_0=0 +lon_0=21 +k=0.999923 +x_0=7500000 +y_0=0 +ellps=GRS80 +units=m +no_defs',
        });
        this.extent = transformExtent([14.07, 49.0, 24.15, 54.84], 'EPSG:4326', 'EPSG:2178');
        this.ready.set(true);
      } catch (error) {
        console.error('The projection could not be loaded', error);
      }
    });
  }
}

Architecture and OpenLayers mechanics

Before @if (ready()) creates the map, the constructor registers EPSG:2178 from its Transverse Mercator proj4 string (+proj=tmerc +lat_0=0 +lon_0=21 +k=0.999923 +x_0=7500000 ...).

transformExtent([14.07, 49.0, 24.15, 54.84], 'EPSG:4326', 'EPSG:2178') projects Poland’s degree box to set [extent]="extent" paired with [minZoom]="6", while <aol-control-scaleline units="metric" /> measures ground scale accurately on the sphere.

How it works

  • Zone 7 of Polish 2000 (EPSG:2178, +proj=tmerc +lat_0=0 +lon_0=21 +k=0.999923 +x_0=7500000) is registered before @if (ready()).
  • transformExtent([14.07, 49.0, 24.15, 54.84], 'EPSG:4326', 'EPSG:2178') fences the view via [extent]="extent" and [minZoom]="6".
  • OpenStreetMap warps into EPSG:2178 on the client while <aol-control-scaleline units="metric" /> computes spherical ground length.

Pitfalls

  • Calling transformExtent without an edge-stops count projects only the four corners—because parallels curve in Transverse Mercator, the straight line between the 14.07° E and 24.15° E corners bows roughly 10 km northward at 21° E, with a maximum sagitta near 12 km (pass a stops argument when tight border clipping matters).
  • Polish 2000 prefixes false eastings with the zone digit (7,500,000 m at 21° E in zone 7 vs 6,500,000 m at 18° E in zone 6)—loading zone-6 coordinates into EPSG:2178 without reprojecting shifts features 1,000 km west.

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.