Tile and image services · Angular, React and OpenLayers
A protected area's data from WMS tiles
Query Natura 2000 protected bird areas on click from a tiled GeoServer WMS in OpenLayers using TileWMS getFeatureInfoUrl and text/plain.

What this example shows
Around Kraków at zoom 9, Natura 2000 Special Protection Areas for birds—such as Puszcza Niepołomicka—render as tiled WMS polygons over OpenStreetMap. Hovering over any shaded reserve turns the cursor into a hand, and clicking displays the reserve’s official name and European site code in a clean plain-text readout below the map.
When you need it
Environmental, geological and planning portals often prefer tiled WMS (TileWMS) over single-image WMS for fast browser caching while still needing accurate point attribute inspection on click.
OpenLayers’ TileWMS source exposes the exact same getFeatureInfoUrl signature as ImageWMS—translating map clicks into tile-local pixel indices automatically.
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-tile.tsimport { ChangeDetectionStrategy, Component, signal, viewChild } from '@angular/core';
import type MapBrowserEvent from 'ol/MapBrowserEvent';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
SourceTileWMSComponent,
ViewComponent,
} from 'cc-openlayers';
/**
* Natura 2000 bird areas around Kraków as a tiled WMS of the GeoServer of Poland's General Directorate for
* Environmental Protection: a click asks the service about the area under it in plain text, and the pointer turns into
* a hand over the areas' pixels.
*/
@Component({
selector: 'app-getfeatureinfo-tile',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
SourceTileWMSComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px" (singleClick)="query($event)" (pointerMove)="hover($event)">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="9"><aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" /></aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-tile #areas>
<aol-source-tilewms
url="https://sdi.gdos.gov.pl/wms"
[params]="{ LAYERS: 'GDOS:ObszarySpecjalnejOchrony', TILED: true }"
crossOrigin="anonymous"
attributions="Natura 2000: GDOŚ"
/>
</aol-layer-tile>
</aol-map>
<div class="example-controls">
<p class="example-hint">Click a bird area to see its data.</p>
<pre>{{ info() }}</pre>
</div>
`,
})
export class GetfeatureinfoTile {
readonly info = signal('');
private readonly map = viewChild.required(MapComponent);
private readonly view = viewChild.required(ViewComponent);
private readonly areas = viewChild.required<LayerTileComponent>('areas');
private readonly source = viewChild.required(SourceTileWMSComponent);
protected query(event: MapBrowserEvent): void {
this.info.set('');
const url = this.source().instance.getFeatureInfoUrl(
event.coordinate,
this.view().instance.getResolution() as number,
'EPSG:3857',
{ INFO_FORMAT: 'text/plain' }
);
if (url) {
void fetch(url)
.then((response) => response.text())
.then((text) => this.info.set(text));
}
}
protected hover(event: MapBrowserEvent): void {
if (event.dragging) return;
const data = this.areas().instance.getData(event.pixel) as ArrayLike<number> | null;
const hit = !!data && data[3] > 0; // transparent pixels have zero for data[3]
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-tile.react.tsximport { useRef, useState } from 'react';
import type OLMap from 'ol/Map.js';
import type MapBrowserEvent from 'ol/MapBrowserEvent.js';
import type OLTileLayer from 'ol/layer/Tile.js';
import type OLView from 'ol/View.js';
import type TileWMS from 'ol/source/TileWMS.js';
import type TileSource from 'ol/source/Tile.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
TileLayer,
TileWMSSource,
View,
} from 'cc-openlayers/react';
const wmsParams = { LAYERS: 'GDOS:ObszarySpecjalnejOchrony', TILED: true };
/**
* Natura 2000 bird areas around Kraków as a tiled WMS of the GeoServer of Poland's General Directorate for
* Environmental Protection: a click asks the service about the area under it in plain text, and the pointer turns into
* a hand over the areas' pixels.
*/
export function GetfeatureinfoTile() {
const [info, setInfo] = useState('');
const map = useRef<OLMap>(null);
const view = useRef<OLView>(null);
const areas = useRef<OLTileLayer<TileSource>>(null);
const source = useRef<TileWMS>(null);
const query = (event: MapBrowserEvent) => {
setInfo('');
const url = source.current?.getFeatureInfoUrl(
event.coordinate,
view.current?.getResolution() as number,
'EPSG:3857',
{
INFO_FORMAT: 'text/plain',
}
);
if (url) {
void fetch(url)
.then((response) => response.text())
.then((text) => setInfo(text));
}
};
const hover = (event: MapBrowserEvent) => {
if (event.dragging) return;
const data = areas.current?.getData(event.pixel) as ArrayLike<number> | null | undefined;
const hit = !!data && data[3] > 0; // transparent pixels have zero for data[3]
const target = map.current?.getTargetElement();
if (target) target.style.cursor = hit ? 'pointer' : '';
};
return (
<>
<Map ref={map} height="480px" onSingleClick={query} onPointerMove={hover}>
<DefaultInteractions />
<DefaultControls />
<View ref={view} zoom={9}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<TileLayer ref={areas}>
<TileWMSSource
ref={source}
url="https://sdi.gdos.gov.pl/wms"
params={wmsParams}
crossOrigin="anonymous"
attributions="Natura 2000: GDOŚ"
/>
</TileLayer>
</Map>
<div className="example-controls">
<p className="example-hint">Click a bird area to see its data.</p>
<pre>{info}</pre>
</div>
</>
);
}How the React version works
Bird areas from the GDOŚ service as WMS tiles: a click asks for the area under the cursor (plain text), and the cursor changes over painted 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 |
<aol-source-tilewms> | <TileWMSSource> with a ref for getFeatureInfoUrl |
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
When clicked, getFeatureInfoUrl on the tiled WMS source identifies the specific 256 × 256 tile covering that coordinate, computes the intra-tile column and row offsets (I and J in WMS 1.3.0), and requests INFO_FORMAT text/plain for display inside a pre block.
During (pointerMove), getData reads the RGBA tuple of the rendered tile pixel under the pointer, showing a hand cursor strictly where alpha is non-zero while attributions credits GDOŚ on the map.
How it works
getFeatureInfoUrlon the tiled WMS source resolves the 256-pixel tile under the click and calculates its internal I and J pixel coordinates.- Requesting
INFO_FORMATtext/plainreturns human-readable attribute lines rendered directly inside apreelement. (pointerMove)checks tile pixel alpha viagetDataso empty transparent areas keep the default panning cursor.attributionsdisplays GDOŚ’s environmental data credit in the map corner.
Pitfalls
- Inspecting tile pixel alpha with
getDatarequires CORS-cleared images: omittingcrossOrigin(or querying a non-CORS server) taints the canvas, makesgetDatareturn null, and prevents the hover cursor from ever activating. - Unlike GML or GeoJSON,
text/plainformatting is completely vendor-specific—GeoServer prints attribute and value pairs whereas some MapServer setups output bare feature IDs, so verify each service’s supported formats in GetCapabilities.
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.