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)
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
});
})