python中folium切换地图源

一、folium默认地图源

文中的folium版本为0.14.0,官方文档中说明内置的地图源为:
在这里插入图片描述
默认情况下均为OpenStreetMap,不过由于网络原因OpenStreetMap加载有时会存在一定问题。此外,根据官方的源码,其中有一些类型的tiles不支持使用keyword来直接添加。

        if tiles_flat in {"cloudmade", "mapbox", "mapboxbright", "mapboxcontrolroom"}:
            # added in May 2020 after v0.11.0, remove in a future release
            raise ValueError(
                "Built-in templates for Mapbox and Cloudmade have been removed. "
                "You can still use these providers by passing a URL to the `tiles` "
                "argument. See the documentation of the `TileLayer` class."
            )

二、使用xyzservices.TileProvider切换地图源

在这里插入图片描述
官方文档中提供了一个免费的源:http://leaflet-extras.github.io/leaflet-providers/preview/,获取想要地图的tiles和attr。
或者通过https://xyzservices.readthedocs.io/en/latest/introduction.html,也能获取到。
在这里插入图片描述
folium使用TileLayer则可添加栅格图层,即可完成不同类型底图的展示。

import webbrowser

import folium

my_map = folium.Map(location=[32, 113], tiles=None, zoom_start=4)  # 默认地图中心点和缩放等级
layer = folium.TileLayer(
    tiles='http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',
    attr='&copy; <a href="http://www.gaode.com/">Gaode.com</a>',
    min_zoom=0,
    max_zoom=19,
    name='test'
).add_to(my_map)
folium.LayerControl(position='bottomright', collapsed=False).add_to(my_map)
# 存储地图
my_map.save('test.html')
# 默认浏览器打开
webbrowser.open('test.html')

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值