@@ -195,6 +195,7 @@ class Map(JSCSSMixin, Evented):
195195 height: {{this.height[0]}}{{this.height[1]}};
196196 min-height: {{this.height[0]}}{{this.height[1]}};
197197 {%- endif %}
198+
198199 left: {{this.left[0]}}{{this.left[1]}};
199200 top: {{this.top[0]}}{{this.top[1]}};
200201 }
@@ -209,6 +210,15 @@ class Map(JSCSSMixin, Evented):
209210 }
210211 </style>
211212
213+ <style>#map {
214+ position:absolute;
215+ top:0;
216+ bottom:0;
217+ right:0;
218+ left:0;
219+ }
220+ </style>
221+
212222 <script>
213223 L_NO_TOUCH = {{ this.global_switches.no_touch |tojson}};
214224 L_DISABLE_3D = {{ this.global_switches.disable_3d|tojson }};
@@ -302,10 +312,8 @@ def __init__(
302312 # Map Size Parameters.
303313 self .width = _parse_size (width )
304314 self .height = _parse_size (height )
305-
306315 self ._height_is_percent = self .height [1 ] == "%"
307316 self ._width_is_percent = self .width [1 ] == "%"
308-
309317 self .left = _parse_size (left )
310318 self .top = _parse_size (top )
311319 self .position = position
@@ -373,15 +381,16 @@ def _to_png(
373381 Examples
374382 --------
375383 >>> m._to_png()
376- >>> m._to_png(time =10) # Wait 10 seconds between render and snapshot.
384+ >>> m._to_png(delay =10) # Wait 10 seconds between render and snapshot.
377385
378386 """
379387
380388 if self ._png_image is None :
381389 if driver is None :
382390 from selenium import webdriver
391+ from selenium .webdriver .firefox .options import Options
383392
384- options = webdriver . firefox . options . Options ()
393+ options = Options ()
385394 options .add_argument ("--headless" )
386395 driver = webdriver .Firefox (options = options )
387396
@@ -396,11 +405,16 @@ def _to_png(
396405 * size ,
397406 )
398407 driver .set_window_size (* window_size )
408+ from selenium .webdriver .support .ui import WebDriverWait
409+
399410 html = self .get_root ().render ()
400411 with temp_html_filepath (html ) as fname :
401412 # We need the tempfile to avoid JS security issues.
402413 driver .get (f"file:///{ fname } " )
403- time .sleep (delay )
414+ WebDriverWait (driver , delay ).until (
415+ lambda _driver : _driver .execute_script ("return document.readyState" )
416+ == "complete"
417+ )
404418 div = driver .find_element ("class name" , "folium-map" )
405419 png = div .screenshot_as_png
406420 driver .quit ()
0 commit comments