diff --git a/src/r3f/README.md b/src/r3f/README.md
index 9cac94d76..ed2f8a4c4 100644
--- a/src/r3f/README.md
+++ b/src/r3f/README.md
@@ -205,7 +205,16 @@ The `TilesAttributionOverlay` component must be embedded in a tile set and will
```jsx
-
+
```
diff --git a/src/r3f/components/CanvasDOMOverlay.jsx b/src/r3f/components/CanvasDOMOverlay.jsx
index 07116c2d8..c63af7e26 100644
--- a/src/r3f/components/CanvasDOMOverlay.jsx
+++ b/src/r3f/components/CanvasDOMOverlay.jsx
@@ -31,7 +31,7 @@ export function CanvasDOMOverlay( { children, ...rest } ) {
container.style.pointerEvents = 'none';
container.style.position = 'absolute';
- document.body.appendChild( container );
+ gl.domElement.parentNode.appendChild( container );
return () => {
diff --git a/src/r3f/components/TilesAttributionOverlay.jsx b/src/r3f/components/TilesAttributionOverlay.jsx
index ef9dfdfde..124b727cc 100644
--- a/src/r3f/components/TilesAttributionOverlay.jsx
+++ b/src/r3f/components/TilesAttributionOverlay.jsx
@@ -3,7 +3,7 @@ import { TilesRendererContext } from './TilesRenderer.jsx';
import { CanvasDOMOverlay } from './CanvasDOMOverlay.jsx';
// Overlay for displaying tile data set attributions
-export function TilesAttributionOverlay( { children, style, ...rest } ) {
+export function TilesAttributionOverlay( { children, style, generateAttributions, ...rest } ) {
const tiles = useContext( TilesRendererContext );
const [ attributions, setAttributions ] = useState( [] );
@@ -46,33 +46,6 @@ export function TilesAttributionOverlay( { children, style, ...rest } ) {
}, [ tiles ] );
- // generate elements for each type of attribution
- const output = [];
- attributions.forEach( ( att, i ) => {
-
- let element = null;
- if ( att.type === 'string' ) {
-
- element =
{ att.value }
;
-
- } else if ( att.type === 'html' ) {
-
- element = ;
-
- } else if ( att.type === 'image' ) {
-
- element = ;
-
- }
-
- if ( element ) {
-
- output.push( element );
-
- }
-
- } );
-
// Generate CSS for modifying child elements implicit to the html attributions
const classId = useMemo( () => 'class_' + window.crypto.randomUUID(), [] );
const styles = useMemo( () => `
@@ -87,6 +60,49 @@ export function TilesAttributionOverlay( { children, style, ...rest } ) {
}
`, [ classId ] );
+ let output;
+ if ( generateAttributions ) {
+
+ output = generateAttributions( attributions, classId );
+
+ } else {
+
+ // generate elements for each type of attribution
+ const elements = [];
+ attributions.forEach( ( att, i ) => {
+
+ let element = null;
+ if ( att.type === 'string' ) {
+
+ element = { att.value }
;
+
+ } else if ( att.type === 'html' ) {
+
+ element = ;
+
+ } else if ( att.type === 'image' ) {
+
+ element = ;
+
+ }
+
+ if ( element ) {
+
+ elements.push( element );
+
+ }
+
+ } );
+
+ output = (
+ <>
+
+ { elements }
+ >
+ );
+
+ }
+
return (
-
{ children }
{ output }