@@ -11,6 +11,7 @@ import type { LoaderOptions } from '@googlemaps/js-api-loader';
11
11
import { Loader } from '@googlemaps/js-api-loader' ;
12
12
import AbstractMapController from '@symfony/ux-map' ;
13
13
import type {
14
+ Icon ,
14
15
InfoWindowWithoutPositionDefinition ,
15
16
MarkerDefinition ,
16
17
Point ,
@@ -55,6 +56,8 @@ export default class extends AbstractMapController<
55
56
56
57
declare map : google . maps . Map ;
57
58
59
+ public parser : DOMParser ;
60
+
58
61
async connect ( ) {
59
62
if ( ! _google ) {
60
63
_google = { maps : { } as typeof google . maps } ;
@@ -88,6 +91,7 @@ export default class extends AbstractMapController<
88
91
}
89
92
90
93
super . connect ( ) ;
94
+ this . parser = new DOMParser ( ) ;
91
95
}
92
96
93
97
public centerValueChanged ( ) : void {
@@ -139,7 +143,7 @@ export default class extends AbstractMapController<
139
143
} : {
140
144
definition : MarkerDefinition < google . maps . marker . AdvancedMarkerElementOptions , google . maps . InfoWindowOptions > ;
141
145
} ) : google . maps . marker . AdvancedMarkerElement {
142
- const { '@id' : _id , position, title, infoWindow, extra, rawOptions = { } , ...otherOptions } = definition ;
146
+ const { '@id' : _id , position, title, infoWindow, icon , extra, rawOptions = { } , ...otherOptions } = definition ;
143
147
144
148
const marker = new _google . maps . marker . AdvancedMarkerElement ( {
145
149
position,
@@ -153,6 +157,10 @@ export default class extends AbstractMapController<
153
157
this . createInfoWindow ( { definition : infoWindow , element : marker } ) ;
154
158
}
155
159
160
+ if ( icon ) {
161
+ this . doCreateIcon ( { definition : icon , element : marker } ) ;
162
+ }
163
+
156
164
return marker ;
157
165
}
158
166
@@ -297,6 +305,26 @@ export default class extends AbstractMapController<
297
305
return content ;
298
306
}
299
307
308
+ protected doCreateIcon ( {
309
+ definition,
310
+ element,
311
+ } : {
312
+ definition : Icon ;
313
+ element : google . maps . marker . AdvancedMarkerElement ;
314
+ } ) : void {
315
+ const { content, type, width, height } = definition ;
316
+ if ( type === 'inline-svg' ) {
317
+ const icon = this . parser . parseFromString ( content , 'image/svg+xml' ) . documentElement ;
318
+ element . content = icon ;
319
+ } else {
320
+ const icon = document . createElement ( 'img' ) ;
321
+ icon . width = width ;
322
+ icon . height = height ;
323
+ icon . src = content ;
324
+ element . content = icon ;
325
+ }
326
+ }
327
+
300
328
private closeInfoWindowsExcept ( infoWindow : google . maps . InfoWindow ) {
301
329
this . infoWindows . forEach ( ( otherInfoWindow ) => {
302
330
if ( otherInfoWindow !== infoWindow ) {
0 commit comments