5

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 Answers 2

9

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' 
            }
          }
        ]

      },
});
Sign up to request clarification or add additional context in comments.

1 Comment

great answer :)
-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.