Skip to content

Add a time named argument to to_png #764

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 4 commits into from
Nov 2, 2017
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: 13 additions & 3 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,18 @@ def _repr_html_(self, **kwargs):
out = self._parent._repr_html_(**kwargs)
return out

def _to_png(self):
"""Export the HTML to byte representation of a PNG image."""
def _to_png(self, delay=3):
"""Export the HTML to byte representation of a PNG image.

Uses Phantom JS to render the HTML and record a PNG. You may need to
adjust the `delay` time keyword argument if maps render without data or tiles.

Examples
--------
>>> map._to_png()
>>> map._to_png(time=10) # Wait 10 seconds between render and snapshot.
"""

if self._png_image is None:
import selenium.webdriver

Expand All @@ -284,7 +294,7 @@ def _to_png(self):
driver.execute_script("document.body.style.width = '100%';") # noqa
# We should probably monitor if some element is present,
# but this is OK for now.
time.sleep(3)
time.sleep(delay)
png = driver.get_screenshot_as_png()
driver.quit()
self._png_image = png
Expand Down