Tile and image services · Angular, React and OpenLayers

A parcel's data from a WMS image

Query cadastral parcel attributes on click from GUGiK’s national land-registry WMS in OpenLayers using getFeatureInfoUrl and pixel hit tests.

Land parcels in the centre of Kraków at zoom 17 over OpenStreetMap, and below the map the registry's table for the parcel clicked in the Main Square.
A screenshot of the example. Land parcels: Krajowa Integracja Ewidencji Gruntów © GUGiK. Map data © OpenStreetMap contributors.

What this example shows

Zoomed to street-and-parcel level 17 in central Kraków, cadastral parcel boundaries stream as a single WMS image over OpenStreetMap. Moving the pointer over drawn parcel lines switches the cursor to an interactive hand, and clicking any parcel fetches its official cadastral identifier, precinct and area table from GUGiK’s national integration service into the panel below.

When you need it

A WMS layer delivers flat raster pixels containing zero client-side attributes, yet cadastral viewers, zoning portals and utility maps must let users click any parcel or pipe to inspect its database record.

OGC GetFeatureInfo bridges raster display and attribute inspection with a lightweight point query against the WMS server.

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.

getfeatureinfo-image.ts
import { ChangeDetectionStrategy, Component, signal, viewChild } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerImageComponent,
  LayerTileComponent,
  MapComponent,
  SourceImageWMSComponent,
  SourceOsmComponent,
  ViewComponent,
} from 'cc-openlayers';
import type { MapBrowserEvent } from 'ol';

/** Land parcels as a single WMS image: a click asks the service for the parcel's data, and the pointer shows where parcels are drawn. */
@Component({
  selector: 'app-getfeatureinfo-image',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerImageComponent,
    LayerTileComponent,
    MapComponent,
    SourceImageWMSComponent,
    SourceOsmComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px" (singleClick)="showInfo($event)" (pointerMove)="showCursor($event)">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="17"><aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" /></aol-view>
      <aol-layer-tile><aol-source-osm /></aol-layer-tile>
      <aol-layer-image>
        <aol-source-imagewms
          url="https://integracja.gugik.gov.pl/cgi-bin/KrajowaIntegracjaEwidencjiGruntow"
          [params]="{ LAYERS: 'dzialki' }"
          crossOrigin="anonymous"
        />
      </aol-layer-image>
    </aol-map>
    <div class="example-controls">
      <p class="example-hint">Click a parcel to see its data.</p>
      <div class="example-info" [innerHTML]="info()"></div>
    </div>
  `,
})
export class GetfeatureinfoImage {
  readonly info = signal('');
  private readonly map = viewChild.required(MapComponent);
  private readonly layer = viewChild.required(LayerImageComponent);
  private readonly source = viewChild.required(SourceImageWMSComponent);

  /** Requests the HTML description of the feature under the click from the service and shows it. */
  protected showInfo(event: MapBrowserEvent): void {
    this.info.set('');
    const resolution = this.map().instance.getView().getResolution();
    if (resolution === undefined) return;
    const url = this.source().instance.getFeatureInfoUrl(event.coordinate, resolution, 'EPSG:3857', {
      INFO_FORMAT: 'text/html',
    });
    if (!url) return;
    fetch(url)
      .then((response) => response.text())
      .then((html) => this.info.set(html));
  }

  /** A pointer cursor over a pixel the layer has drawn (an opaque one), the default one elsewhere. */
  protected showCursor(event: MapBrowserEvent): void {
    if (event.dragging) return;
    const data = this.layer().instance.getData(event.pixel);
    const hit = data && data[3] > 0;
    this.map().instance.getTargetElement().style.cursor = hit ? 'pointer' : '';
  }
}

Architecture and OpenLayers mechanics

On (singleClick), the component calls getFeatureInfoUrl on the image WMS source with the clicked map coordinate, active view resolution and an INFO_FORMAT of text/html. Internally OpenLayers constructs a deterministic 101 × 101 pixel virtual context around the click so hit accuracy stays independent of viewport dimensions, and binds the returned markup through [innerHTML] cleaned by Angular’s HTML sanitizer.

For responsive cursor affordance, (pointerMove) samples the rendered WMS canvas pixel via getData and switches to a pointer hand wherever alpha (data[3] > 0) indicates non-transparent parcel content.

How it works

  • (singleClick) builds an OGC query via getFeatureInfoUrl using the click coordinate, view resolution and INFO_FORMAT set to text/html.
  • OpenLayers evaluates the query inside a fixed 101 × 101 pixel window centred on the click regardless of overall map size.
  • Binding [innerHTML] passes the server’s HTML response through Angular’s built-in sanitizer to strip unsafe scripts or inline handlers.
  • (pointerMove) inspects pixel alpha with getData (data[3] > 0) so the hand cursor appears strictly over rendered parcel strokes.

Pitfalls

  • Many WMS servers return a complete HTML document with head, title and style elements for text/html: HTML sanitizers strip embedded style blocks while preserving title text, which can echo the parcel ID above the attribute table.
  • Federated national WMS aggregators forward requests to county servers on the fly—if an individual county endpoint times out, both its parcel lines and click responses may be temporarily empty.

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.