Vector data · Angular, React and OpenLayers
Natura 2000 areas from WFS by extent
Load Natura 2000 habitat polygons around Kraków by viewport extent from GDOŚ’s WFS in OpenLayers using a bbox strategy and stable site codes.

What this example shows
Over Esri satellite imagery of Kraków and its surrounding valleys at zoom 11, Natura 2000 habitat protection areas stream dynamically from GDOŚ’s OGC Web Feature Service as translucent grey polygons outlined in crisp white.
Panning or zooming out fetches additional habitat features strictly for newly uncovered map areas without duplicating reserves already in memory.
When you need it
National environmental registers, cadastral parcel layers and building footprints contain hundreds of thousands of polygons—far too large to download in a single static GeoJSON request.
Pairing an OGC WFS endpoint with OpenLayers’ bounding-box loading strategy fetches only the features intersecting the current viewport and incrementally expands coverage as the user explores.
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.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import type { Extent } from 'ol/extent';
import type Feature from 'ol/Feature';
import type { ReadOptions } from 'ol/format/Feature';
import GeoJSON from 'ol/format/GeoJSON';
import { bbox } from 'ol/loadingstrategy';
import type { FlatStyle } from 'ol/style/flat';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceImageTileComponent,
SourceVectorComponent,
ViewComponent,
} from 'cc-openlayers';
/** The WFS GetFeature request for the Natura 2000 habitat areas within an extent in Web Mercator, as GeoJSON. */
function habitatAreas(extent: Extent): string {
return (
'https://sdi.gdos.gov.pl/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=GDOS:SpecjalneObszaryOchrony&' +
'outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' +
extent.join(',') +
',EPSG:3857'
);
}
/**
* GeoJSON whose features take their Natura 2000 site code as their id. The WFS makes up a new id for every feature
* of every answer, so without it the source could not tell an area it holds from a new one, and would add an area
* again with every extent that reaches it.
*/
class HabitatAreasFormat extends GeoJSON<Feature> {
override readFeatures(source: Parameters<GeoJSON['readFeatures']>[0], options?: ReadOptions): Feature[] {
const features = super.readFeatures(source, options);
for (const feature of features) feature.setId(feature.get('kod'));
return features;
}
}
/**
* The Natura 2000 habitat areas around Kraków from the WFS of the General Directorate for Environmental Protection
* (GDOŚ), loaded as GeoJSON for each extent the map shows (a bbox strategy), over Esri's World Imagery.
*/
@Component({
selector: 'app-vector-wfs',
imports: [
CoordinateComponent,
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]="11" [maxZoom]="19">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<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='Natura 2000: <a href="https://www.gdos.gov.pl/" target="_blank">GDOŚ</a>'
/>
</aol-layer-vector>
</aol-map>
`,
})
export class VectorWfs {
protected readonly url = habitatAreas;
protected readonly format = new HabitatAreasFormat();
protected readonly strategy = bbox;
protected readonly style: FlatStyle = {
'stroke-width': 0.75,
'stroke-color': '#ffffff',
'fill-color': 'rgba(100,100,100,0.25)',
};
} 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.react.tsximport type { Extent } from 'ol/extent.js';
import type Feature from 'ol/Feature.js';
import type { ReadOptions } from 'ol/format/Feature.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import { bbox } from 'ol/loadingstrategy.js';
import type { FlatStyle } from 'ol/style/flat.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
ImageTileSource,
Map,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
/** The WFS GetFeature request for the Natura 2000 habitat areas within an extent in Web Mercator, as GeoJSON. */
function habitatAreas(extent: Extent): string {
return (
'https://sdi.gdos.gov.pl/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=GDOS:SpecjalneObszaryOchrony&' +
'outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' +
extent.join(',') +
',EPSG:3857'
);
}
/**
* GeoJSON whose features take their Natura 2000 site code as their id. The WFS makes up a new id for every feature
* of every answer, so without it the source could not tell an area it holds from a new one, and would add an area
* again with every extent that reaches it.
*/
class HabitatAreasFormat extends GeoJSON<Feature> {
override readFeatures(source: Parameters<GeoJSON['readFeatures']>[0], options?: ReadOptions): Feature[] {
const features = super.readFeatures(source, options);
for (const feature of features) feature.setId(feature.get('kod'));
return features;
}
}
const format = new HabitatAreasFormat();
const style: FlatStyle = {
'stroke-width': 0.75,
'stroke-color': '#ffffff',
'fill-color': 'rgba(100,100,100,0.25)',
};
/**
* The Natura 2000 habitat areas around Kraków from the WFS of the General Directorate for Environmental Protection
* (GDOŚ), loaded as GeoJSON for each extent the map shows (a bbox strategy), over Esri's World Imagery.
*/
export function VectorWfs() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={11} maxZoom={19}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<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={habitatAreas}
format={format}
strategy={bbox}
attributions='Natura 2000: <a href="https://www.gdos.gov.pl/" target="_blank">GDOŚ</a>'
/>
</VectorLayer>
</Map>
);
}How the React version works
Natura 2000 habitat areas from the GDOŚ WFS fetched for each extent shown; a custom GeoJSON format gives them their site code as id, so the source does not add them again.
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.
From Angular to React
| Angular | React |
|---|---|
<aol-source-vector [url] [format] [strategy]> | <VectorSource url format strategy> with module constants |
the layer's [style] | the layer's style: a function or a flat style, constant in the module |
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.
Architecture and OpenLayers mechanics
habitatAreas constructs WFS GetFeature URLs parameterised by the requested bbox and srsname=EPSG:3857 for GeoJSON output, driven by the bbox strategy imported from ol/loadingstrategy whenever the view exposes an unloaded extent.
Because this WFS assigns fresh transient feature identifiers on every HTTP response, HabitatAreasFormat promotes each reserve’s official Natura 2000 site code (kod) to its OpenLayers feature ID so features spanning multiple query boxes are stored once.
How it works
habitatAreasbuilds a GeoJSON WFS GetFeature URL using the requestedbboxin Web Mercator (srsname=EPSG:3857).- The
bboxloading strategy fromol/loadingstrategytriggers requests only for viewport extents not yet loaded. HabitatAreasFormatassigns each decoded feature its persistent Natura 2000kodidentifier to prevent duplicates across overlapping extents.- A flat white stroke and translucent grey fill keep underlying satellite imagery legible.
Pitfalls
- When a WFS omits persistent feature IDs—or generates ephemeral per-response IDs—OpenLayers cannot deduplicate features across overlapping
bboxrequests unless your format assigns a stable domain key such askod. - OpenLayers marks an extent as loaded as soon as its loader runs, even if the network request fails; retrying a failed region requires removing that extent from the vector source’s loaded-extents tracker first.
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.