Projections · Angular, React and OpenLayers
A single image reprojected
Reproject a static 1000x800 EPSG:2180 topographic image onto a Web Mercator OpenLayers map and toggle bilinear vs nearest-pixel interpolation.

What this example shows
Spanning Kraków from Bronowice to Nowa Huta over Web Mercator OpenStreetMap, a single static 1000 × 800 pixel topographic sheet rendered in the Polish 1992 grid (EPSG:2180 at 20 m/px) is warped in the browser onto EPSG:3857—with an Interpolate checkbox switching between smooth bilinear resampling and crisp, slightly tilted (~0.7° meridian convergence) square source pixels when zoomed in.
When you need it
Georeferenced historical map scans, engineering CAD plots and exported WMS snapshots arrive as single rectangular bitmaps in a national planar grid (EPSG:2180, EPSG:27700) with known corner coordinates.
OpenLayers’ static-image reprojection overlays those plans directly onto Web Mercator street maps without running gdalwarp beforehand.
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.
reprojection-image.shared.ts/** The area of the image in the national grid (EPSG:2180). */
export const imageExtent = [556000, 236000, 576000, 252000];
/** The image: one GetMap request of the topographic map service in EPSG:2180, at 20 metres per pixel. */
export const url =
'https://mapy.geoportal.gov.pl/wss/service/img/guest/TOPO/MapServer/WMSServer?SERVICE=WMS&VERSION=1.1.1' +
`&REQUEST=GetMap&LAYERS=Raster&STYLES=&SRS=EPSG:2180&BBOX=${imageExtent.join(',')}` +
'&WIDTH=1000&HEIGHT=800&FORMAT=image/jpeg';reprojection-image.tsimport { ChangeDetectionStrategy, Component, inject, PendingTasks, signal } from '@angular/core';
import { getCenter } from 'ol/extent';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerImageComponent,
LayerTileComponent,
loadProj4,
MapComponent,
registerProjectionDefinitions,
SourceImageStaticComponent,
SourceOsmComponent,
ViewComponent,
} from 'cc-openlayers';
import { imageExtent, url } from './reprojection-image.shared';
/**
* A 1000 by 800 pixel image of GUGiK's topographic map around Kraków, made in the Polish national grid (EPSG:2180,
* registered through proj4) and reprojected in the browser over OpenStreetMap in Web Mercator; the Interpolate
* checkbox switches between smooth and sharp resampling of its pixels.
*/
@Component({
selector: 'app-reprojection-image',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerImageComponent,
LayerTileComponent,
MapComponent,
SourceImageStaticComponent,
SourceOsmComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@if (ready()) {
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="12">
<aol-coordinate [x]="center[0]" [y]="center[1]" srid="EPSG:2180" />
</aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-image>
<aol-source-imagestatic
[url]="url"
crossOrigin=""
projection="EPSG:2180"
[imageExtent]="imageExtent"
[interpolate]="interpolate()"
attributions="Topographic map © GUGiK"
/>
</aol-layer-image>
</aol-map>
}
<div class="example-controls">
<input type="checkbox" id="interpolate" [checked]="interpolate()" (change)="setInterpolate($event)" />
<label for="interpolate">Interpolate</label>
</div>
`,
})
export class ReprojectionImage {
/** True once EPSG:2180 is known to OpenLayers, which the image source needs when it is created. */
readonly ready = signal(false);
readonly interpolate = signal(true);
protected readonly imageExtent = imageExtent;
protected readonly center = getCenter(imageExtent);
protected readonly url = url;
constructor() {
void inject(PendingTasks).run(async () => {
try {
registerProjectionDefinitions(await loadProj4(), {
'EPSG:2180':
'+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80 +units=m +no_defs',
});
this.ready.set(true);
} catch (error) {
console.error('The projection could not be loaded', error);
}
});
}
protected setInterpolate(event: Event): void {
this.interpolate.set((event.target as HTMLInputElement).checked);
}
} 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.
reprojection-image.react.tsximport { useEffect, useState } from 'react';
import { getCenter } from 'ol/extent.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
ImageLayer,
ImageStaticSource,
Map,
OSMSource,
TileLayer,
View,
} from 'cc-openlayers/react';
import { loadProj4, ProjectionCodeDefinition, registerProjectionDefinitions } from 'cc-openlayers/core';
import { imageExtent, url } from './reprojection-image.shared';
const CENTER = getCenter(imageExtent);
/**
* A 1000 by 800 pixel image of GUGiK's topographic map around Kraków, made in the Polish national grid (EPSG:2180,
* registered through proj4) and reprojected in the browser over OpenStreetMap in Web Mercator; the Interpolate
* checkbox switches between smooth and sharp resampling of its pixels.
*/
export function ReprojectionImage() {
/** True once EPSG:2180 is known to OpenLayers, which the image source needs when it is created. */
const [ready, setReady] = useState(false);
const [interpolate, setInterpolate] = useState(true);
useEffect(() => {
void loadProj4()
.then((proj4) => {
registerProjectionDefinitions(proj4, { 'EPSG:2180': ProjectionCodeDefinition.Pl1992 });
setReady(true);
})
.catch((error: unknown) => console.error('The projection could not be loaded', error));
}, []);
return (
<>
{ready && (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={12}>
<Coordinate x={CENTER[0]} y={CENTER[1]} srid="EPSG:2180" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<ImageLayer>
<ImageStaticSource
url={url}
crossOrigin=""
projection="EPSG:2180"
imageExtent={imageExtent}
interpolate={interpolate}
attributions="Topographic map © GUGiK"
/>
</ImageLayer>
</Map>
)}
<div className="example-controls">
<input
type="checkbox"
id="interpolate"
checked={interpolate}
onChange={(event) => setInterpolate(event.target.checked)}
/>
<label htmlFor="interpolate">Interpolate</label>
</div>
</>
);
}reprojection-image.shared.ts/** The area of the image in the national grid (EPSG:2180). */
export const imageExtent = [556000, 236000, 576000, 252000];
/** The image: one GetMap request of the topographic map service in EPSG:2180, at 20 metres per pixel. */
export const url =
'https://mapy.geoportal.gov.pl/wss/service/img/guest/TOPO/MapServer/WMSServer?SERVICE=WMS&VERSION=1.1.1' +
`&REQUEST=GetMap&LAYERS=Raster&STYLES=&SRS=EPSG:2180&BBOX=${imageExtent.join(',')}` +
'&WIDTH=1000&HEIGHT=800&FORMAT=image/jpeg';How the React version works
One image of GUGiK's topographic map of Kraków, 1000 by 800 pixels in the Polish 1992 grid, reprojected onto OpenStreetMap in Web Mercator, smooth or sharp.
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. Both versions import the image extent and its WMS GetMap URL from the example's .shared.ts file, so the logic exists once.
From Angular to React
| Angular | React |
|---|---|
ready signal set inside PendingTasks.run and @if (ready()) | useState(false) set after loadProj4() resolves, a failed load logged, and return null until then |
<aol-source-imagestatic [interpolate]="interpolate()"> | <ImageStaticSource interpolate={interpolate}> |
<input type="checkbox" (change)="setInterpolate($event)"> | <input type="checkbox" checked={interpolate} onChange={…}> |
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:2180 run in a useEffect with no dependencies; 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. React reads the definition from ProjectionCodeDefinition in cc-openlayers/core, which holds the same string Angular writes out.
Architecture and OpenLayers mechanics
Before @if (ready()) mounts the map, registerProjectionDefinitions registers EPSG:2180 via proj4 so the image source can resolve its CRS at construction time.
The static source loads a fixed WIDTH=1000&HEIGHT=800 topographic image (BBOX=${imageExtent.join(',')}, 20 m/px) positioned via [imageExtent]="imageExtent". Toggling [interpolate]="interpolate()" recreates the source to switch between smooth bilinear filtering and crisp nearest-neighbour square pixels.
How it works
registerProjectionDefinitionsregistersEPSG:2180before@if (ready())instantiates the map and static image source.- Fixed
url(BBOX=${imageExtent.join(',')}atWIDTH=1000&HEIGHT=800) and[imageExtent]="imageExtent"place the 20 × 16 km sheet inEPSG:2180. - Keeping the View in Web Mercator warps the static
EPSG:2180bitmap automatically whenever panning or zooming settles. - Toggling
[interpolate]="interpolate()"compares smooth bilinear resampling against unblended square pixels.
Pitfalls
- Zooming closer than the bitmap’s native 20 m/px resolution cannot fetch finer detail—with interpolation on it softens, and with interpolation off it reveals individual 20 m grid squares rotated ~0.7° relative to Web Mercator north.
- Unlike ImageWMS, a static image covers only its fixed
imageExtent(20 × 16 km) and never requests new areas when you pan outside Kraków.
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.