@@ -36,20 +36,34 @@ function loadIcon(
36
36
const wasInCache = ! ! dataUrl ;
37
37
if ( ! dataUrl ) {
38
38
const div = document . createElement ( "div" ) ;
39
+
39
40
const root = createRoot ( div ) ;
40
- flushSync ( ( ) => {
41
- const [ categoryIconName , accessibilityGrade ] = finalIconName . split ( "-" ) ;
42
- const IconComponent =
43
- categoryIconName && accessibilityGrade
44
- ? icons [ categoryIconName ]
45
- : icons [ iconName ] ;
46
- const element = accessibilityGrade ? (
47
- < ColoredIconMarker accessibilityGrade = { accessibilityGrade } >
48
- < IconComponent />
49
- </ ColoredIconMarker >
50
- ) : (
41
+ const [ categoryIconName , accessibilityGrade ] = finalIconName . split ( "-" ) ;
42
+ const IconComponent =
43
+ categoryIconName && accessibilityGrade
44
+ ? icons [ categoryIconName ]
45
+ : icons [ iconName ] ;
46
+
47
+ // Marker color originates from a CSS variable value like `var(--rating-yes)`
48
+ const style = getComputedStyle ( document . documentElement ) ;
49
+ const backgroundColor = style . getPropertyValue (
50
+ `--rating-${ accessibilityGrade } ` ,
51
+ ) ;
52
+ const foregroundColor = style . getPropertyValue (
53
+ `--rating-${ accessibilityGrade } -contrast` ,
54
+ ) ;
55
+ const element = accessibilityGrade ? (
56
+ < ColoredIconMarker
57
+ accessibilityGrade = { accessibilityGrade }
58
+ backgroundColor = { backgroundColor }
59
+ >
51
60
< IconComponent />
52
- ) ;
61
+ </ ColoredIconMarker >
62
+ ) : (
63
+ < IconComponent />
64
+ ) ;
65
+
66
+ flushSync ( ( ) => {
53
67
root . render ( element ) ;
54
68
} ) ;
55
69
const svgElement = div . querySelector ( "svg" ) ;
@@ -76,13 +90,12 @@ function loadIcon(
76
90
`scale(${ options . iconSize } , ${ options . iconSize } )` ,
77
91
) ;
78
92
}
79
- if ( options ?. fill ) {
80
- const filledElements = iconElement . querySelectorAll (
93
+ const filledElements =
94
+ iconElement ? .querySelectorAll (
81
95
"path, rect, circle, ellipse, line, polyline, polygon" ,
82
- ) ;
83
- for ( const e of filledElements ) {
84
- e . setAttribute ( "fill" , options . fill ) ;
85
- }
96
+ ) ?? [ ] ;
97
+ for ( const e of filledElements ) {
98
+ e . setAttribute ( "fill" , options . fill ?? foregroundColor ) ;
86
99
}
87
100
88
101
if ( options . addShadow ) {
@@ -147,13 +160,11 @@ export function loadIconsInMapInstance(mapInstance: MapBoxMap): void {
147
160
for ( const iconName of Object . keys ( categoryIcons ) ) {
148
161
for ( const accessibilityGrade of [ "yes" , "no" , "limited" ] ) {
149
162
loadIcon ( mapInstance , categoryIcons , iconName , {
150
- fill : "white" ,
151
163
addShadow : true ,
152
164
suffix : `-${ accessibilityGrade } ` ,
153
165
} ) ;
154
166
}
155
167
loadIcon ( mapInstance , categoryIcons , iconName , {
156
- fill : "#666" ,
157
168
addShadow : true ,
158
169
suffix : "-unknown" ,
159
170
iconSize : 0.8 ,
0 commit comments