11import { isEqual } from "lodash-es" ;
2- import { FC , useEffect , useState } from "react" ;
2+ import { FC , useEffect , useMemo , useState } from "react" ;
33
44import { useT } from "@reearth/services/i18n" ;
55import { styled , usePublishTheme } from "@reearth/services/theme" ;
@@ -8,7 +8,7 @@ import { ComponentProps as WidgetProps } from "..";
88import { Credits } from "../../Engine/ref" ;
99
1010import ContentModal from "./ContentModal" ;
11- import useCredits from "./useCredits" ;
11+ import useCredits , { ProcessedCredit } from "./useCredits" ;
1212
1313export type Props = WidgetProps < DataAttributionWidgetProperty > ;
1414
@@ -21,13 +21,39 @@ export type DataAttributionWidgetProperty = {
2121 } [ ] ;
2222} ;
2323
24- const DataAttribution : FC < Props > = ( { onGetCredits, sceneProperty, widget } ) => {
24+ const DataAttribution : FC < Props > = ( {
25+ onGetCredits,
26+ sceneProperty,
27+ widget,
28+ hasVisibleReearthBuildingsLayers,
29+ } ) => {
2530 const t = useT ( ) ;
2631 const [ visible , setVisible ] = useState ( false ) ;
2732 const [ credits , setCredits ] = useState < Credits > ( ) ;
2833
2934 const publishedTheme = usePublishTheme ( sceneProperty ?. theme ) ;
3035
36+ // Check for visible reearth-buildings tileset layers
37+ // This effect will run whenever hasVisibleReearthBuildingsLayers changes (layer added/removed/visibility changed)
38+ useEffect ( ( ) => {
39+ if ( hasVisibleReearthBuildingsLayers ) {
40+ console . log (
41+ "[Re:Earth] Visible reearth-buildings tileset layers detected" ,
42+ hasVisibleReearthBuildingsLayers ,
43+ ) ;
44+ }
45+ } , [ hasVisibleReearthBuildingsLayers ] ) ;
46+
47+ const layerCredits : ProcessedCredit [ ] = useMemo ( ( ) => {
48+ if ( ! hasVisibleReearthBuildingsLayers ) return [ ] ;
49+ return [
50+ {
51+ builtinHtml :
52+ '<a href="https://buildings.reearth.land/" target="_blank" rel="noopener">Re:Earth Buildings</a> — Buildings © <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap contributors</a>, <a href="https://overturemaps.org/" target="_blank" rel="noopener">Overture Maps Foundation</a> (ODbL)<br/> Terrain by <a href="https://terrain.reearth.land/" target="_blank" rel="noopener">Re:Earth Terrain</a> (Mapterhorn / EGM2008)' ,
53+ } ,
54+ ] ;
55+ } , [ hasVisibleReearthBuildingsLayers ] ) ;
56+
3157 useEffect ( ( ) => {
3258 let intervalId : NodeJS . Timeout | null = null ;
3359
@@ -48,7 +74,14 @@ const DataAttribution: FC<Props> = ({ onGetCredits, sceneProperty, widget }) =>
4874 } ;
4975 } , [ onGetCredits , credits ] ) ;
5076
51- const { cesiumCredit, otherCredits } = useCredits ( { credits, property : widget . property } ) ;
77+ const { cesiumCredit, otherCredits, googleCredit } = useCredits ( {
78+ credits,
79+ property : widget . property ,
80+ } ) ;
81+
82+ const modalCredits = useMemo ( ( ) => {
83+ return [ ...( otherCredits ?? [ ] ) , ...layerCredits ] ;
84+ } , [ layerCredits , otherCredits ] ) ;
5285
5386 return (
5487 < Wrapper >
@@ -57,11 +90,20 @@ const DataAttribution: FC<Props> = ({ onGetCredits, sceneProperty, widget }) =>
5790 < img src = { cesiumCredit . logo } title = { cesiumCredit . description } />
5891 </ CesiumLink >
5992 ) }
93+ { googleCredit && (
94+ < GoogleLink target = "_blank" rel = "noreferrer" aria-label = { googleCredit . description } >
95+ < img
96+ src = { googleCredit . logo }
97+ alt = { googleCredit . description }
98+ title = { googleCredit . description }
99+ />
100+ </ GoogleLink >
101+ ) }
60102 < DataLink onClick = { ( ) => setVisible ( true ) } > { t ( "Data Attribution" ) } </ DataLink >
61103 < ContentModal
62104 publishedTheme = { publishedTheme }
63105 visible = { visible }
64- credits = { otherCredits }
106+ credits = { modalCredits }
65107 onClose = { ( ) => setVisible ( false ) }
66108 />
67109 </ Wrapper >
@@ -87,4 +129,8 @@ const DataLink = styled("div")(() => ({
87129 padding : 4 ,
88130} ) ) ;
89131
132+ const GoogleLink = styled ( "a" ) ( ( ) => ( {
133+ height : 18 ,
134+ } ) ) ;
135+
90136export default DataAttribution ;
0 commit comments