Creating an API token

With the new account comes the Account Dashboard, which supplies an API access token by default. This public access token or key begins with pk and is a long string of characters. This API access token is used to authenticate all of the maps and apps that will be built using this account. Copy the string of characters and add it to your maps:

To create a new API access token, push the Create a token button and select the access levels that it will allow:

Within the JavaScript code, the API access token is passed to the MapboxGL object to enable access to tiles and tools. Here is a simple web map using HTML/JavaScript as an example of how the access token is used to create a map. Replace the access token mentioned in the following code with your own public access token:

<html><head>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.css' rel='stylesheet' />
</head><body>
<div id='map' style='width: 400px; height: 300px;'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoibG9raXByZXNpZGVud0.8S8l9kH4Ws_ES_ZCjw2i8A';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9'
});
</script></body></html>

Save this code as "index.html", and open it using a browser to see the simple map. Make sure that you replace the API access token in the earlier example with your own key, or the map will not appear. 

Explore the documentation to understand the various configurations available for the API access token:
https://www.mapbox.com/help/how-access-tokens-work/.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset