@@ -11,6 +11,7 @@ import type { LoaderOptions } from '@googlemaps/js-api-loader';
1111import { Loader } from '@googlemaps/js-api-loader' ;
1212import AbstractMapController from '@symfony/ux-map' ;
1313import type {
14+ Icon ,
1415 InfoWindowWithoutPositionDefinition ,
1516 MarkerDefinition ,
1617 Point ,
@@ -55,6 +56,8 @@ export default class extends AbstractMapController<
5556
5657 declare map : google . maps . Map ;
5758
59+ public parser : DOMParser ;
60+
5861 async connect ( ) {
5962 if ( ! _google ) {
6063 _google = { maps : { } as typeof google . maps } ;
@@ -88,6 +91,7 @@ export default class extends AbstractMapController<
8891 }
8992
9093 super . connect ( ) ;
94+ this . parser = new DOMParser ( ) ;
9195 }
9296
9397 public centerValueChanged ( ) : void {
@@ -139,7 +143,7 @@ export default class extends AbstractMapController<
139143 } : {
140144 definition : MarkerDefinition < google . maps . marker . AdvancedMarkerElementOptions , google . maps . InfoWindowOptions > ;
141145 } ) : 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 ;
143147
144148 const marker = new _google . maps . marker . AdvancedMarkerElement ( {
145149 position,
@@ -153,6 +157,10 @@ export default class extends AbstractMapController<
153157 this . createInfoWindow ( { definition : infoWindow , element : marker } ) ;
154158 }
155159
160+ if ( icon ) {
161+ this . doCreateIcon ( { definition : icon , element : marker } ) ;
162+ }
163+
156164 return marker ;
157165 }
158166
@@ -297,6 +305,26 @@ export default class extends AbstractMapController<
297305 return content ;
298306 }
299307
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+
300328 private closeInfoWindowsExcept ( infoWindow : google . maps . InfoWindow ) {
301329 this . infoWindows . forEach ( ( otherInfoWindow ) => {
302330 if ( otherInfoWindow !== infoWindow ) {
0 commit comments