Skip to content

Commit 9d31525

Browse files
authored
Map.show_in_browser() using temp file (#1651)
* Map.show_in_browser() using temp file * update comment
1 parent 3fd4669 commit 9d31525

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

folium/folium.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import time
77
import warnings
8+
import webbrowser
89

910
from branca.element import Element, Figure, MacroElement
1011

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

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

379+
def show_in_browser(self):
380+
"""Display the Map in the default web browser."""
381+
with temp_html_filepath(self.get_root().render()) as fname:
382+
webbrowser.open(fname)
383+
print(
384+
'Your map should have been opened in your browser automatically.'
385+
'\nPress ctrl+c to return.'
386+
)
387+
# Block until stopped by user, afterwards remove the temporary file
388+
try:
389+
while True:
390+
time.sleep(100)
391+
except KeyboardInterrupt:
392+
pass
393+
378394
def fit_bounds(self, bounds, padding_top_left=None,
379395
padding_bottom_right=None, padding=None, max_zoom=None):
380396
"""Fit the map to contain a bounding box with the

0 commit comments

Comments
 (0)