Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom attribution strings #1485

Closed
Tracked by #229
AlanPew opened this issue Sep 14, 2015 · 11 comments · Fixed by #6364
Closed
Tracked by #229

Support custom attribution strings #1485

AlanPew opened this issue Sep 14, 2015 · 11 comments · Fixed by #6364
Assignees

Comments

@AlanPew
Copy link

AlanPew commented Sep 14, 2015

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.

@jfirebaugh
Copy link
Contributor

Good question. Unfortunately there's not a good way to add a custom attribution right now. We'll look into adding this.

@lyzidiamond
Copy link
Contributor

tagging @mapbox/support for known issue

@nilshoerrmann
Copy link

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."
});

@stepankuzmin
Copy link
Contributor

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.

@andrewharvey
Copy link
Collaborator

andrewharvey commented Mar 3, 2017

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).

@andrewharvey
Copy link
Collaborator

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";

@1ec5
Copy link
Contributor

1ec5 commented Jul 6, 2017

The equivalent issue for iOS is tracked in mapbox/mapbox-gl-native#9024.

@pathmapper
Copy link
Contributor

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.

@andrewharvey andrewharvey reopened this Jul 10, 2018
@andrewharvey
Copy link
Collaborator

@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)

@andrewharvey
Copy link
Collaborator

closed by #7033

@jfoshee
Copy link

jfoshee commented Jun 25, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.