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.

GUGiK's topographic map of Kraków from Bronowice to Nowa Huta as one image over OpenStreetMap in Web Mercator, which shows at its left and right edges, with the Interpolate checkbox checked below the map.
A screenshot of the example. Topographic map © GUGiK. Map data © OpenStreetMap contributors.

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

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

  • registerProjectionDefinitions registers EPSG:2180 before @if (ready()) instantiates the map and static image source.
  • Fixed url (BBOX=${imageExtent.join(',')} at WIDTH=1000&HEIGHT=800) and [imageExtent]="imageExtent" place the 20 × 16 km sheet in EPSG:2180.
  • Keeping the View in Web Mercator warps the static EPSG:2180 bitmap 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.

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.