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.

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.tsimport { 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);
}
});
}
} 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.
scaleline-indiana-east.react.tsximport { useEffect, useState } from 'react';
import type { Extent } from 'ol/extent.js';
import { transformExtent } from 'ol/proj.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
ScaleLineControl,
TileLayer,
View,
} from 'cc-openlayers/react';
import { loadProj4, ProjectionCodeDefinition, registerProjectionDefinitions } from 'cc-openlayers/core';
/**
* 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.
*/
export function ScalelineIndianaEast() {
/** A box around Poland in the grid, which the view keeps within; known once EPSG:2178 is known to OpenLayers. */
const [extent, setExtent] = useState<Extent>();
useEffect(() => {
void loadProj4()
.then((proj4) => {
registerProjectionDefinitions(proj4, { 'EPSG:2178': ProjectionCodeDefinition.Pl2000zone7 });
setExtent(transformExtent([14.07, 49.0, 24.15, 54.84], 'EPSG:4326', 'EPSG:2178'));
})
.catch((error: unknown) => console.error('The projection could not be loaded', error));
}, []);
if (!extent) return null;
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<ScaleLineControl units="metric" />
<View projection="EPSG:2178" zoom={9} minZoom={6} extent={extent}>
<Coordinate x={19.9373} y={50.0617} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
</Map>
);
}How the React version works
OpenStreetMap reprojected into zone 7 of the Polish 2000 grid, EPSG:2178, around Kraków, with a metric scale line and the view kept within Poland.
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. The example has no shared file.
From Angular to React
| Angular | React |
|---|---|
ready signal, a plain extent field and @if (ready()) | useState<Extent>(), which also serves as the ready flag |
<aol-view projection="EPSG:2178" [minZoom]="6" [extent]="extent"> | <View projection="EPSG:2178" minZoom={6} extent={extent}> |
<aol-coordinate [x] [y] srid="EPSG:4326" /> inside the view | <Coordinate x y srid="EPSG:4326" /> inside View |
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. loadProj4 and the registration of EPSG:2178 run in a useEffect with no dependencies, which logs a failed load; the component renders nothing until a state flag says the projection is known, as @if (ready()) does around PendingTasks.run in Angular. Under StrictMode the effect runs twice and registers the same definition twice, which changes nothing. The effect then sets the extent, Poland's box transformed into the grid. React reads the definition from ProjectionCodeDefinition.Pl2000zone7 in cc-openlayers/core, the same string Angular writes out.
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:2178on the client while<aol-control-scaleline units="metric" />computes spherical ground length.
Pitfalls
- Calling
transformExtentwithout 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:2178without reprojecting shifts features 1,000 km west.
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.