fix: icon element is undefined when clustered

This commit is contained in:
Yohan Boniface 2024-01-08 16:35:41 +01:00
parent 16a42025b5
commit 067d74de9f

View file

@ -208,15 +208,16 @@ L.U.Icon.makeIconElement = function (src, parent) {
return icon return icon
} }
L.U.Icon.setIconContrast = function (el, parent, src, bgcolor) { L.U.Icon.setIconContrast = function (icon, parent, src, bgcolor) {
/* /*
* el: the element we'll adapt the style, it can be an image or text * icon: the element we'll adapt the style, it can be an image or text
* parent: the element we'll consider to decide whether to adapt the style, * parent: the element we'll consider to decide whether to adapt the style,
* by looking at its background color * by looking at its background color
* src: the raw "icon" value, can be an URL, a path, text, emoticon, etc. * src: the raw "icon" value, can be an URL, a path, text, emoticon, etc.
* bgcolor: the background color, used for caching and in case we cannot guess the * bgcolor: the background color, used for caching and in case we cannot guess the
* parent background color * parent background color
*/ */
if (!icon) return
if (L.DomUtil.contrastedColor(parent, bgcolor)) { if (L.DomUtil.contrastedColor(parent, bgcolor)) {
// Decide whether to switch svg to white or not, but do it // Decide whether to switch svg to white or not, but do it
@ -224,10 +225,10 @@ L.U.Icon.setIconContrast = function (el, parent, src, bgcolor) {
if (L.Util.isPath(src) && src.endsWith('.svg')) { if (L.Util.isPath(src) && src.endsWith('.svg')) {
// Must be called after icon container is added to the DOM // Must be called after icon container is added to the DOM
// An image // An image
el.style.filter = 'invert(1)' icon.style.filter = 'invert(1)'
} else if (!el.src) { } else if (!icon.src) {
// Text icon // Text icon
el.style.color = 'white' icon.style.color = 'white'
} }
} }
} }