【问题标题】:In OpenLayers 6.9.0 I use fetch WMTSCapabilities but I it doesn't work在 OpenLayers 6.9.0 中,我使用 fetch WMTSCapabilities 但它不起作用
【发布时间】:2021-12-24 18:21:47
【问题描述】:

我使用 fetch WMTSCapabilities 但我收到以下消息: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Layer') 在 Function.rL.source.WMTS.optionsFromCapabilities (ol.js:2)

这是我使用的代码:

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

【问题讨论】:

    标签: javascript fetch openlayers-6


    【解决方案1】:

    这似乎在optionsFromCapabilities 的这一行从the OpenLayers source 失败:

    export function optionsFromCapabilities(wmtsCap, config) {
      const layers = wmtsCap['Contents']['Layer'];
    

    检查您是否获得了有效的WMTSCapabilities.xml,包括Contents 标签 它应该类似于this xml

    【讨论】:

      【解决方案2】:

      谢谢,我现在已经使用另一种方法,通过像这样编程起源、扩展和解析:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-06-29
        • 1970-01-01
        • 2019-08-07
        • 1970-01-01
        • 1970-01-01
        • 2020-12-26
        • 2015-12-17
        相关资源
        最近更新 更多