Repository navigation
Keep natural image size for CustomIcon without icon_size - #2334
Open
KhadeerBasha1232 wants to merge 1 commit into
Open
KhadeerBasha1232 wants to merge 1 commit into
KhadeerBasha1232 wants to merge 1 commit into
Conversation
Leaflet reuses the default marker's <img> when setIcon swaps in another image icon, and keeps its inline width, height and margins when the new icon does not set them. A CustomIcon without icon_size was therefore shown at the default icon's 25x41 px. Clear those styles before calling setIcon. Closes python-visualization#1934 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was previously deployed
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.
Closes #1934
Problem
A
CustomIconwithouticon_sizeis shown at 25×41 px (the size of Leaflet's default marker) instead of the image's own size, so non-square logos get squashed.Cause
folium creates the marker with Leaflet's default icon and then calls
setIcon(). When both icons are images, Leaflet reuses the existing<img>element and only overwriteswidth,heightand the margins if the new icon sets them. WithouticonSize, the default icon's inline styles stay behind.Fix
Before calling
setIcon(),Marker.SetIconclears the inlinewidth,height,marginLeftandmarginTopof the current marker element (via the publicgetElement()). Icons that define a size or anchor set them again as before. The cleanup uses a block-scopedconst, so repeated saves still produce identical HTML (#2237).Checked in a browser
CustomIcon(120×40 image), noicon_sizeCustomIconwithicon_size=(60, 20)CustomIconwith onlyicon_anchorCustomIconinsideMarkerClusterIcon/DivIconChanges
folium/map.py: clear stale inline styles inMarker.SetIcon.folium/features.py: document that the natural image size is used whenicon_sizeis not given.tests/test_map.py: test that the styles are cleared beforesetIcon.