3
votes

I'd like to display a Mapbox GL JS map with a white background, rather than a map background.

This is my code right now:

mapboxgl.accessToken = 'mytoken';
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/light-v9',
    minZoom: 4,
    maxZoom: 14,
    center: [-2.0, 53.3],
});

How can I replace the light background with plain white? If I change style to white then I get an error.

2

2 Answers

4
votes

You don't need to create the style in Mapbox Studio, you can create it in the browser:

var map = new mapboxgl.Map({
    container: 'map',
    style: {
        version: 8,
        sources: {

        },
        layers: [
          {
            id: 'background',
            type: 'background',
            paint: { 
              'background-color': 'white' 
            }
          }
        ]

      },
});
0
votes

I figured this out. You need to make your own "style" in Mapbox Studio and set it to be plain white, then add this in the style property of the map.