ENH: expose folium.map kwds as map_kwds in explore() (#2315)

Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
This commit is contained in:
rraymondgh
2022-01-27 08:22:43 +01:00
committed by GitHub
co-authored by Martin Fleischmann
parent 13bec53619
commit f990008d90
2 changed files with 34 additions and 1 deletions
+15 -1
View File
@@ -57,6 +57,7 @@ def _explore(
tooltip_kwds={},
popup_kwds={},
legend_kwds={},
map_kwds={},
**kwargs,
):
"""Interactive map based on GeoPandas and folium/leaflet.js
@@ -225,6 +226,10 @@ def _explore(
Applies if ``colorbar=False``.
max_labels : int, default 10
Maximum number of colorbar tick labels (requires branca>=0.5.0)
map_kwds : dict (default {})
Additional keywords to be passed to folium :class:`~folium.folium.Map`,
e.g. ``dragging``, or ``scrollWheelZoom``.
**kwargs : dict
Additional options to be passed on to the folium object.
@@ -302,7 +307,16 @@ GON (((180.00000 -16.06713, 180.00000...
fit = False
# get a subset of kwargs to be passed to folium.Map
map_kwds = {i: kwargs[i] for i in kwargs.keys() if i in _MAP_KWARGS}
for i in _MAP_KWARGS:
if i in map_kwds:
raise ValueError(
f"'{i}' cannot be specified in 'map_kwds'. "
f"Use the '{i}={map_kwds[i]}' argument instead."
)
map_kwds = {
**map_kwds,
**{i: kwargs[i] for i in kwargs.keys() if i in _MAP_KWARGS},
}
if HAS_XYZSERVICES:
# match provider name string to xyzservices.TileProvider
+19
View File
@@ -797,3 +797,22 @@ class TestExplore:
gdf["centroid"] = gdf.centroid
gdf.explore()
def test_map_kwds(self):
def check():
out_str = self._fetch_map_string(m)
assert "zoomControl:false" in out_str
assert "dragging:false" in out_str
assert "scrollWheelZoom:false" in out_str
# check that folium and leaflet Map() parameters can be passed
m = self.world.explore(
zoom_control=False, map_kwds=dict(dragging=False, scrollWheelZoom=False)
)
check()
with pytest.raises(
ValueError, match="'zoom_control' cannot be specified in 'map_kwds'"
):
self.world.explore(
map_kwds=dict(dragging=False, scrollWheelZoom=False, zoom_control=False)
)