From e4fbc137b563dd3eb7bfd5a23bd318138868a864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 8 Sep 2016 15:10:32 -0400 Subject: [PATCH] mapbox: add special mapboxAccessToken case for Atlas users - setting mapboxAccessToken to '', guarantees that plotly.js will not attempt to make request to the public mapbox server regardless of what layout.mapbox.accesstoken is set to. --- src/plot_api/plot_config.js | 2 ++ src/plots/mapbox/index.js | 3 +++ test/jasmine/tests/mapbox_test.js | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/plot_api/plot_config.js b/src/plot_api/plot_config.js index 71635c0d816..107d2800d97 100644 --- a/src/plot_api/plot_config.js +++ b/src/plot_api/plot_config.js @@ -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) diff --git a/src/plots/mapbox/index.js b/src/plots/mapbox/index.js index e7ab347d07b..875417fa653 100644 --- a/src/plots/mapbox/index.js +++ b/src/plots/mapbox/index.js @@ -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; diff --git a/test/jasmine/tests/mapbox_test.js b/test/jasmine/tests/mapbox_test.js index 043af340a14..867c99c6e1c 100644 --- a/test/jasmine/tests/mapbox_test.js +++ b/test/jasmine/tests/mapbox_test.js @@ -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, [{ + 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() {