Skip to content

Commit f8a12a6

Browse files
hunterowensocefpaf
authored andcommitted
Add a time named argument to to_png (#764)
* 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 :-(
1 parent fe46557 commit f8a12a6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

folium/folium.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,18 @@ def _repr_html_(self, **kwargs):
267267
out = self._parent._repr_html_(**kwargs)
268268
return out
269269

270-
def _to_png(self):
271-
"""Export the HTML to byte representation of a PNG image."""
270+
def _to_png(self, delay=3):
271+
"""Export the HTML to byte representation of a PNG image.
272+
273+
Uses Phantom JS to render the HTML and record a PNG. You may need to
274+
adjust the `delay` time keyword argument if maps render without data or tiles.
275+
276+
Examples
277+
--------
278+
>>> map._to_png()
279+
>>> map._to_png(time=10) # Wait 10 seconds between render and snapshot.
280+
"""
281+
272282
if self._png_image is None:
273283
import selenium.webdriver
274284

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

0 commit comments

Comments
 (0)