[英]In OpenLayers 6.9.0 I use fetch WMTSCapabilities but I it doesn't work
I use fetch WMTSCapabilities but I get this message: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Layer') at Function.rL.source.WMTS.optionsFromCapabilities (ol.js:2)我使用 fetch WMTSCapabilities 但我收到此消息:未捕获(承诺)TypeError:无法读取 Function.rL.source.WMTS.optionsFromCapabilities (ol.js:2) 处未定义的属性(读取“层”)
This is the code I use:这是我使用的代码:
const parser = new ol.format.WMTSCapabilities();
let bgRaster;
fetch('data/WMTSCapabilities.xml')
.then(function (response) {
return response.text();
})
.then(function (text) {
const result = parser.read(text);
const options = ol.source.WMTS.optionsFromCapabilities(result, {
layer: 'standaard',
format: 'image/png',
matrixSet: 'EPSG:28992',
});
bgRaster = new ol.layer.Tile({
opacity: 0.7,
source: new ol.source.WMTS(options),
title: 'Kadaster',
visible: false
});
})
Sorry, that I brought my question so bluntly.对不起,我这么直率地提出了我的问题。 I didn't realize that my request was more or less a staement.
我没有意识到我的要求或多或少是一种要求。 Not my intention.
不是我的本意。 IF you could help me out, I would be very pleased.
如果你能帮助我,我会很高兴。
Regards Boudewijn van Os问候 Boudewijn van Os
This looks like it is failing at this line in optionsFromCapabilities
from the OpenLayers source :看起来它在 OpenLayers 源的
optionsFromCapabilities
中的这一行失败了:
export function optionsFromCapabilities(wmtsCap, config) {
const layers = wmtsCap['Contents']['Layer'];
Check that you are getting a valid WMTSCapabilities.xml
including the Contents
tag It should look similar to this xml检查您是否获得了包含
Contents
标签的有效WMTSCapabilities.xml
它应该类似于这个 xml
Thanks, I've got it working now with another approach, by programming origin,extend and resolution like this:谢谢,我现在用另一种方法让它工作,通过像这样的编程源、扩展和分辨率:
const size = ol.extent.getWidth(projectionExtent) / 256;
// Er zijn 20 (0 tot 19) zoomniveaus beschikbaar van de WMTS-service voor de BGT-Achtergrondkaart:
let matrixIds = new Array(20);
for (let z = 0; z < 10; ++z) {
matrixIds[z] = 'EPSG:3857:0' + z;
}
for (let z = 10; z < 20; ++z) {
matrixIds[z] = 'EPSG:3857:' + z;
}
const bgRaster = new ol.layer.Tile({
extent: projectionExtent,
source: new ol.source.WMTS({
attributions: 'Kaartgegevens: © <a href="https://www.kadaster.nl">Kadaster</a>',
url: 'https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0?',
layer: 'standaard',
matrixSet: 'EPSG:3857',
format: 'image/png',
projection: projection,
tileGrid: new ol.tilegrid.WMTS({
origin: ol.extent.getTopLeft(projectionExtent),
// origin: -285401.92 + "," + 903402.0,
resolutions: resolutions,
matrixIds: matrixIds
}),
style: 'default',
wrapX: false
}),
title: 'Kadaster',
visible: true
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.