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.

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.tsimport { 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' : '';
}
} 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.
getfeatureinfo-image.react.tsximport DOMPurify from 'dompurify';
import { useRef, useState } from 'react';
import type { MapBrowserEvent } from 'ol';
import type OLMap from 'ol/Map.js';
import type OLImageLayer from 'ol/layer/Image.js';
import type ImageWMS from 'ol/source/ImageWMS.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
ImageLayer,
ImageWMSSource,
Map,
OSMSource,
TileLayer,
View,
} from 'cc-openlayers/react';
const wmsParams = { LAYERS: 'dzialki' };
/** 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. */
export function GetfeatureinfoImage() {
const [info, setInfo] = useState('');
const map = useRef<OLMap>(null);
const layer = useRef<OLImageLayer<never>>(null);
const source = useRef<ImageWMS>(null);
/** Requests the HTML description of the feature under the click from the service and shows it. */
const showInfo = (event: MapBrowserEvent) => {
setInfo('');
const resolution = map.current?.getView().getResolution();
if (resolution === undefined) return;
const url = source.current?.getFeatureInfoUrl(event.coordinate, resolution, 'EPSG:3857', {
INFO_FORMAT: 'text/html',
});
if (!url) return;
fetch(url)
.then((response) => response.text())
.then((html) => setInfo(html));
};
/** A pointer cursor over a pixel the layer has drawn (an opaque one), the default one elsewhere. */
const showCursor = (event: MapBrowserEvent) => {
if (event.dragging) return;
const data = layer.current?.getData(event.pixel) as ArrayLike<number> | null | undefined;
const hit = data && data[3] > 0;
const target = map.current?.getTargetElement();
if (target) target.style.cursor = hit ? 'pointer' : '';
};
return (
<>
<Map ref={map} height="480px" onSingleClick={showInfo} onPointerMove={showCursor}>
<DefaultInteractions />
<DefaultControls />
<View zoom={17}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<ImageLayer ref={layer}>
<ImageWMSSource
ref={source}
url="https://integracja.gugik.gov.pl/cgi-bin/KrajowaIntegracjaEwidencjiGruntow"
params={wmsParams}
crossOrigin="anonymous"
/>
</ImageLayer>
</Map>
<div className="example-controls">
<p className="example-hint">Click a parcel to see its data.</p>
<div className="example-info" dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(info) }} />
</div>
</>
);
}How the React version works
Parcels from the national cadastre integration as a WMS image: a click asks the service for the parcel data (HTML), and the cursor turns into a hand over drawn pixels.
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 |
|---|---|
(singleClick), (pointerMove) | onSingleClick, onPointerMove |
[innerHTML]="info()" (Angular removes scripts and event attributes itself) | dangerouslySetInnerHTML with DOMPurify.sanitize(info): React sanitises nothing, so DOMPurify does it |
viewChild of the layer and the source | two useRef calls |
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
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 viagetFeatureInfoUrlusing the click coordinate, view resolution andINFO_FORMATset totext/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 withgetData(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.
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.