Tile and image services · Angular, React and OpenLayers
A WMS image within an extent
Fence a national GUGiK county-boundary WMS image layer inside Poland’s Web Mercator extent and render crisp HiDPI output via MapServer DPI.

What this example shows
At zoom 6 across Poland, all county (powiat) borders in pink and county names in crisp black stream from GUGiK’s national WMS as a single image clipped cleanly to Poland’s bounding box over OpenStreetMap—rendering at native Retina sharpness on high-density displays.
When you need it
National WMS endpoints carry zero features outside their country’s borders, yet an unbounded image layer still dispatches full-screen blank GetMap requests whenever a user pans across neighbouring countries.
Combining a projected layer extent with explicit serverType DPI scaling eliminates wasted out-of-country requests and fixes blurry 1x WMS text on modern 2x/3x laptops and phones.
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.
wms-image.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerImageComponent,
LayerTileComponent,
MapComponent,
SourceImageWMSComponent,
SourceOsmComponent,
ViewComponent,
} from 'cc-openlayers';
/** Poland's county boundaries from a WMS as one image over OpenStreetMap, limited to the country's extent. */
@Component({
selector: 'app-wms-image',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerImageComponent,
LayerTileComponent,
MapComponent,
SourceImageWMSComponent,
SourceOsmComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="6"><aol-coordinate [x]="19.4" [y]="52.1" srid="EPSG:4326" /></aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-image [extent]="extent">
<aol-source-imagewms
url="https://mapy.geoportal.gov.pl/wss/service/PZGIK/PRG/WMS/AdministrativeBoundaries"
[params]="{ LAYERS: 'A02_Granice_powiatow' }"
[ratio]="1"
serverType="mapserver"
attributions="Administrative boundaries © GUGiK"
/>
</aol-layer-image>
</aol-map>
`,
})
export class WmsImage {
/** Poland in Web Mercator. */
protected readonly extent = [1525077, 6207260, 2771855, 7381298];
} 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.
wms-image.react.tsximport {
Coordinate,
DefaultControls,
DefaultInteractions,
ImageLayer,
ImageWMSSource,
Map,
OSMSource,
TileLayer,
View,
} from 'cc-openlayers/react';
/** Poland in Web Mercator. */
const extent = [1525077, 6207260, 2771855, 7381298];
const params = { LAYERS: 'A02_Granice_powiatow' };
/** Poland's county boundaries from a WMS as one image over OpenStreetMap, limited to the country's extent. */
export function WmsImage() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={6}>
<Coordinate x={19.4} y={52.1} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<ImageLayer extent={extent}>
<ImageWMSSource
url="https://mapy.geoportal.gov.pl/wss/service/PZGIK/PRG/WMS/AdministrativeBoundaries"
params={params}
ratio={1}
serverType="mapserver"
attributions="Administrative boundaries © GUGiK"
/>
</ImageLayer>
</Map>
);
}How the React version works
County borders from GUGiK's WMS as one image at ratio 1 (exactly the visible extent), only within Poland's extent.
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 |
|---|---|
<aol-layer-image [extent]> with <aol-source-imagewms [ratio]="1"> | <ImageLayer extent> with <ImageWMSSource ratio={1}> |
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
Setting [extent] on aol-layer-image in Web Mercator metres restricts WMS GetMap requests strictly to the intersection of the current viewport and Poland’s bounding box—asking for nothing when Poland leaves the screen.
Configuring serverType="mapserver" enables OpenLayers’ vendor-specific HiDPI negotiation: on a 2x Retina screen, OpenLayers doubles requested pixel width/height and appends MAP_RESOLUTION=180 (90 * pixelRatio) so MapServer scales stroke widths and font sizes proportionally.
How it works
[extent]onaol-layer-imagerestricts WMS GetMap requests and rendering to Poland’s projected Web Mercator bounding box.serverType="mapserver"requests device-pixel-ratio image dimensions and passes MAP_RESOLUTION (90 × ratio) for crisp Retina typography.[params]selects theA02_Granice_powiatowcounty layer while[ratio]of1sizes requests to the exact visible intersection.
Pitfalls
- Omitting
serverTypedisables vendor DPI scaling, causing OpenLayers to stretch 1x CSS-pixel bitmaps that look noticeably fuzzy on Retina monitors and phones. - Always convert EX_GeographicBoundingBox degree coordinates from WMS capabilities into your view’s projection before assigning layer
[extent].
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.