folium custom map tiles

孤街醉人 提交于 2020-04-13 05:20:50

问题


I want to add this map tile layer to my map – Stamen toner-background. As I read in documentation I need to simply give custom url in the tiles attribute of map

mapa = folium.Map(width=1000, height=700, zoom_start=5.5,
              location=[52.5, 19], tiles='http://maps.stamen.com/toner-background/embed#6/{x}/{z}', attr="toner-bcg")

It loads but nothing is displayed.

I don't really know how this attribution thing works like and what should I do. I like the tile because it's like stamen toner but without country names and that makes my map a lot more beautiful.


回答1:


This is your lucky day, Stamen designs are built-in in Folium. You should run the following code:

mapa = folium.Map(width=1000, height=700, zoom_start=5.5,
              location=[52.5, 19], tiles='Stamen Toner')

This should solve the issue.

The reason your code was not working is because you were not using the correct URL templates. The format is one specified here:

http://tile.stamen.com/toner/{z}/{x}/{y}.png
http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg
http://tile.stamen.com/watercolor/{z}/{x}/{y}.jpg

The code would look like this:

mapa = folium.Map(width=1000, height=700, zoom_start=5.5,
              location=[52.5, 19], tiles='http://tile.stamen.com/toner/{z}/{x}/{y}.png ')



回答2:


To improve Fernando's answer, the below code works for me:

mapa = folium.Map(width=1000, height=700, zoom_start=5.5,
    location=[52.5, 19], 
    tiles='http://tile.stamen.com/toner/{z}/{x}/{y}.png ', 
    attr="toner-bcg") # <-- note this


来源:https://stackoverflow.com/questions/48318538/folium-custom-map-tiles

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