Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the map pickable natively #1812

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove index = 0 for selenium compatibility
add set_parent_for_children function needed after unpickling
BastienGauthier committed Oct 6, 2023
commit 1254fe94c42198b8bae18d575420dcda554095cb
13 changes: 9 additions & 4 deletions folium/folium.py
Original file line number Diff line number Diff line change
@@ -345,13 +345,18 @@ def __init__(
self.add_child(child, name = key)
else: # Initialize the tiles
if isinstance(tiles, TileLayer):
self.add_child(tiles, index = 0)
self.add_child(tiles)
elif tiles:
tile_layer = TileLayer(
tiles=tiles, attr=attr, min_zoom=min_zoom, max_zoom=max_zoom, index = 0
tiles=tiles, attr=attr, min_zoom=min_zoom, max_zoom=max_zoom
)
self.add_child(tile_layer, name=tile_layer.tile_name)

def set_parent_for_children(self) -> None:
for _, child in self._children.items():
child._parent = self
return None

def _repr_html_(self, **kwargs) -> str:
"""Displays the HTML Map in a Jupyter notebook."""
if self._parent is None:
@@ -516,7 +521,7 @@ def keep_in_front(self, *args: Layer) -> None:
for obj in args:
self.objects_to_stay_in_front.append(obj)

def map_reduce(map_instance):
def map_pickler(map_instance):
return (Map, (
map_instance.location,
map_instance.width,
@@ -544,4 +549,4 @@ def map_reduce(map_instance):
map_instance._children,
))

copyreg.pickle(Map, map_reduce)
copyreg.pickle(Map, map_pickler)