Skip to content

Commit

Permalink
Remove empty values from the options.
Browse files Browse the repository at this point in the history
  • Loading branch information
hansthen committed Dec 12, 2024
1 parent d115da6 commit bc219ff
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 40 deletions.
7 changes: 4 additions & 3 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
javascript_identifier_path_to_array_notation,
none_max,
none_min,
remove_empty,
validate_locations,
)
from folium.vector_layers import Circle, CircleMarker, PolyLine, path_options
Expand Down Expand Up @@ -688,7 +689,7 @@ def __init__(
self.popup_keep_highlighted = popup_keep_highlighted

self.marker = marker
self.options = kwargs
self.options = remove_empty(**kwargs)

self.data = self.process_data(data)

Expand Down Expand Up @@ -1715,7 +1716,7 @@ def __init__(
):
super().__init__()
self._name = "DivIcon"
self.options = dict(
self.options = remove_empty(
html=html,
icon_size=icon_size,
icon_anchor=icon_anchor,
Expand Down Expand Up @@ -1894,7 +1895,7 @@ def __init__(
):
super(Icon, self).__init__()
self._name = "CustomIcon"
self.options = dict(
self.options = remove_empty(
icon_url=image_to_url(icon_image),
icon_size=icon_size,
icon_anchor=icon_anchor,
Expand Down
3 changes: 2 additions & 1 deletion folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
TypeJsonValue,
_parse_size,
parse_font_size,
remove_empty,
temp_html_filepath,
validate_location,
)
Expand Down Expand Up @@ -303,7 +304,7 @@ def __init__(
else:
self.zoom_control_position = False

self.options = dict(
self.options = remove_empty(
max_bounds=max_bounds_array,
zoom=zoom_start,
zoom_control=False if self.zoom_control_position else zoom_control,
Expand Down
15 changes: 8 additions & 7 deletions folium/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
TypeJsonValue,
escape_backticks,
parse_options,
remove_empty,
validate_location,
)

Expand Down Expand Up @@ -131,7 +132,7 @@ def __init__(
super().__init__(name=name, overlay=overlay, control=control, show=show)
self._name = "FeatureGroup"
self.tile_name = name if name is not None else self.get_name()
self.options = kwargs
self.options = remove_empty(**kwargs)


class LayerControl(MacroElement):
Expand Down Expand Up @@ -206,7 +207,7 @@ def __init__(
):
super().__init__()
self._name = "LayerControl"
self.options = dict(
self.options = remove_empty(
position=position, collapsed=collapsed, autoZIndex=autoZIndex, **kwargs
)
self.draggable = draggable
Expand Down Expand Up @@ -312,7 +313,7 @@ def __init__(
f"color argument of Icon should be one of: {self.color_options}.",
stacklevel=2,
)
self.options = dict(
self.options = remove_empty(
marker_color=color,
icon_color=icon_color,
icon=icon,
Expand Down Expand Up @@ -379,7 +380,7 @@ def __init__(
super().__init__()
self._name = "Marker"
self.location = validate_location(location) if location is not None else None
self.options = dict(
self.options = remove_empty(
draggable=draggable or None, autoPan=draggable or None, **kwargs
)
if icon is not None:
Expand Down Expand Up @@ -481,7 +482,7 @@ def __init__(

self.show = show
self.lazy = lazy
self.options = dict(
self.options = remove_empty(
max_width=max_width,
autoClose=False if show or sticky else None,
closeOnClick=False if sticky else None,
Expand Down Expand Up @@ -550,7 +551,7 @@ def __init__(
self.text = str(text)

kwargs.update({"sticky": sticky})
self.options = kwargs
self.options = remove_empty(**kwargs)

if style:
assert isinstance(
Expand Down Expand Up @@ -659,7 +660,7 @@ def __init__(
self._name = "FitOverlays"
self.method = "flyToBounds" if fly else "fitBounds"
self.fit_on_map_load = fit_on_map_load
self.options = dict(padding=(padding, padding), max_zoom=max_zoom)
self.options = remove_empty(padding=(padding, padding), max_zoom=max_zoom)


class CustomPane(MacroElement):
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/beautify_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from folium.elements import JSCSSMixin
from folium.template import Template
from folium.utilities import remove_empty


class BeautifyIcon(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -99,7 +100,7 @@ def __init__(
super().__init__()
self._name = "BeautifyIcon"

self.options = dict(
self.options = remove_empty(
icon=icon,
icon_shape=icon_shape,
border_width=border_width,
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/boat_marker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from folium.elements import JSCSSMixin
from folium.map import Marker
from folium.template import Template
from folium.utilities import remove_empty


class BoatMarker(JSCSSMixin, Marker):
Expand Down Expand Up @@ -65,4 +66,4 @@ def __init__(
self.heading = heading
self.wind_heading = wind_heading
self.wind_speed = wind_speed
self.options = dict(**kwargs)
self.options = remove_empty(**kwargs)
3 changes: 2 additions & 1 deletion folium/plugins/fullscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from folium.elements import JSCSSMixin
from folium.template import Template
from folium.utilities import remove_empty


class Fullscreen(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -59,7 +60,7 @@ def __init__(
):
super().__init__()
self._name = "Fullscreen"
self.options = dict(
self.options = remove_empty(
position=position,
title=title,
title_cancel=title_cancel,
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/geocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from folium.elements import JSCSSMixin
from folium.template import Template
from folium.utilities import remove_empty


class Geocoder(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -81,7 +82,7 @@ def __init__(
):
super().__init__()
self._name = "Geocoder"
self.options = dict(
self.options = remove_empty(
collapsed=collapsed,
position=position,
default_mark_geocode=add_marker,
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/groupedlayercontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from folium.elements import JSCSSMixin
from folium.template import Template
from folium.utilities import remove_empty


class GroupedLayerControl(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -68,7 +69,7 @@ class GroupedLayerControl(JSCSSMixin, MacroElement):
def __init__(self, groups, exclusive_groups=True, **kwargs):
super().__init__()
self._name = "GroupedLayerControl"
self.options = dict(**kwargs)
self.options = remove_empty(**kwargs)
if exclusive_groups:
self.options["exclusiveGroups"] = list(groups.keys())
self.layers_untoggle = set()
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/heat_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
if_pandas_df_convert_to_numpy,
none_max,
none_min,
remove_empty,
validate_location,
)

Expand Down Expand Up @@ -89,7 +90,7 @@ def __init__(
"The largest intensity is calculated automatically.",
stacklevel=2,
)
self.options = dict(
self.options = remove_empty(
min_opacity=min_opacity,
max_zoom=max_zoom,
radius=radius,
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/locate_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from folium.elements import JSCSSMixin
from folium.template import Template
from folium.utilities import remove_empty


class LocateControl(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -73,4 +74,4 @@ def __init__(self, auto_start=False, **kwargs):
super().__init__()
self._name = "LocateControl"
self.auto_start = auto_start
self.options = dict(**kwargs)
self.options = remove_empty(**kwargs)
4 changes: 2 additions & 2 deletions folium/plugins/marker_cluster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from folium.elements import JSCSSMixin
from folium.map import Layer, Marker
from folium.template import Template
from folium.utilities import validate_locations
from folium.utilities import remove_empty, validate_locations


class MarkerCluster(JSCSSMixin, Layer):
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(
)
)

self.options = dict(**kwargs)
self.options = remove_empty(**kwargs)
if icon_create_function is not None:
assert isinstance(icon_create_function, str)
self.icon_create_function = icon_create_function
3 changes: 2 additions & 1 deletion folium/plugins/measure_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from folium.elements import JSCSSMixin
from folium.template import Template
from folium.utilities import remove_empty


class MeasureControl(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -72,7 +73,7 @@ def __init__(
super().__init__()
self._name = "MeasureControl"

self.options = dict(
self.options = remove_empty(
position=position,
primary_length_unit=primary_length_unit,
secondary_length_unit=secondary_length_unit,
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/minimap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from folium.elements import JSCSSMixin
from folium.raster_layers import TileLayer
from folium.template import Template
from folium.utilities import remove_empty


class MiniMap(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -114,7 +115,7 @@ def __init__(
else:
self.tile_layer = TileLayer(tile_layer)

self.options = dict(
self.options = remove_empty(
position=position,
width=width,
height=height,
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/mouse_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from folium.elements import JSCSSMixin
from folium.template import Template
from folium.utilities import remove_empty


class MousePosition(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -87,7 +88,7 @@ def __init__(
super().__init__()
self._name = "MousePosition"

self.options = dict(
self.options = remove_empty(
position=position,
separator=separator,
empty_string=empty_string,
Expand Down
4 changes: 2 additions & 2 deletions folium/plugins/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from folium.elements import JSCSSMixin
from folium.folium import Map
from folium.template import Template
from folium.utilities import get_obj_in_upper_tree
from folium.utilities import get_obj_in_upper_tree, remove_empty


class StripePattern(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -59,7 +59,7 @@ def __init__(
):
super().__init__()
self._name = "StripePattern"
self.options = dict(
self.options = remove_empty(
angle=angle,
weight=weight,
space_weight=space_weight,
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/polyline_text_path.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from folium.elements import JSCSSMixin
from folium.features import MacroElement
from folium.template import Template
from folium.utilities import remove_empty


class PolyLineTextPath(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -67,7 +68,7 @@ def __init__(
self._name = "PolyLineTextPath"
self.polyline = polyline
self.text = text
self.options = dict(
self.options = remove_empty(
repeat=repeat,
center=center,
below=below,
Expand Down
4 changes: 2 additions & 2 deletions folium/plugins/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from folium.features import GeoJson
from folium.map import FeatureGroup
from folium.template import Template
from folium.utilities import JsCode
from folium.utilities import JsCode, remove_empty


class Realtime(JSCSSMixin, FeatureGroup):
Expand Down Expand Up @@ -115,4 +115,4 @@ def __init__(
kwargs["remove_missing"] = remove_missing
kwargs["container"] = container

self.options = kwargs
self.options = remove_empty(**kwargs)
3 changes: 2 additions & 1 deletion folium/plugins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from folium.features import FeatureGroup, GeoJson, TopoJson
from folium.plugins import MarkerCluster
from folium.template import Template
from folium.utilities import remove_empty


class Search(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -121,7 +122,7 @@ def __init__(
self.position = position
self.placeholder = placeholder
self.collapsed = collapsed
self.options = dict(**kwargs)
self.options = remove_empty(**kwargs)

def test_params(self, keys):
if keys is not None and self.search_label is not None:
Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/tag_filter_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from folium.elements import JSCSSMixin
from folium.template import Template
from folium.utilities import remove_empty


class TagFilterButton(JSCSSMixin, MacroElement):
Expand Down Expand Up @@ -85,7 +86,7 @@ def __init__(
):
super().__init__()
self._name = "TagFilterButton"
self.options = dict(
self.options = remove_empty(
data=data,
icon=icon,
clear_text=clear_text,
Expand Down
Loading

0 comments on commit bc219ff

Please sign in to comment.