Projections · Angular, React and OpenLayers
Geographic vector tiles in a polar equal-area view
Reproject EPSG:4326 geographic vector tiles on the fly into a polar Lambert Azimuthal Equal Area (ESRI:102017) OpenLayers view with proj4.

What this example shows
Using the exact same EPSG:4326 PRG municipality vector-tile pyramid as vector-tiles-4326, OpenLayers reprojects decoded polygon geometries in the browser into the North Pole Lambert Azimuthal Equal Area projection (ESRI:102017)—displaying Kraków and surrounding communes rotated along their true polar meridian angle.
When you need it
Polar research portals, pan-European equal-area atlases (EPSG:3035) and national-grid CAD apps (EPSG:2180) often need custom projected views while consuming vector-tile basemaps published in EPSG:4326 or EPSG:3857.
When a VectorTile source declares its own native projection and tileGrid explicitly, OpenLayers reprojects decoded vector-tile geometries into any proj4-registered View CRS cleanly.
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.
vector-tiles-reprojected.shared.tsimport type { Extent } from 'ol/extent.js';
import { transformExtent } from 'ol/proj.js';
import { municipalityFixtureExtent } from '../vector-tiles-4326/vector-tiles-4326.shared';
export const ESRI_102017_CODE = 'ESRI:102017';
export const ESRI_102017_DEFINITION =
'+proj=laea +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs';
/** Transforms the real fixture bound for the view after ESRI:102017 has been registered. */
export function getReprojectedMunicipalityFixtureExtent(): Extent {
return transformExtent(municipalityFixtureExtent, 'EPSG:4326', ESRI_102017_CODE);
}vector-tiles-reprojected.tsimport {
ChangeDetectionStrategy,
Component,
DestroyRef,
PendingTasks,
effect,
inject,
signal,
viewChild,
} from '@angular/core';
import { applyBackground, applyStyle } from 'ol-mapbox-style';
import type OLVectorTileLayer from 'ol/layer/VectorTile.js';
import type { Extent } from 'ol/extent.js';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FormatMVTComponent,
LayerVectorTileComponent,
loadProj4,
MapComponent,
registerProjectionDefinitions,
SourceVectorTileComponent,
TileGridComponent,
ViewComponent,
} from 'cc-openlayers';
import {
geographicTileGridDeclaration,
municipalityAttributionOptions,
municipalityStyle,
municipalityTileUrl,
} from '../vector-tiles-4326/vector-tiles-4326.shared';
import {
ESRI_102017_CODE,
ESRI_102017_DEFINITION,
getReprojectedMunicipalityFixtureExtent,
} from './vector-tiles-reprojected.shared';
@Component({
selector: 'app-vector-tiles-reprojected',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FormatMVTComponent,
LayerVectorTileComponent,
MapComponent,
SourceVectorTileComponent,
TileGridComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@if (ready()) {
<aol-map height="480px" ariaLabel="Geographic vector tiles in a North Pole equal-area view">
<aol-interaction-default />
<aol-control-defaults [attributionOptions]="attributionOptions" />
<aol-view
[projection]="projection"
[zoom]="11"
[minZoom]="3"
[extent]="fixtureExtent"
[constrainOnlyCenter]="true"
>
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-vectortile [declutter]="true" background="#d1d1d1">
<aol-source-vectortile
projection="EPSG:4326"
[tileUrlFunction]="tileUrlFunction"
attributions="Boundaries: PRG, Główny Urząd Geodezji i Kartografii"
>
<aol-format-mvt />
<aol-tilegrid
[extent]="grid.extent"
[minZoom]="grid.minZoom"
[origin]="grid.origin"
[resolutions]="grid.resolutions"
[tileSize]="grid.tileSize"
/>
</aol-source-vectortile>
</aol-layer-vectortile>
</aol-map>
}
@if (styleError()) {
<p role="status">The local vector style could not be applied.</p>
}
@if (initializationError()) {
<p role="status">The projected map could not be initialized.</p>
}
`,
})
export class VectorTilesReprojected {
protected readonly projection = ESRI_102017_CODE;
protected readonly grid = geographicTileGridDeclaration;
protected readonly attributionOptions = municipalityAttributionOptions;
protected readonly tileUrlFunction = municipalityTileUrl;
protected readonly ready = signal(false);
protected readonly styleError = signal(false);
protected readonly initializationError = signal(false);
protected fixtureExtent: Extent = [0, 0, 0, 0];
private readonly layer = viewChild(LayerVectorTileComponent);
private readonly destroyRef = inject(DestroyRef);
constructor() {
void inject(PendingTasks).run(async () => {
try {
const proj4 = await loadProj4();
if (this.destroyRef.destroyed) return;
registerProjectionDefinitions(proj4, { [ESRI_102017_CODE]: ESRI_102017_DEFINITION });
this.fixtureExtent = getReprojectedMunicipalityFixtureExtent();
this.ready.set(true);
} catch {
if (!this.destroyRef.destroyed) this.initializationError.set(true);
}
});
effect(() => {
const layer = this.layer()?.instance as OLVectorTileLayer | undefined;
if (!layer) return;
void Promise.all([
applyStyle(layer, municipalityStyle, { updateSource: false }),
applyBackground(layer, municipalityStyle),
]).catch(() => {
if (!this.destroyRef.destroyed) this.styleError.set(true);
});
});
}
} 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.
vector-tiles-reprojected.react.tsximport { useCallback, useEffect, useState } from 'react';
import { applyBackground, applyStyle } from 'ol-mapbox-style';
import type OLVectorTileLayer from 'ol/layer/VectorTile.js';
import type { Extent } from 'ol/extent.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
useLayer,
useMVTFormat,
useTileGrid,
VectorTileLayer,
VectorTileSource,
View,
} from 'cc-openlayers/react';
import { loadProj4, registerProjectionDefinitions } from 'cc-openlayers/core';
import {
geographicTileGridDeclaration,
municipalityAttributionOptions,
municipalityStyle,
municipalityTileUrl,
} from '../vector-tiles-4326/vector-tiles-4326.shared';
import {
ESRI_102017_CODE,
ESRI_102017_DEFINITION,
getReprojectedMunicipalityFixtureExtent,
} from './vector-tiles-reprojected.shared';
function ApplyMunicipalityStyle({ onError }: { onError: () => void }) {
const layer = useLayer() as OLVectorTileLayer;
useEffect(() => {
let active = true;
void Promise.all([
applyStyle(layer, municipalityStyle, { updateSource: false }),
applyBackground(layer, municipalityStyle),
]).catch(() => {
if (active) onError();
});
return () => {
active = false;
};
}, [layer, onError]);
return null;
}
/** The local PRG MVT fixture in the original North Pole equal-area view. */
export function VectorTilesReprojectedReact() {
const [fixtureExtent, setFixtureExtent] = useState<Extent | null>(null);
const [styleError, setStyleError] = useState(false);
const [initializationError, setInitializationError] = useState(false);
const format = useMVTFormat();
const tileGrid = useTileGrid(geographicTileGridDeclaration);
const reportStyleError = useCallback(() => setStyleError(true), []);
useEffect(() => {
let active = true;
void loadProj4()
.then((proj4) => {
if (!active) return;
registerProjectionDefinitions(proj4, { [ESRI_102017_CODE]: ESRI_102017_DEFINITION });
setFixtureExtent(getReprojectedMunicipalityFixtureExtent());
})
.catch(() => {
if (active) setInitializationError(true);
});
return () => {
active = false;
};
}, []);
return (
<>
{fixtureExtent ? (
<Map height="480px" ariaLabel="Geographic vector tiles in a North Pole equal-area view">
<DefaultInteractions />
<DefaultControls attributionOptions={municipalityAttributionOptions} />
<View projection={ESRI_102017_CODE} zoom={11} minZoom={3} extent={fixtureExtent} constrainOnlyCenter>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<VectorTileLayer declutter background="#d1d1d1">
<VectorTileSource
projection="EPSG:4326"
tileUrlFunction={municipalityTileUrl}
tileGrid={tileGrid}
format={format}
attributions="Boundaries: PRG, Główny Urząd Geodezji i Kartografii"
/>
<ApplyMunicipalityStyle onError={reportStyleError} />
</VectorTileLayer>
</Map>
) : null}
{styleError ? <p role="status">The local vector style could not be applied.</p> : null}
{initializationError ? <p role="status">The projected map could not be initialized.</p> : null}
</>
);
}vector-tiles-reprojected.shared.tsimport type { Extent } from 'ol/extent.js';
import { transformExtent } from 'ol/proj.js';
import { municipalityFixtureExtent } from '../vector-tiles-4326/vector-tiles-4326.shared';
export const ESRI_102017_CODE = 'ESRI:102017';
export const ESRI_102017_DEFINITION =
'+proj=laea +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs';
/** Transforms the real fixture bound for the view after ESRI:102017 has been registered. */
export function getReprojectedMunicipalityFixtureExtent(): Extent {
return transformExtent(municipalityFixtureExtent, 'EPSG:4326', ESRI_102017_CODE);
}How the React version works
The geographic PRG vector-tile source stays in EPSG:4326 while the map view uses ESRI:102017, North Pole Lambert Azimuthal Equal Area. Decoded vector geometry is transformed for that view. The default centre is Kraków; the projection still has its original polar definition.
What both versions share
The source, MVT files, 512-pixel logical grid and local style are shared with [vector-tiles-4326](vector-tiles-4326.md). The existing projection-registration API makes the original proj4 definition available before the projected view is constructed. Source coordinates must not be relabelled as projected metres. Unlike the geographic example, the reprojected example follows upstream by keeping the style helper's default metre-based resolution ladder. It does not pass the degree-based source-grid resolutions into that call. The global projection definition keeps its normal extent behavior; the finite fixture bounds constrain only the view centre. The finite municipality dataset replaces the original global provider basemap. Overzooming retains existing vector geometry; it must not request source matrix levels beyond 4–10. Centre bounds preserve the fixture without silently restricting the intended view zoom at a real map size.
From Angular to React
| Angular | React |
|---|---|
| Registration completes before rendering the projected view | Registration completes before mounting the projected view |
| The source projection remains EPSG:4326 | The source keeps the same projection |
| The view receives the registered ESRI:102017 code | The view receives the same registered code |
| The coordinate adapter transforms the Kraków centre | The coordinate adapter performs the same transformation |
Who creates, updates and disposes
Projection definitions belong to the existing OpenLayers registry. The map, layer and source remain owned by their framework adapters. Late registration or styling must not mount a map after its owner has gone. The example retains visible PRG credit and a map name that identifies the polar equal-area view.
Architecture and OpenLayers mechanics
Inside PendingTasks, the constructor lazily loads proj4 (loadProj4()), registers ESRI:102017 via registerProjectionDefinitions, computes the reprojected bounding box, and sets ready to true before @if (ready()) mounts aol-map and aol-view in ESRI:102017.
Meanwhile, aol-source-vectortile keeps projection="EPSG:4326" and its 512-pixel geographic aol-tilegrid, while applyStyle (updateSource: false) and applyBackground style the layer.
How it works
- The
EPSG:4326vector-tile source and 512-pixel geographic grid remain unchanged while only the View switches toESRI:102017. - Asynchronous
proj4registration finishes insidePendingTasksbefore@ifmounts the projectedaol-view. - Local Mapbox GL styling and background apply cleanly in both Angular and React adapters without duplicating source setup.
- Metre-based view resolutions stay decoupled from the degree-based source tile matrix.
Pitfalls
- Never set the
VectorTilesource projection toESRI:102017when the tiles themselves are cut inEPSG:4326: the source must keepprojection="EPSG:4326"so OpenLayers knows what CRS to reproject decoded vertices from. - Always register custom
proj4definitions before instantiatingViewor transforming [center] /[extent]coordinates, otherwise OpenLayers cannot look up the target CRS.
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.