fix: use viewport units for percentage map dimensions (fixes #2186)#2229
fix: use viewport units for percentage map dimensions (fixes #2186)#2229Kakarot35 wants to merge 7 commits into
Conversation
| *size, | ||
| ) | ||
| driver.set_window_size(*window_size) | ||
| from selenium.webdriver.support.ui import WebDriverWait |
There was a problem hiding this comment.
Not sure why these changes are necessary? Did you branch from an older version of the code? This was changed not too long ago. Using WebDriverWait ensures we wait only until the appropriate conditions are met, instead of waiting a fixed amount of time.
|
Apart from the change that removed WebDriverWait, this looks like a great addition. Could you rebase the change on latest master, so we don't have the problem documentation not building? |
fbaa932 to
55d9426
Compare
|
@hansthen Thanks for the feedback! I see that you are correct, since it was based off of an earlier version, my branch accidentally stripped out WebDriverWait. However, I have rebased back to the current main and put folium/folium.py back into upstream with only the viewport unit updates. The WebDriverWait functionality remains completely intact. |
|
@hansthen I will open another PR for the formatting error in GroupedLayerControl documentation. I think the problem with network timeout to pae-paha.pacioos.hawaii.edu is due to external server connection - please advise whether I should look into that as well. |
Fixes #2186
Problem
folium.Map(height='100%')collapses to nearly zero height when the mapis embedded inside a Django or Flask template. This happens because
height: 100%in CSS requires every ancestor element to have an explicitheight — which page templates typically don't have.
Similarly,
folium.Map(height='1000px')can shrink in a non-maximizedbrowser window because there is no minimum floor set.
Changes
Viewport units for percentages: when
heightorwidthis given asa percentage, emit
vh/vwinstead of%. Viewport units are alwaysrelative to the browser window size, not the ancestor chain, so they work
correctly in both standalone and embedded (Django/Flask) contexts.
Min constraints for pixel sizes: when
heightorwidthis given inpixels, also emit
min-height/min-widthso the map cannot shrink belowits intended size in a smaller window.
Remove dead CSS rule: the template was emitting
#map { position:absolute; ... }which never matched anything — foliumuses hashed IDs like
map_d7a447c..., notmap. Removed.Before / After
Tests
13 new tests added covering percentage → viewport units, pixel → min
constraints, dead rule removal, and full backwards compatibility.