OpenLayers v 5.3.0 - get back attribution behavior

2.2k Views Asked by At

In new version v 5.3.0 (ol map library) Changed behavior attribution. Before I had icon "i" and under it all attribution for displayed layers.

enter image description here

enter image description here

Now I have some flattened info.

Developers gave instructions to use the previous behavior:

Attributions are not collapsible for ol/source/OSM

When a map contains a layer from a ol/source/OSM source, the ol/control/Attribution control will be shown with the ``collapsible: false` behavior.

To get the previous behavior, configure the ol/control/Attribution control with collapsible: true.

But how to achieve this?

2

There are 2 best solutions below

1
On BEST ANSWER

The same way as collapsible: false was specified in previous versions (note that it has always been a terms of use requirement of OSM and some other sources that attributions are always visible when their tiles are used on a public facing site)

  import Map from 'ol/Map.js';
  import View from 'ol/View.js';
  import {defaults as defaultControls} from 'ol/control.js';
  import TileLayer from 'ol/layer/Tile.js';
  import OSM from 'ol/source/OSM.js';

  var map = new Map({
    layers: [
      new TileLayer({
        source: new OSM()
      })
    ],
    controls: defaultControls({ attributionOptions: { collapsible: true } }),
    target: 'map',
    view: new View({
      center: [0, 0],
      zoom: 2
    })
  });

or if you are using the full build:

var map = new ol.Map({
  target: 'map',
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    })
  ],
  controls: ol.control.defaults({ attributionOptions: { collapsible: true } }),
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    zoom: 2
  })
});
0
On

Mike I had tried

controls: ol.control.defaults({ attributionOptions: { collapsible: true }).extend([ 
new ol.control.FullScreen(), 
new ol.control.ZoomSlider(), 
new ol.control.Zoom(), ... ]),

And everything it's ok. A huge thanks!