Motivation
Currently, a Mapbox access token must be set on the global mapboxgl library object. There are some use cases that require multiple maps on a page, each using a different access token.
Design Alternatives
- Do nothing
It's technically possible to use the Map's transformRequest option to get different maps using different access tokens via something like:
mapboxgl.accessToken = '<access token>' // placeholder
var map1 = new mapboxgl.Map({
container: container,
style: style,
transformRequest: (url) => ({url: url.replace('<access token>', token_1)})
});
var map2 = new mapboxgl.Map({
container: container,
style: style,
transformRequest: (url) => ({url: url.replace('<access token>', token_2)})
});
- Accept
accessToken as a Map option that takes precedence over mapboxgl.accessToken.
Design
While option 1 above works, I think it would be better to address this use case more directly via option 2.
Mock-Up
mapboxgl.accessToken = token_1;
var map1 = new mapboxgl.Map({ // defaults to `mapboxgl.accessToken`
container: container,
style: style,
});
var map2 = new mapboxgl.Map({
container: container,
style: style,
accessToken: token_2 // overrides `mapboxgl.accessToken`
});
Motivation
Currently, a Mapbox access token must be set on the global
mapboxgllibrary object. There are some use cases that require multiple maps on a page, each using a different access token.Design Alternatives
It's technically possible to use the Map's
transformRequestoption to get different maps using different access tokens via something like:accessTokenas aMapoption that takes precedence overmapboxgl.accessToken.Design
While option 1 above works, I think it would be better to address this use case more directly via option 2.
Mock-Up