Skip to content

Commit 5d3e016

Browse files
committed
Don't copy children twice when rendering twice
1 parent 2e6f3da commit 5d3e016

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

folium/plugins/dual_map.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self, location=None, layout='horizontal', **kwargs):
6464
# Important: add self to Figure last.
6565
figure.add_child(self)
6666
self.children_for_m2 = []
67+
self.children_for_m2_copied = [] # list with ids
6768

6869
def _repr_html_(self, **kwargs):
6970
"""Displays the HTML Map in a Jupyter notebook."""
@@ -93,10 +94,14 @@ def render(self, **kwargs):
9394
super(DualMap, self).render(**kwargs)
9495

9596
for child, name, index in self.children_for_m2:
97+
if child._id in self.children_for_m2_copied:
98+
# This map has been rendered before, child was copied already.
99+
continue
96100
child_copy = deep_copy(child)
97101
self.m2.add_child(child_copy, name, index)
98-
# m2 has already been rendered, so render the child here.
102+
# m2 has already been rendered, so render the child here:
99103
child_copy.render()
104+
self.children_for_m2_copied.append(child._id)
100105

101106
def fit_bounds(self, *args, **kwargs):
102107
for m in (self.m1, self.m2):

0 commit comments

Comments
 (0)