WMSSource
Quick answer
WMSSource is ol.source.ImageWMS, an image source that requests one GetMap response per view and drapes it over an image layer. Required url and params carry LAYERS, VERSION and STYLES; ratio, hidpi, serverType, crossOrigin and attributions tune requests. Use updateParams to switch layers and getFeatureInfoUrl to query attributes at a coordinate.
new ol.source.ImageWMS( options )
Key points
- updateParams merges new request parameters and immediately refetches the image.
- getFeatureInfoUrl returns undefined when parameters are incomplete or projection conversion fails.
- ratio defaults to 1.5, prefetching beyond the viewport to reduce blank gaps while panning.
Example
var wms = new ol.source.ImageWMS({
url: 'https://example.com/geoserver/wms',
params: {
LAYERS: 'demo:landuse',
VERSION: '1.3.0',
STYLES: '',
FORMAT: 'image/png',
TRANSPARENT: true
},
serverType: 'geoserver',
ratio: 1.5,
crossOrigin: 'anonymous'
});
var layer = new ol.layer.Image({ source: wms, opacity: 0.8 });
wms.updateParams({ LAYERS: 'demo:roads' });
map.on('singleclick', function (evt) {
var url = wms.getFeatureInfoUrl(
evt.coordinate,
map.getView().getResolution(),
map.getView().getProjection(),
{ INFO_FORMAT: 'application/json' }
);
if (url) { fetch(url).then(function (r) { return r.json(); }).then(console.log); }
});
Notes
- Every pan or zoom issues a new GetMap, so large or multi-layer services respond slower than tiles.
- WMS 1.3.0 with EPSG:4326 puts latitude first, so axis-order mismatches misplace the layer.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). WMSSource. https://www.jingweizhi.com/en/openlayers/api/wms-source.html (accessed 2026-11-03).