请求太大或无效的 BBOX



我正在开发一个地理门户,我想使用公共 WMS 服务。我正在使用Openlayers 4.6.4。当我按如下方式设置我的图层时:

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 创建此 URL 以获取磁贴:

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

但随后我从瓷砖服务器收到以下消息:

<?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>

我的问题是双重的:

  1. 正确的 BBOX 格式是什么?
  2. 如何使开放层使用这种正确的格式?

有 3 个问题:

  • 应设置范围以避免在范围之外对 WMS 进行不必要的调用(不良做法,但不是失败的原因(
  • 使用'TILED': true调用 WMS 假定在 GeoServer 中配置了 GeoWebCache(并且失败确认尚未配置它,因为您不拥有它,因此您必须避免此选项;否则,这是一个很好的做法(
  • 混合了 WMS 版本(1.3.0 和 1.1.1(。这并不容易推断,请参阅 https://openlayers.org/en/latest/apidoc/ol.source.TileWMS.html TLDR中params的属性:OpenLayers库中的默认WMS调用是1.3.0。所以,'SRS': 'EPSG:3857'应该'CRS': 'EPSG:3857'

您将在下面进行代码演示(在回答之前进行了内联测试和注释(

<!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>

最新更新