1

I'm loading different layers from one WMTS source and want to display the correct attributions for the source of each layer.

In my code I define the attribution at the source-level for a ol.layer.Tile. The layer is later added to the map and display correct, but when I click the i-button on the map it only displays 'undefined'. In the console I don't get any errors.

var parser = new ol.format.WMTSCapabilities();

  fetch('http://wmts1.geoportail.lu/opendata/wmts/1.0.0/WMTSCapabilities.xml').then(function(response) {
    return response.text();
  }).then(function(text) {
    var result = parser.read(text);

    var hybrid_source = ol.source.WMTS.optionsFromCapabilities(result, {
          layer: 'hybrid',
          matrixSet: 'EPSG:3857',
          attributions: [new ol.Attribution({
                    html: '<a href="https://data.public.lu" target="_blank">data.public.lu</a> Hybrid @ ACT Luxembourg'
                    })]
    });

    var hybrid_layer = new ol.layer.Tile({
          opacity: 1.0,
          title: 'Hybrid',
          baseLayer: true,
          visible: true,              
          source: new ol.source.WMTS(/** @type {!olx.source.WMTSOptions} */ (hybrid_source))
        });
  });
  • I have the same problem now. Did you solve this issue ? – pLumo Jun 15 '18 at 11:19
1

meanwhile I simplified my code to load different WMTS layers in the following way. This works fine for me and the attributions are displayed correctly.

    var baselayers = new ol.layer.Group({
        title: 'Background-Layer',
        layers: [
            new ol.layer.Tile({
                title: 'OSM',
                baseLayer: true,
                visible: false,
                source: new ol.source.OSM({
                attributions: [new ol.Attribution({
                        html: '<a href="https://www.openstreetmap.org" target="_blank">OpenstreetMap</a> OpenstreetMap'
                    })]
                    })
            }),

            new ol.layer.Tile({
                title: 'Basemap HD',
                baseLayer: true,
                visible: false,
                extent: [636757.681558, 6351042.69913, 728716.389785, 6478379.8966],
                source: new ol.source.TileWMS({
                    url: 'https://wmts3.geoportail.lu/opendata/service?',
                    params: {
                        'LAYERS': 'basemap_hd'
                    },
                    attributions: [new ol.Attribution({
                        html: '<br /><a href="https://data.public.lu" target="_blank">data.public.lu</a> Basemap HD @ ACT Luxembourg'
                    })],
                    serverType: 'geoserver'
                })
            })
        ]
     });

var map = new ol.Map({
        target: 'map',
        view: view,
        layers: [baselayers]
    }); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.