如何在使用 explore() 创建的 geopandas 地图中禁用缩放和平移

How to disable zoom and pan in a geopandas map created with explore()

我已经在 geopandas 中使用 explore() 函数创建了地图,但我想修复缩放级别并禁用鼠标平移。

我试过以下方法

merged1.explore(
     column="department", # make choropleth based on "department" column
     tooltip="decision_type", # show "decision_type" value in tooltip (on hover)
     popup=True, # show all values in popup (on click)
     tiles="CartoDB positron", # use "CartoDB positron" tiles
     cmap="Set1", # use "Set1" matplotlib colormap
     style_kwds=dict(color="black"), # use black outline
     zoom_control=False,
    )

zoom_control=False 禁用缩放按钮,但我无法禁用滚动或平移缩放。我尝试在参数中添加 dragging=Falsescroll_wheel_zoom=False,但没有用。

如何将参数传递给 folium 对象 and/or leafletjs 以实现我的目标?

如果你在 geopandas 包中查看 explore.py,你会发现有一个常量列表 kwargs 传递给 folium / leaflet

使用您要使用的传单 https://leafletjs.com/reference-1.6.0.html#map 中定义的参数扩展此列表允许您从 explore() 调用中传递它们。

下图显示平移和缩放已完全禁用。

import geopandas as gpd
import geopandas.explore

geopandas.explore._MAP_KWARGS += ["dragging", "scrollWheelZoom"]

world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
world.loc[world["continent"].eq("Europe") & ~world["iso_a3"].isin(["RUS","-99"])].explore(
    # m=m,
    column="gdp_md_est",  # make choropleth based on "department" column
    tooltip="name",  # show "decision_type" value in tooltip (on hover)
    popup=True,  # show all values in popup (on click)
    tiles="CartoDB positron",  # use "CartoDB positron" tiles
    cmap="Set1",  # use "Set1" matplotlib colormap
    style_kwds=dict(color="black"),  # use black outline
    zoom_control=False,
    dragging=False,
    scrollWheelZoom=False
)