Skip to content

Commit ba30a45

Browse files
authored
vector layers: allow both snake_case and lowerCamelCase path options (#1672)
* vector layers: snake_case and lowerCamelCase options * add test
1 parent aaf3bb6 commit ba30a45

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

folium/vector_layers.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from jinja2 import Template
88

99
from folium.map import Marker, Popup, Tooltip
10-
from folium.utilities import get_bounds, validate_locations
10+
from folium.utilities import camelize, get_bounds, validate_locations
1111

1212

1313
def path_options(line=False, radius=False, **kwargs):
@@ -59,21 +59,25 @@ def path_options(line=False, radius=False, **kwargs):
5959
6060
Note that the presence of `fill_color` will override `fill=False`.
6161
62+
This function accepts both snake_case and lowerCamelCase equivalents.
63+
6264
See https://leafletjs.com/reference.html#path
6365
6466
"""
6567

68+
kwargs = {camelize(key): value for key, value in kwargs.items()}
69+
6670
extra_options = {}
6771
if line:
6872
extra_options = {
69-
"smoothFactor": kwargs.pop("smooth_factor", 1.0),
70-
"noClip": kwargs.pop("no_clip", False),
73+
"smoothFactor": kwargs.pop("smoothFactor", 1.0),
74+
"noClip": kwargs.pop("noClip", False),
7175
}
7276
if radius:
7377
extra_options.update({"radius": radius})
7478

7579
color = kwargs.pop("color", "#3388ff")
76-
fill_color = kwargs.pop("fill_color", False)
80+
fill_color = kwargs.pop("fillColor", False)
7781
if fill_color:
7882
fill = True
7983
elif not fill_color:
@@ -89,15 +93,15 @@ def path_options(line=False, radius=False, **kwargs):
8993
"color": color,
9094
"weight": kwargs.pop("weight", 3),
9195
"opacity": kwargs.pop("opacity", 1.0),
92-
"lineCap": kwargs.pop("line_cap", "round"),
93-
"lineJoin": kwargs.pop("line_join", "round"),
94-
"dashArray": kwargs.pop("dash_array", None),
95-
"dashOffset": kwargs.pop("dash_offset", None),
96+
"lineCap": kwargs.pop("lineCap", "round"),
97+
"lineJoin": kwargs.pop("lineJoin", "round"),
98+
"dashArray": kwargs.pop("dashArray", None),
99+
"dashOffset": kwargs.pop("dashOffset", None),
96100
"fill": fill,
97101
"fillColor": fill_color,
98-
"fillOpacity": kwargs.pop("fill_opacity", 0.2),
99-
"fillRule": kwargs.pop("fill_rule", "evenodd"),
100-
"bubblingMouseEvents": kwargs.pop("bubbling_mouse_events", True),
102+
"fillOpacity": kwargs.pop("fillOpacity", 0.2),
103+
"fillRule": kwargs.pop("fillRule", "evenodd"),
104+
"bubblingMouseEvents": kwargs.pop("bubblingMouseEvents", True),
101105
}
102106
default.update(extra_options)
103107
return default

tests/test_vector_layers.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

99
from folium import Map
1010
from folium.utilities import get_bounds, normalize
11-
from folium.vector_layers import Circle, CircleMarker, Polygon, PolyLine, Rectangle
11+
from folium.vector_layers import (
12+
Circle,
13+
CircleMarker,
14+
Polygon,
15+
PolyLine,
16+
Rectangle,
17+
path_options,
18+
)
1219

1320

1421
def test_circle():
@@ -406,3 +413,9 @@ def test_mulyipolyline():
406413
assert multipolyline.get_bounds() == get_bounds(locations)
407414
assert json.dumps(multipolyline.to_dict()) == multipolyline.to_json()
408415
assert multipolyline.options == expected_options
416+
417+
418+
def test_path_options_lower_camel_case():
419+
options = path_options(fill_color="red", fillOpacity=0.3)
420+
assert options["fillColor"] == "red"
421+
assert options["fillOpacity"] == 0.3

0 commit comments

Comments
 (0)