将MapBox底图更改为Natural Earth II?

时间:2017-11-07 05:24:09

标签: mapbox mapbox-gl-js mapbox-gl

如果这是基本的道歉,我试图找到答案......

显然要添加底图,我需要更改“样式”,如下所示:

  

样式:'mapbox:// styles / mapbox / satellite-v9 ',

但是如何添加此mapbox底图(Natural Earth II)? https://a.tiles.mapbox.com/v3/mapbox.natural-earth-2.html

...以及如何更改此处显示的少数几个底图? https://www.mapbox.com/mapbox-gl-js/example/setstyle/

1 个答案:

答案 0 :(得分:1)

您必须创建自己的来源,因为Mapbox没有此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'
    })
})