openlayers加载Mapbox底图

Mapbox Studio样式或Mapbox基础地图样式
要在OpenLayers 3.x中使用Mapbox Studio样式或Mapbox基础地图样式URL,需要引用Mapbox静态Tiles API。也可以将样式URL替换为mapbox/streets-v11 。

var map = new ol.Map({
  layers: [
    new ol.layer.Tile({
      source: new ol.source.XYZ({
        url: 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1Ijoid2FuZ2hhaGExIiwiYSI6ImNqeHUycXF5ZDEweDQzYnBiOTcwZGoxMHAifQ.eCGuiA6erHJ7ew-Fkc7dRA'
      })
    })
  ],
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    zoom: 2
  })
});

Mapbox图块ID
要将Mapbox Tileset ID与OpenLayers 3.x结合使用,需要引用Mapbox Raster Tiles API。可以用mapbox.satellite自己的图素ID替换。

var map = new ol.Map({
  layers: [
    new ol.layer.Tile({
      source: new ol.source.XYZ({
        url: 'https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.jpg?access_token=pk.eyJ1Ijoid2FuZ2hhaGExIiwiYSI6ImNqeHUycXF5ZDEweDQzYnBiOTcwZGoxMHAifQ.eCGuiA6erHJ7ew-Fkc7dRA'
      })
    })
  ],
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    zoom: 2
  })
});

(给个赞再走呗)

你可能感兴趣的:(openlayers,html,gis)