目录
加载WMTS图层影像
在Geoserver欢迎界面点击右侧WMTS服务,打开xml文件,找到要发布的图层,复制url(Geoserver版本不同url结构略有差异)。
修改url,将{TileMatrix}改为{TileMatrixSet}:{TileMatrix}。图层预览时可以看到发送的Request URL中TileMatrix参数值为EPSG:900913:11,是TileMatrixSet:TileMatrix的形式。
代码如下,如果选择EPSG:4326,还需要添加tilingScheme: new Cesium.GeographicTilingScheme()
let wmtsImageryProvider = new Cesium.WebMapTileServiceImageryProvider({
url: "http://localhost:8090/geoserver/gwc/rest/wmts/Cesium:S40PGWGS1984/{style}/{TileMatrixSet}/{TileMatrixSet}:{TileMatrix}/{TileRow}/{TileCol}?format=image/png",
style: "",
tileMatrixSetID: "EPSG:900913",
// tileMatrixSetID: "EPSG:4326",
// tilingScheme: new Cesium.GeographicTilingScheme(),
});
viewer.imageryLayers.addImageryProvider(wmtsImageryProvider);
解决401错误
加载后控制台报错401,网页弹出登录Geoserver账号界面,按要求登录后可以显示影像,原因是未进行用户名密码验证,请求头中没有传入授权验证。关闭Geoserver请求的过滤器,Security->>Authentication->>Filter Chains中删除gwc过滤器。也可以在请求头中添加用户名密码,参考https://blog.csdn.net/weixin_42047398/article/details/107400129