fix: use viewport units for percentage map dimensions (fixes #2186)#2229
Open
Kakarot35 wants to merge 6 commits into
Open
fix: use viewport units for percentage map dimensions (fixes #2186)#2229Kakarot35 wants to merge 6 commits into
Kakarot35 wants to merge 6 commits into
Conversation
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.