I'm having trouble figuring out how to add a custom attribution to my maps in addition to the standard attributions already added. When I call..... map.addControl(new mapboxgl.Attribution()); where do I add a custom string? Probably a stupid question, but just trying to do the right thing with attributions before I share the awesomeness that is customized Mapbox GL maps.
Good question. Unfortunately there's not a good way to add a custom attribution right now. We'll look into adding this.
tagging @mapbox/support for known issue
I just encountered this issue as well. Would it be possible to add an additional attribution key to the different source objects that let us specify custom attributions? For example:
"geojson-marker": {
"type": "geojson",
"data": { … },
"attribution": "My custom attribution text."
}
Or:
var sourceObj = new mapboxgl.GeoJSONSource({
data: { … },
attribution: "My custom attribution text."
});
I've found custom attribution strings support for vector sources here, but it seems that there is no support for geojson sources according to this discussion.
I've just noticed that, at least for raster sources you can just pass an attribution property to the source options https://www.mapbox.com/mapbox-gl-js/style-spec/#sources-raster (although it's not actually documented there).
Until this is implemented, one workaround is to set the attribution string directly:
map.addLayer({
"id": "attribution-layer",
"type": "circle",
"source": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {},
"geometry": null
}
}
});
map.style.sourceCaches['attribution-layer']._source.attribution = "© foobar";
The equivalent issue for iOS is tracked in mapbox/mapbox-gl-native#9024.
It looks like this issue was closed unintended by #6364 because of the word _close_ in the PR description.
I think to close #1485 we would still need to allow custom attribution strings passed directly to the AttributionControl not attached to any source.
Although there are workarounds available, custom attribution strings are not implemented yet.
@pathmapper You're right passing a fixed string directly to the AttributionControl isn't yet supported, but one workaround is pretty straight forward now:
map.addSource('attribution', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: []
},
attribution: 'Your custom attribution'
});
(until #6281, then you'll need to add a layer too)
closed by #7033
Most helpful comment
@pathmapper You're right passing a fixed string directly to the AttributionControl isn't yet supported, but one workaround is pretty straight forward now:
(until #6281, then you'll need to add a layer too)