Skip to content

Commit

Permalink
Add a time named argument to to_png (#764)
Browse files Browse the repository at this point in the history
* Add a `time` named argument to `to_png`

Since it might take longer than 3 seconds to render the map, this adds a time named arg that allows you to delay the screenshot.

* Fix lints, builtin clobber and docstring

* fix trailing whitespace

* one more :-(
  • Loading branch information
hunterowens authored and ocefpaf committed Nov 2, 2017
1 parent fe46557 commit f8a12a6
Showing 1 changed file with 13 additions and 3 deletions.
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

0 comments on commit f8a12a6

Please sign in to comment.