0
votes

Apologies if this is basic, I've tried to find an answer...

Apparently to add a basemap, I need to change the "style", like here:

style: 'mapbox://styles/mapbox/satellite-v9',

But how do I add this mapbox basemap (Natural Earth II)? https://a.tiles.mapbox.com/v3/mapbox.natural-earth-2.html

... and how to I change basemaps outside of the few that are shown here? https://www.mapbox.com/mapbox-gl-js/example/setstyle/

1

1 Answers

1
votes

you'll have to create your own source because Mapbox does not have a public style with this tileset.

var map = new mapboxgl.Map({ 
  container: 'map', 
  style: 'mapbox://styles/mapbox/light-v9', 
  hash: true, 
  center: [-93.6135, 42.0256], 
  zoom: 15, 
  pitchWithRotate: false
});

map.on('load', () =>{
    map.addLayer({
      id: 'naturalearth',
      source: {
        type: 'raster',
        tiles: ['https://a.tiles.mapbox.com/v3/mapbox.natural-earth-2/{z}/{x}/{y}.png']
      },
      type: 'raster'
    })
})