Mapbox tiles and Leafletjs

南楼画角 提交于 2019-12-03 02:46:38

问题


I'm trying to load some additional tile layers on my map but I can't quite figure it out. The ones that I currently have I only have thanks to someone that provided a tutorial but didn't say what the other tile options were. Can someone help me with this?

var mapboxUrl = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}';
var accessToken = 'mySuperSecretToken';

var grayscale = L.tileLayer(mapboxUrl, {id: 'mapbox.light', attribution: '', maxZoom: 20, accessToken: accessToken}),
streets = L.tileLayer(mapboxUrl, {id: 'mapbox.streets', attribution: '', maxZoom: 20, accessToken: accessToken});

I cannot seem to figure out how to get any additional layers or even use the new streets version that I got an email about today.


回答1:


I actually finally found the answer.

The URL string needed to be updated to

https://api.mapbox.com/styles/v1/mapbox/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}

The available styles ({id}) are

  • streets-v9
  • satellite-streets-v9
  • light-v9
  • dark-v9
  • outdoors-v9



回答2:


Full list of Mapbox classic map IDs, ie for Leaflet, are at https://www.mapbox.com/api-documentation/#maps.

At the time of writing the IDs are:

  • mapbox.streets
  • mapbox.light
  • mapbox.dark
  • mapbox.satellite
  • mapbox.streets-satellite
  • mapbox.wheatpaste
  • mapbox.streets-basic
  • mapbox.comic
  • mapbox.outdoors
  • mapbox.run-bike-hike
  • mapbox.pencil
  • mapbox.pirates
  • mapbox.emerald
  • mapbox.high-contrast



回答3:


Actually, the new tile layers 'styles' that Mapbox was referring to were vector tile layers.

Mapbox-GL JS uses vector styles which you listed (xxx-v9). (up to date as of 05/2019)

Mapbox JS is built on top of Leaflet (L.tilelayer()) and uses raster tilesets, which are images. Here are the available basemaps from Mapbox.



来源:https://stackoverflow.com/questions/37166172/mapbox-tiles-and-leafletjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!