10

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?

6

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.

| improve this answer | |
1

The answer above is correct, but I wanted to add some detail of where Mapbox users can get the necessary url for the code. When in Mapbox Styles page, simply choose to share your style, and under 'Developer Resources', change the method to Fulcrum as pictured below. Then, simply copy the link from the integration url and paste in the tiles=' '.

Fulcrum Method

| improve this answer | |
  • Is there a programmatic way to get this link, with classic mapbox API above, you just needed to upload the tileset and could link. Now you need to manually add to studio? What if you have hundreds of tiles. Or multiple time slices of the same geography that your app needs to choose? gis.stackexchange.com/questions/366018/… – bw4sz Jun 26 at 3:20
  • @bw4sz, 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 – CriticalWill Jun 26 at 5:04
  • @bw4sz, 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. You should also keep in mind that if you use Mapbox api key it is exposed in the html, so be sure to restrict the use to only the domain in which it will be deployed. – CriticalWill Jun 26 at 5:11

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.