Show loading screen

Use events to show when features are loading and loaded by displaying and hiding a loading message

<!DOCTYPE html>
<meta charset=utf-8 />
<title>Show loading screen</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src=''></script>
<link href='' rel='stylesheet' />
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }

 * This is a very simple version of a 'loading screen': there are much
 * fancier ones you can use instead, like
#loader {
    position:absolute; top:0; bottom:0; width:100%;
    background:rgba(255, 255, 255, 1);
    transition:background 1s ease-out;
    -webkit-transition:background 1s ease-out;
#loader.done {
    background:rgba(255, 255, 255, 0);
#loader.hide {
#loader .message {
<div id='map'></div>
<div id='loader'><span class='message'>loading</span></div>
L.mapbox.accessToken = '<your access token here>';
var loader = document.getElementById('loader');

var map ='map')
    .setView([38.91, -77.03], 13);

// start the loading screen

// Add a tile layer with a loading animation
    .addTo(map) // add your tiles to the map
    .on('load', finishedLoading); // when the tiles load, remove the screen

function startLoading() {
    loader.className = '';

function finishedLoading() {
    // first, toggle the class 'done', which makes the loading screen
    // fade out
    loader.className = 'done';
    setTimeout(function() {
        // then, after a half-second, add the class 'hide', which hides
        // it completely and ensures that the user can interact with the
        // map again.
        loader.className = 'hide';
    }, 500);
to create your own custom map and use it in this example.
Use this example by copying its source into your own HTML page and replacing the Map ID with one of your own from your projects. Having trouble with JavaScript? Try out Codecademy or contact our support team.
Copy example