I'm working on a geoportal and I want to use a public WMS service. I'm using Openlayers 4.6.4. When I set my layer up as follows:
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'https://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wms',
params: {
'LAYERS': 'Actueel_ortho25',
'TILED': true,
'FORMAT': 'image/jpeg',
'SRS': 'EPSG:3857'
},
serverType: 'geoserver'
})
})
Openlayers creates this URL to get a tile:
https://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fjpeg&TRANSPARENT=true&LAYERS=Actueel_ortho25&TILED=true&SRS=EPSG%3A3857&WIDTH=256&HEIGHT=256&CRS=EPSG%3A3857&STYLES=&BBOX=665613.642307315%2C6602019.007047243%2C665919.3904204557%2C6602324.755160384
But then I received the following message from the tileserver:
<?xml version="1.0"?>
<ServiceExceptionReport version="1.3.0"
xmlns="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/ogc
http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">
<ServiceException>Request too large or invalid BBOX.</ServiceException>
</ServiceExceptionReport>
My question is twofold:
There are 3 issues:
'TILED': true
supposes there is a GeoWebCache configured in GeoServer (and the failure confirms it has not been configured, as you do not own it, you have to avoid this option; otherwise, a good practice)params
in https://openlayers.org/en/latest/apidoc/ol.source.TileWMS.html TLDR: default WMS calls in OpenLayers library are 1.3.0. So, 'SRS': 'EPSG:3857'
should be 'CRS': 'EPSG:3857'
You will a code demo below (tested and commented inline before answering)
<!DOCTYPE html>
<html>
<head>
<title>WMS debug bad extent and geowebcache unwanted</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([5.38722, 52.25865]),
zoom: 6
})
});
var wms = new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'https://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wms',
params: {
'LAYERS': 'Actueel_ortho25',
// Commented because it's supposed to speed up thing as long as it provides call to GeoWebcache to cache WMS as tiles behind the scene but it's what cause the error you got
//'TILED': true,
'FORMAT': 'image/jpeg',
// As default WMS calls in OpenLayers library are 1.3.0, you should use CRS and not CRS
'CRS': 'EPSG:3857'
},
serverType: 'geoserver'
}),
// To avoid blank background from your WMS to spread on the world and avoid making WMS call where there is no photos
// Extent deduced from https://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
extent: [-184488.85727, 6113595.5499, 1383893.54886, 7580462.49937]
});
map.addLayer(wms);
</script>
</body>
</html>