Mapbox GL JS  |  Basic Map

This is a blank map, with the built-in zoom and navigation controls, as well as the fullscreen control (not working correctly for this layout). Usually you would reference a Mapbox style url in the ‘style’ option, but that requires an API key. For the purposes of these tutorials, we will be using a blank map.

« Outline Adding Layers »

Full Map Code

      
/*Blank Mapbox GL Map*/

var map = new mapboxgl.Map({
  container: 'map',
  hash: true,
  /*style: 'some mapbox style url*/
  /*below is a blank style*/
  style: {
    "version": 8,
    "name": "blank",
    "sources": {
      "openmaptiles": {
        "type": "vector",
        "url": ""
      }
    },
    "layers": [{
      "id": "background",
      "type": "background",
      "paint": {
        "background-color": "#1d1f20"
      }
    }]
  },
  center: [-95.52, 39.94],
  zoom: 4,
  debug: 1
});
map.addControl(new mapboxgl.NavigationControl());
map.addControl(new mapboxgl.FullscreenControl());

/*End Blank Map*/