Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0c9681

Browse files
committed
add mapboxAccessToken config arg:
- use it upon instantiating mapbox subplots - throw error if not set (mapboxAccessToken is null by default)
1 parent b93b3b2 commit b0c9681

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/plot_api/plot_config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ module.exports = {
8383
setBackground: defaultSetBackground,
8484

8585
// URL to topojson files used in geo charts
86-
topojsonURL: 'https://cdn.plot.ly/'
86+
topojsonURL: 'https://cdn.plot.ly/',
87+
88+
// Mapbox access token (required to plot mapbox trace types)
89+
mapboxAccessToken: null
8790

8891
};
8992

src/plots/mapbox/constants.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,13 @@
1212

1313
module.exports = {
1414
styleUrlPrefix: 'mapbox://styles/mapbox/',
15-
styleUrlSuffix: 'v9'
15+
styleUrlSuffix: 'v9',
16+
17+
noAccessTokenErrorMsg: [
18+
'Missing Mapbox access token.',
19+
'Mapbox trace type require a Mapbox access token to be registered.',
20+
'For example:',
21+
'Plotly.plot(gd, data, layout, { mapboxAccessToken: \'my-access-token\' });',
22+
'More info here: https://www.mapbox.com/help/define-access-token/'
23+
].join('\n')
1624
};

src/plots/mapbox/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
var mapboxgl = require('mapbox-gl');
1313

1414
var Plots = require('../plots');
15-
var createMapbox = require('./mapbox');
1615
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
1716

18-
var CREDS = require('../../../../creds.json');
17+
var createMapbox = require('./mapbox');
18+
var constants = require('./constants');
1919

2020

2121
exports.name = 'mapbox';
@@ -48,8 +48,12 @@ exports.supplyLayoutDefaults = require('./layout_defaults');
4848

4949
exports.plot = function plotMapbox(gd) {
5050

51-
// TODO maybe this should be a config argument?
52-
mapboxgl.accessToken = CREDS.accessToken;
51+
if(!gd._context.mapboxAccessToken) {
52+
throw new Error(constants.noAccessTokenErrorMsg);
53+
}
54+
else {
55+
mapboxgl.accessToken = gd._context.mapboxAccessToken;
56+
}
5357

5458
var fullLayout = gd._fullLayout,
5559
calcData = gd.calcdata,

0 commit comments

Comments
 (0)