简体   繁体   English

在 OpenLayers 6.9.0 中,我使用 fetch WMTSCapabilities 但它不起作用

[英]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: &copy; <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.

相关问题 我试图用 fetch 更新我的 ejs 页面,但它不起作用 - i tried to upate my ejs page with fetch but it doesn't work 将标记放在OpenLayers中的Geolocation-不起作用 - Put marker at Geolocation in OpenLayers - doesn't work Openlayers中的KML层不适用于localhost - KML layer in Openlayers doesn't work on localhost 绘图在带有Polymer的openlayers3中不起作用 - Drawing doesn't work in openlayers3 with Polymer Openlayers 3 forEachFeatureAtPixel对于Points不能正常工作 - Openlayers 3 forEachFeatureAtPixel doesn't work correctly for Points Rails + Javascript +图形-如果我使用变量,则Javascript不起作用 - Rails + Javascript + Graph - Javascript doesn't work if I use a variable 如果使用ul标签,为什么不能向上滑动? - Why slide up doesn't work if I use ul tag? 当我将它与 onClick 中的其他 function 一起使用时,useState 不起作用 - useState doesn't work when I use it with other function in onClick 当我在 VueJS 中使用 Fetch 调用数据时,jquery 无法正常工作? - jquery doesn't work correctly when I call data with Fetch in VueJS? 除非我使用$ timeout,否则AngularJs不能在指令中进行动画处理 - AngularJs animating in directive doesn't work unless i use $timeout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM