Skip to content

Map.show_in_browser() using temp file #1651

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

Merged
Merged
Changes from all commits
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
16 changes: 16 additions & 0 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import time
import warnings
import webbrowser

from branca.element import Element, Figure, MacroElement

Expand Down Expand Up @@ -375,6 +376,21 @@ def render(self, **kwargs):

super(Map, self).render(**kwargs)

def show_in_browser(self):
"""Display the Map in the default web browser."""
with temp_html_filepath(self.get_root().render()) as fname:
webbrowser.open(fname)
print(
'Your map should have been opened in your browser automatically.'
'\nPress ctrl+c to return.'
)
# Block until stopped by user, afterwards remove the temporary file
try:
while True:
time.sleep(100)
except KeyboardInterrupt:
pass

def fit_bounds(self, bounds, padding_top_left=None,
padding_bottom_right=None, padding=None, max_zoom=None):
"""Fit the map to contain a bounding box with the
Expand Down