I have a R shiny app that successfully uses leaflet to interact with a custom mapbox studio style.

mapbox_url = "https://api.mapbox.com/styles/v1/bweinstein/ck94nmzn20an31imrz6ffplun/tiles/256/{z}/{x}/{y}@2x?access_token=####"
leaflet() %>% addTiles(mapbox_url)

To do this I

  1. Uploaded tileset to mapbox
  2. Created a new style and added the tileset as a source
  3. Click share in studio and got the CARTO link (as in https://stackoverflow.com/questions/34072237/how-can-i-use-a-custom-created-mapbox-style-along-with-leaflet)

Is there anyway to programmatically create styles, or better yet, directly get the tileset without studio? Studio styles have a limit of 15 sources. I have hundreds of tiles that I'd like to programmatically choose in my app.

Expected behavior

If I have a tileset with the id


I expected the tileset to be available at url:

mapbox_url = 'https://api.mapbox.com/styles/v1/bweinstein/bweinstein.CypressCity_03_25_2020/tiles/256/{z}/{x}/{y}@2x?access_token=####'

I've tried a number of variants, e.g.

mapbox_url = 'https://api.mapbox.com/styles/v1/bweinstein/CypressCity_03_25_2020/tiles/256/{z}/{x}/{y}?access_token=####'

I don't see anything here: https://docs.mapbox.com/studio-manual/overview/publish-your-style/#leaflet but this seems like a core use-case?


The answer Using Mapbox tiles with folium from 2016 uses classic mapbox API and appears deprecated.

MacBook-Pro:Downloads ben$ curl http://{s}.tiles.mapbox.com/v4/bweinstein.CypressCity_03_25_2020/{z}/{x}/{y}.png?access_token=#####
curl: (6) Could not resolve host: s.tiles.mapbox.com

Current tileset API cannot find it

MacBook-Pro:Downloads ben$ curl http://api.mapbox.com/v4/bweinstein.CypressCity_03_25_2020/{z}/{x}/{y}.png?access_token=######
{"message":"Not Found"}
  • getting closer here: docs.mapbox.com/api/maps/#example-request-body-create-a-style
    – bw4sz
    Commented Jun 26, 2020 at 3:25
  • sounds like you may be better off hosting your tiles with maptiler which allows a certain number (I dont know how much) to be hosted in their cloud for free. cloud.maptiler.com
    – Mike W
    Commented Jun 26, 2020 at 5:08
  • You might find your answer here: gis.stackexchange.com/questions/203062/…. It seems that your tileset is identified by userId.tilesetId combination..
    – TomazicM
    Commented Jun 26, 2020 at 6:25
  • @TomazicM that first answer is from five years ago and seems to apply only to deprecated "mapbox classic" tiles? I'm struggling to understand why such a critical use-case was deprecated?
    – bw4sz
    Commented Jun 26, 2020 at 13:34
  • According to docs at docs.mapbox.com/api/maps/#raster-tiles syntax https://tiles.mapbox.com/v4/userId.tilesetId/{z}/{x}/{y}.png should work, but I couldn't get it working either.
    – TomazicM
    Commented Jun 27, 2020 at 11:21

1 Answer 1


Very simple. Don't construct the URL yourself.

  leaflet() %>% addProviderTiles("MapBox", 
                   options = providerTileOptions(id = "bweinstein.CypressCity_03_25_2020",
                                                 accessToken ="########"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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