4

I would like to add Mapbox basemaps to Leaflet or OpenLayers, but I am missing the map IDs.

Before Mapbox Editor was deactivated, one could easily create and save a map, copy that map's ID and your personal API token and then include the map in Leaflet or OpenLayers by using the following URL, replacing my.map and your < access token here >:

http://a.tiles.mapbox.com/v4/my.map/{z}/{x}/{y}.png?access_token=<your access token here>

This still works. But only if you have existing maps from before Mapbox Editor was deactivated on January 31, 2017.

How do new users, who cannot save maps and therefore do not have a personal map ID, go about formatting the URL? New users get an API token but they cannot save maps anymore and thereby get a map ID.

So, how can the following Mapbox basemaps be accessed now:

  • Classic
  • Light
  • Dark
  • Satellite
  • Satellite Streets
  • Wheatpaste
  • Streets Classic
  • Comic
  • Outdoors
  • Run, Bike, Hike
  • Pencil
  • Pirates
  • Emerald
  • High Contrast

I found a post on Stack Overflow, which shows that the URL can be formatted this way:

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

So, you do not necessarily need a personal map ID as every public Mapbox basemap seems to have an ID.

I have tested this and it works, you just need to replace {id} with a map's name, such as streets-v9 but I am unable to find the IDs of the above maps.

8

Let me quote from https://www.mapbox.com/api-documentation/#maps :

If you use Mapbox.js, Mapbox GL JS, or another library like Leaflet, you're already using this API. This documentation is geared toward software developers who want to programmatically read these resources: it isn't necessary to read or understand this reference to design or use maps.

Mapbox classic map IDs

The following map IDs are accessible to all accounts using a valid access token:

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

So you should use something like

http://a.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token=...

  • I found that but it did not work. I will try again soon and let you know. – BritishSteel Jun 21 '17 at 11:16
  • Works perfectly fine! Had a minor error in the URL and that kept it from working! – BritishSteel Jun 21 '17 at 11:26
  • You should edit my answer to fix that typo in the URL :-) – IvanSanchez Jun 21 '17 at 11:51
  • These identifiers like mapbox.comic, are no longer listed in the Mapbox documentation, at least not in the URL provided here. Therefore this answer is helpful to provide these IDs, which still work – The Red Pea Jun 16 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.