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.

Esri's satellite image of western Kraków with the airport at Balice, the Vistula and the Wolski Forest, and a handful of small nature reserves outlined in blue, among them the rocks of Bielany and Przegorzały.
A screenshot of the example. Nature reserves: Generalna Dyrekcja Ochrony Środowiska (GDOŚ). Imagery: Esri World Imagery (Esri, Maxar, Earthstar Geographics and the GIS User Community).

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

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) requests typename=GDOS:Rezerwaty with outputFormat=application/json&srsname=EPSG:4326 and degree bbox.
  • 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 the EPSG:4326 features directly, styled with a 2-pixel blue stroke over Esri World Imagery.

Pitfalls

  • Pay close attention to trailing CRS syntax on GeoServer WFS bbox parameters: ,EPSG:4326 expects 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.

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.