请求太大或 BBOX 无效
Request too large or invalid BBOX
我正在开发地理门户,我想使用 public 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
但随后我从 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>
我的问题是双重的:
- 正确的 BBOX 格式是什么?
- 如何让openlayers使用这个正确的格式?
有 3 个问题:
- 应设置范围以避免在范围外时对 WMS 进行不必要的调用(不好的做法,但不是失败的原因)
- 使用
'TILED': true
调用 WMS 假设在 GeoServer 中配置了 GeoWebCache(失败确认它尚未配置,因为您不拥有它,您必须避免此选项;否则,一个好习惯)
- 有多种 WMS 版本(1.3.0 和 1.1.1)。这并不容易推断,请参阅 https://openlayers.org/en/latest/apidoc/ol.source.TileWMS.html 中的属性
params
TLDR: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>
我正在开发地理门户,我想使用 public 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
但随后我从 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>
我的问题是双重的:
- 正确的 BBOX 格式是什么?
- 如何让openlayers使用这个正确的格式?
有 3 个问题:
- 应设置范围以避免在范围外时对 WMS 进行不必要的调用(不好的做法,但不是失败的原因)
- 使用
'TILED': true
调用 WMS 假设在 GeoServer 中配置了 GeoWebCache(失败确认它尚未配置,因为您不拥有它,您必须避免此选项;否则,一个好习惯) - 有多种 WMS 版本(1.3.0 和 1.1.1)。这并不容易推断,请参阅 https://openlayers.org/en/latest/apidoc/ol.source.TileWMS.html 中的属性
params
TLDR: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>