Malcolm
Malcolm

Reputation: 473

How do I add custom attribution to the default mapbox-gl attribution control?

attributionControl: true

Does nothing. Where do I need to put the attribution in the mapbox-gl style so that it shows up in the control?

Upvotes: 4

Views: 5302

Answers (5)

hoogw
hoogw

Reputation: 5525

---- 2023 update ----

here is official mapbox document and example

https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol

here is my working code,

enter image description here

Upvotes: -1

to4st
to4st

Reputation: 21

Meanwhile the feature is available https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol

Upvotes: 1

naSSa
naSSa

Reputation: 56

For those that still wondering about this. Mapbox have made a good workaround for this as described in Mapbox issue #1485.

I'm simply copying the solution provided by a collaborator of Mapbox:

map.addSource('attribution', {
type: 'geojson',
data: {
  type: 'FeatureCollection',
  features: []
},
attribution: 'Your custom attribution'
});

Upvotes: 3

Camilo
Camilo

Reputation: 169

You can also work around with HTML/CSS + Mapbox CSS Styles by including and positioning a div inside the map div wrapper by using the mapboxgl-ctrl-attrib classes (example):

<div id="map">
    <!-- Modify the style: right position so it matches with the mapbox attribution -->
    <div id="attribution" class="mapboxgl-ctrl mapboxgl-ctrl-attrib mapboxgl-ctrl-bottom-right" style="position: fixed; bottom: 0; right: 230px;">
        <a href="*">Attribution 1</a> &nbsp;|&nbsp; 
        <a href="*">Attribution 2</a>  &nbsp;|&nbsp;
        <a href="*">Attribution n</a> &nbsp;|
    </div>
</div>

Upvotes: 1

Lucas Wojciechowski
Lucas Wojciechowski

Reputation: 3802

This feature is not yet implemented. It is sorely missing. Would you consider submitting a PR? https://github.com/mapbox/mapbox-gl-js/issues/1485

Upvotes: 1

Related Questions