Projections · Angular, React and OpenLayers
A WFS in geographic coordinates
Load GDOŚ nature reserves tile by tile as WGS84 GeoJSON from an OGC WFS in OpenLayers using useGeographic() and a 512px XYZ tile strategy.

What this example shows
Over Esri World Imagery of western Kraków—spanning Balice airport, Las Wolski and the limestone bluffs of Bielany and Przegorzały—nature reserves stream incrementally in 512-pixel tiles from GDOŚ’s WFS in geographic EPSG:4326 degrees and render as crisp 2-pixel blue outlines.
When you need it
Environmental and cadastral WFS endpoints publishing natively in EPSG:4326 integrate cleanly with useGeographic() apps—keeping request bbox envelopes, GeoJSON responses and client features in longitude and latitude from end to end.
Driving WFS queries with a 512-pixel XYZ tile strategy caches loaded grid cells in memory and avoids redundant overlapping requests during small pans.
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-wfs-geographic.shared.tsimport type { Extent } from 'ol/extent.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import { tile } from 'ol/loadingstrategy.js';
import Stroke from 'ol/style/Stroke.js';
import Style from 'ol/style/Style.js';
import { createXYZ } from 'ol/tilegrid.js';
/** The WFS GetFeature request for the nature reserves within an extent in longitude and latitude, as GeoJSON. */
export function natureReserves(extent: Extent): string {
return (
'https://sdi.gdos.gov.pl/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=GDOS:Rezerwaty&' +
'outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' +
extent.join(',') +
',EPSG:4326'
);
}
/** Reads the WFS's answer. */
export const format = new GeoJSON();
/** Loads in tiles of 512 pixels. */
export const strategy = tile(createXYZ({ tileSize: 512 }));
/** The reserves, stroked blue. */
export const style = new Style({ stroke: new Stroke({ color: 'rgba(0, 0, 255, 1.0)', width: 2 }) });vector-wfs-geographic.tsimport { ChangeDetectionStrategy, Component, DestroyRef, inject } from '@angular/core';
import { clearUserProjection, useGeographic } from 'ol/proj';
import {
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceImageTileComponent,
SourceVectorComponent,
ViewComponent,
} from 'cc-openlayers';
import { format, natureReserves, strategy, style } from './vector-wfs-geographic.shared';
/**
* The nature reserves around Kraków from the WFS of the General Directorate for Environmental Protection (GDOŚ),
* asked for in longitude and latitude: `useGeographic()` makes them the map's coordinates while the example is
* shown, so the view's centre and the extents to load are geographic, loaded in 512-pixel tiles.
*/
@Component({
selector: 'app-vector-wfs-geographic',
imports: [
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceImageTileComponent,
SourceVectorComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="12" [maxZoom]="19" [center]="center" />
<aol-layer-tile>
<aol-source-imagetile
url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
[maxZoom]="19"
attributions="Tiles © Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community"
/>
</aol-layer-tile>
<aol-layer-vector [style]="style">
<aol-source-vector
[url]="url"
[format]="format"
[strategy]="strategy"
attributions='Nature reserves: <a href="https://www.gdos.gov.pl/" target="_blank">GDOŚ</a>'
/>
</aol-layer-vector>
</aol-map>
`,
})
export class VectorWfsGeographic {
/** Between the Bielany and Przegorzały rocks, west of the city centre. */
protected readonly center = [19.855, 50.045];
protected readonly url = natureReserves;
protected readonly format = format;
protected readonly strategy = strategy;
protected readonly style = style;
constructor() {
useGeographic();
inject(DestroyRef).onDestroy(clearUserProjection);
}
} 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-wfs-geographic.react.tsximport { useEffect, useState } from 'react';
import { clearUserProjection, useGeographic as setGeographicUserProjection } from 'ol/proj.js';
import {
DefaultControls,
DefaultInteractions,
ImageTileSource,
Map,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
import { format, natureReserves, strategy, style } from './vector-wfs-geographic.shared';
/** Between the Bielany and Przegorzały rocks, west of the city centre. */
const CENTER = [19.855, 50.045];
/**
* The nature reserves around Kraków from the WFS of the General Directorate for Environmental Protection (GDOŚ),
* asked for in longitude and latitude: `useGeographic()` makes them the map's coordinates while the example is
* shown, so the view's centre and the extents to load are geographic, loaded in 512-pixel tiles.
*/
export function VectorWfsGeographic() {
// The view reads the user projection as it mounts, before any passive effect runs; StrictMode clears it with the
// first effect's cleanup, so the effect sets it again.
useState(setGeographicUserProjection);
useEffect(() => {
setGeographicUserProjection();
return clearUserProjection;
}, []);
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={12} maxZoom={19} center={CENTER} />
<TileLayer>
<ImageTileSource
url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
maxZoom={19}
attributions="Tiles © Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community"
/>
</TileLayer>
<VectorLayer style={style}>
<VectorSource
url={natureReserves}
format={format}
strategy={strategy}
attributions='Nature reserves: <a href="https://www.gdos.gov.pl/" target="_blank">GDOŚ</a>'
/>
</VectorLayer>
</Map>
);
}vector-wfs-geographic.shared.tsimport type { Extent } from 'ol/extent.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import { tile } from 'ol/loadingstrategy.js';
import Stroke from 'ol/style/Stroke.js';
import Style from 'ol/style/Style.js';
import { createXYZ } from 'ol/tilegrid.js';
/** The WFS GetFeature request for the nature reserves within an extent in longitude and latitude, as GeoJSON. */
export function natureReserves(extent: Extent): string {
return (
'https://sdi.gdos.gov.pl/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=GDOS:Rezerwaty&' +
'outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' +
extent.join(',') +
',EPSG:4326'
);
}
/** Reads the WFS's answer. */
export const format = new GeoJSON();
/** Loads in tiles of 512 pixels. */
export const strategy = tile(createXYZ({ tileSize: 512 }));
/** The reserves, stroked blue. */
export const style = new Style({ stroke: new Stroke({ color: 'rgba(0, 0, 255, 1.0)', width: 2 }) });How the React version works
The nature reserves around Kraków loaded tile by tile from GDOŚ's WFS as GeoJSON in longitude and latitude, over Esri's imagery, with useGeographic.
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 natureReserves (the WFS URL of an extent), the GeoJSON format, the tile strategy and the blue style from the example's .shared.ts file, so the logic exists once.
From Angular to React
| Angular | React |
|---|---|
useGeographic() in the constructor and clearUserProjection on destroy | useState(setGeographicUserProjection) and a useEffect that sets it again and returns clearUserProjection |
<aol-source-vector [url]="url" [format]="format" [strategy]="strategy"> | <VectorSource url={natureReserves} format={format} strategy={strategy}> |
<aol-view [zoom]="12" [maxZoom]="19" [center]="center" /> | <View zoom={12} maxZoom={19} center={CENTER} /> |
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. useGeographic becomes setGeographicUserProjection, called in a useState initialiser, because the view and the geometries read the user projection while they mount, before any effect runs. StrictMode runs the effect's cleanup (clearUserProjection) once at the start, so the effect sets the projection again; the cleanup also restores it on unmount, as DestroyRef.onDestroy does in Angular.
Architecture and OpenLayers mechanics
With useGeographic() active, OpenLayers passes requested tile extents to [url]="url" (natureReserves) directly in [minLon, minLat, maxLon, maxLat] degrees—allowing extent.join(',') followed by ,EPSG:4326 to build typename=GDOS:Rezerwaty queries with outputFormat=application/json&srsname=EPSG:4326.
Loading strategy tile(createXYZ({ tileSize: 512 })) partitions queries onto a deterministic 512-pixel grid, and new GeoJSON() ingests the degree coordinates directly.
How it works
[url]="url"(natureReserves) requeststypename=GDOS:RezerwatywithoutputFormat=application/json&srsname=EPSG:4326and degreebbox.- Under
useGeographic(),extent.join(',')already contains [minLon, minLat, maxLon, maxLat] ready for,EPSG:4326. tile(createXYZ({ tileSize: 512 }))issues one WFS request per 512-pixel grid cell and skips already loaded cells.new GeoJSON()reads theEPSG:4326features directly, styled with a 2-pixel blue stroke over Esri World Imagery.
Pitfalls
- Pay close attention to trailing CRS syntax on GeoServer WFS
bboxparameters:,EPSG:4326expects longitude-first coordinates, whereas ,urn:ogc:def:crs:EPSG::4326 expects latitude-first coordinates—mixing them queries the wrong part of Earth and returns zero reserves.
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.