More

Defining attribution in OpenLayers3

Defining attribution in OpenLayers3


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: 'TEXT', collapsed:true, tipLabel:'My attribution' }) ],… }) });

and

source: new ol.source.TileWMS({ attributions: [ new ol.Attribution({ html: 'TEXT', options: { collapsible: true, label: 'A', collapsed: true, tipLabel: 'yooo' } }) ],…

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

Refering to the API docol.Attributionaccepts onlyhtmlas an option.

You have to change the default control for attribution and it's done using anol.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]) });

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


Watch the video: 01. React + OpenLayers. TypeScript. Map, VectorLayer