Skip to content

Commit c37eea7

Browse files
committed
Merge pull request #919 from plotly/mapbox-no-request-config
Special mapboxAccessToken case for Atlas users
1 parent 91f03b7 commit c37eea7

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/plot_api/plot_config.js

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ module.exports = {
9090
topojsonURL: 'https://cdn.plot.ly/',
9191

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

9597
// Turn all console logging on or off (errors will be thrown)

src/plots/mapbox/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ function findAccessToken(gd, mapboxIds) {
135135
var fullLayout = gd._fullLayout,
136136
context = gd._context;
137137

138+
// special case for Mapbox Atlas users
139+
if(context.mapboxAccessToken === '') return '';
140+
138141
// first look for access token in context
139142
var accessToken = context.mapboxAccessToken;
140143

test/jasmine/tests/mapbox_test.js

+26
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,32 @@ describe('mapbox credentials', function() {
245245
done();
246246
});
247247
});
248+
249+
it('should bypass access token in mapbox layout options when config points to an Atlas server', function(done) {
250+
var cnt = 0;
251+
var msg = [
252+
'An API access token is required to use Mapbox GL.',
253+
'See https://www.mapbox.com/developers/api/#access-tokens'
254+
].join(' ');
255+
256+
Plotly.plot(gd, [{
257+
type: 'scattermapbox',
258+
lon: [10, 20, 30],
259+
lat: [10, 20, 30]
260+
}], {
261+
mapbox: {
262+
accesstoken: MAPBOX_ACCESS_TOKEN
263+
}
264+
}, {
265+
mapboxAccessToken: ''
266+
}).catch(function(err) {
267+
cnt++;
268+
expect(err).toEqual(new Error(msg));
269+
}).then(function() {
270+
expect(cnt).toEqual(1);
271+
done();
272+
});
273+
});
248274
});
249275

250276
describe('mapbox plots', function() {

0 commit comments

Comments
 (0)