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.

Poland at zoom 6 with the boundaries of its counties in pink and their names in black, over OpenStreetMap.
A screenshot of the example. Administrative boundaries © GUGiK. Map data © OpenStreetMap contributors.

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

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] on aol-layer-image restricts 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 the A02_Granice_powiatow county layer while [ratio] of 1 sizes requests to the exact visible intersection.

Pitfalls

  • Omitting serverType disables 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].

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.