Repository navigation
Reset the previous icon's styles when a marker reuses its element - #10538
Merged
Merged
Conversation
Marker#setIcon hands the current element to the new icon, but _setIconStyles, DivIcon#createIcon and Icon#_createIcon only write what the new icon defines. Whatever it leaves out stays on the element from the old icon: width, height, margins, transform origin, background position and crossOrigin. An icon sized by CSS keeps the old inline size, and an image that doesn't allow CORS fails to load under the old crossOrigin.
mourner
requested changes
Nov 7, 2026
mourner
approved these changes
Nov 7, 2026
simon04
pushed a commit
to maplair/maplair
that referenced
this pull request
Nov 8, 2026
The size, anchor, background position and crossOrigin of the previous icon stayed on the reused element if the new icon didn't set them. Leaflet: Leaflet/Leaflet#10538 Leaflet commit: Leaflet/Leaflet@96ed26a
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.
setIconreuses the marker's element, but the icon only writes what it defines. Whatever the new icon leaves out stays from the old one:backgroundPositionfrom aDivIconbgPoscrossOrigin, so an image from a host without CORS headers can fail to loadFor example,
setIcon(new DivIcon({iconSize: 'auto'}))on a defaultDivIconstays 12×12, because the inline size wins over CSS. With[100, 'auto']the height stays too, becauseautopxis an invalid value and gets ignored._setIconStylesnow clears these before setting them, so a reused element looks like a fresh one.DivIconandIcondo the same forbackgroundPositionandcrossOrigin.