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.

Esri imagery of Kraków and its surroundings at zoom 11 with the Natura 2000 habitat areas outlined in white.
A screenshot of the example. Natura 2000 habitat areas: Generalna Dyrekcja Ochrony Środowiska (GDOŚ). Imagery: Esri World Imagery (Esri, Maxar, Earthstar Geographics and the GIS User Community).

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

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

  • habitatAreas builds a GeoJSON WFS GetFeature URL using the requested bbox in Web Mercator (srsname=EPSG:3857).
  • The bbox loading strategy from ol/loadingstrategy triggers requests only for viewport extents not yet loaded.
  • HabitatAreasFormat assigns each decoded feature its persistent Natura 2000 kod identifier 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 bbox requests unless your format assigns a stable domain key such as kod.
  • 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.

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.