Skip to content

Commit eed305f

Browse files
committed
WIP undo changes
1 parent d45e306 commit eed305f

File tree

3 files changed

+56
-25
lines changed

3 files changed

+56
-25
lines changed

folium/folium.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import webbrowser
88
from typing import Any, List, Optional, Sequence, Union
99

10-
from branca.element import Figure
10+
from branca.element import Element, Figure
1111

1212
from folium.elements import JSCSSMixin
1313
from folium.map import Evented, FitBounds, Layer
@@ -62,6 +62,23 @@
6262
]
6363

6464

65+
class GlobalSwitches(Element):
66+
_template = Template(
67+
"""
68+
<script>
69+
L_NO_TOUCH = {{ this.no_touch |tojson}};
70+
L_DISABLE_3D = {{ this.disable_3d|tojson }};
71+
</script>
72+
"""
73+
)
74+
75+
def __init__(self, no_touch=False, disable_3d=False):
76+
super().__init__()
77+
self._name = "GlobalSwitches"
78+
self.no_touch = no_touch
79+
self.disable_3d = disable_3d
80+
81+
6582
class Map(JSCSSMixin, Evented):
6683
"""Create a Map with Folium and Leaflet.js
6784

folium/map.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections import OrderedDict
88
from typing import TYPE_CHECKING, Optional, Sequence, Union, cast
99

10-
from branca.element import Element, Html, MacroElement
10+
from branca.element import Element, Figure, Html, MacroElement
1111

1212
from folium.elements import ElementAddToElement, EventHandler
1313
from folium.template import Template
@@ -454,27 +454,25 @@ class Popup(MacroElement):
454454

455455
_template = Template(
456456
"""
457-
{% macro script(this, kwargs) %}
458-
var {{this.get_name()}} = L.popup({{ this.options|tojavascript }});
459-
460-
{% for name, element in this.html._children.items() %}
461-
{% if this.lazy %}
462-
{{ this._parent.get_name() }}.once('click', function() {
463-
{{ this.get_name() }}.setContent($(`{{ element.render(**kwargs).replace('\\n',' ') }}`)[0]);
464-
});
465-
{% else %}
466-
var {{ name }} = $(`{{ element.render(**kwargs).replace('\\n',' ') }}`)[0];
467-
{{ this.get_name() }}.setContent({{ name }});
468-
{% endif %}
469-
{% endfor %}
470-
471-
{{ this._parent.get_name() }}.bindPopup({{ this.get_name() }})
472-
{% if this.show %}.openPopup(){% endif %};
473-
474-
{% for name, element in this.script._children.items() %}
475-
{{element.render()}}
476-
{% endfor %}
477-
{% endmacro %}
457+
var {{this.get_name()}} = L.popup({{ this.options|tojavascript }});
458+
459+
{% for name, element in this.html._children.items() %}
460+
{% if this.lazy %}
461+
{{ this._parent.get_name() }}.once('click', function() {
462+
{{ this.get_name() }}.setContent($(`{{ element.render(**kwargs).replace('\\n',' ') }}`)[0]);
463+
});
464+
{% else %}
465+
var {{ name }} = $(`{{ element.render(**kwargs).replace('\\n',' ') }}`)[0];
466+
{{ this.get_name() }}.setContent({{ name }});
467+
{% endif %}
468+
{% endfor %}
469+
470+
{{ this._parent.get_name() }}.bindPopup({{ this.get_name() }})
471+
{% if this.show %}.openPopup(){% endif %};
472+
473+
{% for name, element in this.script._children.items() %}
474+
{{element.render()}}
475+
{% endfor %}
478476
"""
479477
) # noqa
480478

@@ -515,6 +513,21 @@ def __init__(
515513
**kwargs,
516514
)
517515

516+
def render(self, **kwargs):
517+
"""Renders the HTML representation of the element."""
518+
for name, child in self._children.items():
519+
child.render(**kwargs)
520+
521+
figure = self.get_root()
522+
assert isinstance(
523+
figure, Figure
524+
), "You cannot render this Element if it is not in a Figure."
525+
526+
figure.script.add_child(
527+
Element(self._template.render(this=self, kwargs=kwargs)),
528+
name=self.get_name(),
529+
)
530+
518531

519532
class Tooltip(MacroElement):
520533
"""

folium/plugins/search.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ def __init__(
122122
self.placeholder = placeholder
123123
self.collapsed = collapsed
124124
self.options = remove_empty(**kwargs)
125-
self.test_params()
126125

127-
def test_params(self):
126+
def render(self, **kwargs):
127+
super().render(**kwargs)
128+
128129
if isinstance(self.layer, GeoJson):
129130
keys = tuple(self.layer.data["features"][0]["properties"].keys())
130131
elif isinstance(self.layer, TopoJson):

0 commit comments

Comments
 (0)