Skip to content

Special mapboxAccessToken case for Atlas users #919

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

Merged
merged 1 commit into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/plot_api/plot_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ module.exports = {
topojsonURL: 'https://cdn.plot.ly/',

// Mapbox access token (required to plot mapbox trace types)
// If using an Mapbox Atlas server, set this option to '',
// so that plotly.js won't attempt to authenticate to the public Mapbox server.
mapboxAccessToken: null,

// Turn all console logging on or off (errors will be thrown)
Expand Down
3 changes: 3 additions & 0 deletions src/plots/mapbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ function findAccessToken(gd, mapboxIds) {
var fullLayout = gd._fullLayout,
context = gd._context;

// special case for Mapbox Atlas users
if(context.mapboxAccessToken === '') return '';

// first look for access token in context
var accessToken = context.mapboxAccessToken;

Expand Down
26 changes: 26 additions & 0 deletions test/jasmine/tests/mapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,32 @@ describe('mapbox credentials', function() {
done();
});
});

it('should bypass access token in mapbox layout options when config points to an Atlas server', function(done) {
var cnt = 0;
var msg = [
'An API access token is required to use Mapbox GL.',
'See https://www.mapbox.com/developers/api/#access-tokens'
].join(' ');

Plotly.plot(gd, [{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, because there's an error thrown we can't catch yr '' return from plot, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit, ^^ sorry, that doesn't make sense. Ignore.

type: 'scattermapbox',
lon: [10, 20, 30],
lat: [10, 20, 30]
}], {
mapbox: {
accesstoken: MAPBOX_ACCESS_TOKEN
}
}, {
mapboxAccessToken: ''
}).catch(function(err) {
cnt++;
expect(err).toEqual(new Error(msg));
}).then(function() {
expect(cnt).toEqual(1);
done();
});
});
});

describe('mapbox plots', function() {
Expand Down