@@ -161,10 +161,8 @@ export const Marker3D = forwardRef(function Marker3D(
161161 const [ contentContainer , setContentContainer ] =
162162 useState < HTMLDivElement | null > ( null ) ;
163163
164- // Track whether we need the interactive variant
165164 const isInteractive = Boolean ( onClick ) ;
166165
167- // Expose marker element via ref
168166 useImperativeHandle (
169167 ref ,
170168 ( ) =>
@@ -174,7 +172,6 @@ export const Marker3D = forwardRef(function Marker3D(
174172 [ marker ]
175173 ) ;
176174
177- // Create marker element and attach to map
178175 useEffect ( ( ) => {
179176 if ( ! map3d || ! maps3dLibrary ) return ;
180177
@@ -188,50 +185,42 @@ export const Marker3D = forwardRef(function Marker3D(
188185 newMarker = new maps3dLibrary . Marker3DElement ( ) ;
189186 }
190187
191- // Append marker to map3d element
192188 map3d . appendChild ( newMarker ) ;
193189 setMarker ( newMarker ) ;
194190
195- // Create content container for children
191+ // Hidden container used as React portal target for custom marker content
196192 const container = document . createElement ( 'div' ) ;
197193 container . style . display = 'none' ;
198194 document . body . appendChild ( container ) ;
199195 setContentContainer ( container ) ;
200196
201197 return ( ) => {
202- // Remove marker from map
203198 if ( newMarker . parentElement ) {
204199 newMarker . parentElement . removeChild ( newMarker ) ;
205200 }
206- // Clean up content container
207201 container . remove ( ) ;
208202 setMarker ( null ) ;
209203 setContentContainer ( null ) ;
210204 } ;
211205 } , [ map3d , maps3dLibrary , isInteractive ] ) ;
212206
213- // Sync position prop
214207 useEffect ( ( ) => {
215208 if ( ! marker || position === undefined ) return ;
216209 marker . position = position ;
217210 } , [ marker , position ] ) ;
218211
219- // Sync altitudeMode prop
220212 useEffect ( ( ) => {
221213 if ( ! marker || altitudeMode === undefined ) return ;
222214 marker . altitudeMode =
223215 altitudeMode as unknown as google . maps . maps3d . AltitudeMode ;
224216 } , [ marker , altitudeMode ] ) ;
225217
226- // Sync collisionBehavior prop
227218 useEffect ( ( ) => {
228219 if ( ! marker || collisionBehavior === undefined ) return ;
229- // Cast to the google.maps.CollisionBehavior type expected by Marker3DElement
230220 marker . collisionBehavior =
231221 collisionBehavior as google . maps . CollisionBehavior ;
232222 } , [ marker , collisionBehavior ] ) ;
233223
234- // Sync simple props
235224 useEffect ( ( ) => {
236225 if ( ! marker ) return ;
237226 if ( drawsWhenOccluded !== undefined )
@@ -258,29 +247,25 @@ export const Marker3D = forwardRef(function Marker3D(
258247 if ( zIndex !== undefined ) marker . zIndex = zIndex ;
259248 } , [ marker , zIndex ] ) ;
260249
261- // Sync title prop (interactive only)
250+ // title is only available on Marker3DInteractiveElement
262251 useEffect ( ( ) => {
263252 if ( ! marker || ! isInteractive ) return ;
264253 const interactiveMarker =
265254 marker as google . maps . maps3d . Marker3DInteractiveElement ;
266255 if ( title !== undefined ) interactiveMarker . title = title ;
267256 } , [ marker , title , isInteractive ] ) ;
268257
269- // Bind click event for interactive marker
270258 useDomEventListener ( marker , 'gmp-click' , onClick ) ;
271259
272- // Process children and move to marker slot with template wrapping
260+ // Move React children to marker's slot, wrapping img/svg in < template> as required by the API
273261 useLayoutEffect ( ( ) => {
274- // Skip if a child component (like Pin) is handling content
275262 if ( contentHandledExternally ) return ;
276263 if ( ! marker || ! contentContainer ) return ;
277264
278- // Clear any existing slotted content
279265 while ( marker . firstChild ) {
280266 marker . removeChild ( marker . firstChild ) ;
281267 }
282268
283- // Process each child node in the content container
284269 const childNodes = Array . from ( contentContainer . childNodes ) ;
285270
286271 for ( const node of childNodes ) {
@@ -290,24 +275,20 @@ export const Marker3D = forwardRef(function Marker3D(
290275 const tagName = element . tagName . toLowerCase ( ) ;
291276
292277 if ( tagName === 'img' || tagName === 'svg' ) {
293- // Wrap img and svg in template element
294278 const template = document . createElement ( 'template' ) ;
295279 template . content . appendChild ( element . cloneNode ( true ) ) ;
296280 marker . appendChild ( template ) ;
297281 } else {
298- // Append other elements directly (e.g., PinElement)
299282 marker . appendChild ( element . cloneNode ( true ) ) ;
300283 }
301284 }
302285 } , [ marker , contentContainer , children , contentHandledExternally ] ) ;
303286
304- // Memoize context value
305287 const contextValue = useMemo (
306288 ( ) => ( { marker, setContentHandledExternally} ) ,
307289 [ marker ]
308290 ) ;
309291
310- // Render children into hidden container, then useLayoutEffect moves them
311292 if ( ! contentContainer ) return null ;
312293
313294 return (
0 commit comments