2

Can't define options for source attribution. What is the right way to do this?

Tried this two approaches> (My attribution does not change: is open and with default labels )

 var tile_photo = new ol.layer.Tile({
        source: new ol.source.TileWMS({
            attributions: [
                new ol.Attribution({
                    html: '<a href="http://link">TEXT</a>',
                    collapsed:true,
                    tipLabel:'My attribution'
                })
            ],
           ...............

        })
});

and

source: new ol.source.TileWMS({
            attributions: [
                new ol.Attribution({
                    html: '<a href="http://link">TEXT</a>',
                    options: {
                        collapsible: true,
                        label: 'A',
                        collapsed: true,
                        tipLabel: 'yooo'
                    }
                })
            ],
.........
6

It's because you are using options in the wrong place:

Refering to the API doc ol.Attribution accepts only html as an option.

You have to change the default control for attribution and it's done using an ol.control.Attribution. See the doc about this control.

You should create a new control like below (borrowed from attribution official sample)

var attribution = new ol.control.Attribution({
  collapsible: true,
  label: 'A',
  collapsed: true,
  tipLabel: 'yooo'
});

and in the map add

var map = new ol.Map({
  target: 'map',
  controls: ol.control.defaults({ attribution: false }).extend([attribution])
});

The ol.control.defaults({ attribution: false }).extend([attribution]) means use default controls except the default attribution (attribution: false) and then add the new attribution object to list of controls using an array (.extend([attribution]))

  • I don't know why, but adding new attribution control like that is not working for me. Attribution is added only if I add it after map is created like that map.addControl(newAttribution); But I can't remove default attribution. How can I get to it in form of map.removeControl(?) ? – Anuket Nov 28 '14 at 18:22
  • and if I define className to my new attribution control, it dissapears. Do I need to specify this class then somewhere in the sourse, when I define html for attribution? – Anuket Nov 28 '14 at 18:28
  • Just add controls: ol.control.defaults({ attribution: false }) and use the map.addControl(newAttribution); Is it better? – ThomasG77 Nov 28 '14 at 19:18
  • I tried controls: ol.control.defaults({ attribution: false }) but it didn't work for me and I had two attributions on each other. – Anuket Nov 29 '14 at 7:01

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.