Folium – Using Mapbox Tiles

foliummapboxpython

I cannot find correct usage for using custom mapbox tilesets with folium.

From the documentation, "Folium also supports Cloudmade and Mapbox custom tilesets- simply pass your key to the API_key keyword" (http://python-visualization.github.io/folium/quickstart.html).

The docs provide this example…

folium.Map(location=[45.5236, -122.6750],
           tiles='Mapbox',
           API_key='your.API.key')

So I have tried…

#Create Map
my_map = folium.Map(location=[45.372, -121.6972],
                    zoom_start=12,
                    tiles='Mapbox',
                    API_key = 'pk.xxxxxxxxxxxxxxxxxxxxxxxxxxx') #mapbox map id 


#Create Map
my_map = folium.Map(location=[45.372, -121.6972],
                    zoom_start=12,
                    tiles='Mapbox',
                    API_key = 'pk.xxxxxxxxxxxxxxxxxxxxxxxxxxx')#mb api key 

#Create Map
 my_map = folium.Map(location=[45.372, -121.6972],
                    zoom_start=12,
                    tiles='user.2fb7fc73',
                    API_key = 'pk.xxxxxxxxxxxxxxxxxxxxxxx',
                    attr='Mapbox Data Attribution')

I have not been able to find any more example usage or explanation in the documents. If anyone has had success please advise?

Best Answer

As per http://python-visualization.github.io/folium/quickstart.html "Folium supports passing any Leaflet.js compatible custom tileset" let lets try that and bypass it's built in support:

folium.Map(location=[45.372, -121.6972],
       zoom_start=12,
       tiles='"http://{s}.tiles.mapbox.com/v4/wtgeographer.2fb7fc73/{z}/{x}/{y}.png?access_token=pk.xxx',
       attr='XXX Mapbox Attribution')

You'll need to places the pk.xxx with your pubilc access token.

This uses the API for Mapbox Studio Classic styles.

Related Question