Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Feat] render dataset attributions in map container (#2148)
Igor Dykhta06f085db6fc1
diff --git a/src/components/src/common/styled-components.tsx b/src/components/src/common/styled-components.tsxindex cc743d4ec..a10847f3f 100644--- a/src/components/src/common/styled-components.tsx+++ b/src/components/src/common/styled-components.tsx@@ -67,6 +67,12 @@ export const CenterVerticalFlexbox = styled.div`align-items: center;`;+export const EndHorizontalFlexbox = styled.div`+ display: flex;+ flex-direction: row;+ align-items: end;+`;+export const SpaceBetweenFlexbox = styled.div`display: flex;justify-content: space-between;@@ -541,7 +547,7 @@ export const StyledAttrbution = styled.div.attrs({position: absolute;display: block;margin: 0 10px 6px;- z-index: 0;+ z-index: 1;.attrition-link {display: flex;align-items: center;diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsxindex 9b8801ff9..4b330794e 100644--- a/src/components/src/map-container.tsx+++ b/src/components/src/map-container.tsx@@ -31,7 +31,11 @@ import {VisStateActions, MapStateActions, UIStateActions} from '@kepler.gl/actio// componentsimport MapPopoverFactory from './map/map-popover';import MapControlFactory from './map/map-control';-import {StyledMapContainer, StyledAttrbution} from './common/styled-components';+import {+ StyledMapContainer,+ StyledAttrbution,+ EndHorizontalFlexbox+} from './common/styled-components';import EditorFactory from './editor/editor';@@ -71,6 +75,7 @@ import {} from '@kepler.gl/constants';import ErrorBoundary from './common/error-boundary';+import {DatasetAttribution} from './types';import {LOCALE_CODES} from '@kepler.gl/localization';import {MapView} from '@deck.gl/core';import {@@ -132,50 +137,99 @@ const MapboxLogo = () => (</div>);-export const Attribution = ({showMapboxLogo = true}) => {+interface StyledDatasetAttributionsContainerProps {+ isPalm: boolean;+}++const StyledDatasetAttributionsContainer = styled.div<StyledDatasetAttributionsContainerProps>`+ width: ${props => (props.isPalm ? '130px' : '180px')};+ text-overflow: ellipsis;+ white-space: nowrap;+ overflow: hidden;+ color: ${props => props.theme.labelColor};+ margin-right: 2px;+ line-height: ${props => (props.isPalm ? '1em' : '1.4em')};+ :hover {+ white-space: inherit;+ }+`;++const DatasetAttributions = ({+ datasetAttributions,+ isPalm+}: {+ datasetAttributions: DatasetAttribution[];+ isPalm: boolean;+}) => (+ <>+ {datasetAttributions?.length ? (+ <StyledDatasetAttributionsContainer isPalm={isPalm}>+ {datasetAttributions.map((ds, idx) => (+ <a href={ds.url} target="_blank" rel="noopener noreferrer" key={`${ds.title}_${idx}`}>+ {ds.title}+ {idx !== datasetAttributions.length - 1 ? ', ' : null}+ </a>+ ))}+ </StyledDatasetAttributionsContainer>+ ) : null}+ </>+);++export const Attribution = ({+ showMapboxLogo = true,+ showOsmBasemapAttribution = false,+ datasetAttributions+}) => {const isPalm = hasMobileWidth(breakPointValues);const memoizedComponents = useMemo(() => {if (!showMapboxLogo) {return (<StyledAttrbution>- <a- href="http://www.openstreetmap.org/copyright"- target="_blank"- rel="noopener noreferrer"- >- © OpenStreetMap- </a>+ <EndHorizontalFlexbox>+ <DatasetAttributions datasetAttributions={datasetAttributions} isPalm={isPalm} />+ {showOsmBasemapAttribution ? (+ <div className="attrition-link">+ <a+ href="http://www.openstreetmap.org/copyright"+ target="_blank"+ rel="noopener noreferrer"+ >+ © OpenStreetMap+ </a>+ </div>+ ) : null}+ </EndHorizontalFlexbox></StyledAttrbution>);}return (<StyledAttrbution>- {isPalm ? <MapboxLogo /> : null}- <div className="attrition-link">- <a href="https://kepler.gl/policy/" target="_blank" rel="noopener noreferrer">- © kepler.gl |{' '}- </a>- <a href="https://www.mapbox.com/about/maps/" target="_blank" rel="noopener noreferrer">- © Mapbox |{' '}- </a>- <a- href="http://www.openstreetmap.org/copyright"- target="_blank"- rel="noopener noreferrer"- >- © OpenStreetMap |{' '}- </a>- <a href="https://www.mapbox.com/map-feedback/" target="_blank" rel="noopener noreferrer">- <strong>Improve this map </strong>- {!isPalm ? <strong> | </strong> : null}- </a>- {!isPalm ? <MapboxLogo /> : null}- </div>+ <EndHorizontalFlexbox>+ <DatasetAttributions datasetAttributions={datasetAttributions} isPalm={isPalm} />+ <div className="attrition-link">+ {isPalm ? <MapboxLogo /> : null}+ <a href="https://kepler.gl/policy/" target="_blank" rel="noopener noreferrer">+ © kepler.gl |{' '}+ </a>+ <a href="https://www.mapbox.com/about/maps/" target="_blank" rel="noopener noreferrer">+ © Mapbox |{' '}+ </a>+ <a+ href="https://www.mapbox.com/map-feedback/"+ target="_blank"+ rel="noopener noreferrer"+ >+ <strong>Improve this map </strong>+ {!isPalm ? <strong> | </strong> : null}+ </a>+ {!isPalm ? <MapboxLogo /> : null}+ </div>+ </EndHorizontalFlexbox></StyledAttrbution>);- }, [showMapboxLogo, isPalm]);+ }, [showMapboxLogo, showOsmBasemapAttribution, datasetAttributions, isPalm]);return memoizedComponents;};@@ -217,6 +271,8 @@ interface MapContainerProps {topMapContainerProps: any;bottomMapContainerProps: any;transformRequest?: any;++ datasetAttributions?: DatasetAttribution[];}export default function MapContainerFactory(@@ -761,7 +817,8 @@ export default function MapContainerFactory(primary,bottomMapContainerProps,topMapContainerProps,- theme+ theme,+ datasetAttributions = []} = this.props;const {layers, datasets, editor, interactionConfig} = visState;@@ -858,8 +915,12 @@ export default function MapContainerFactory(</div>) : null}{this._renderMapPopover()}- {!isSplit || index === 1 ? (- <Attribution showMapboxLogo={this.state.showMapboxAttribution} />+ {this.props.primary ? (+ <Attribution+ showMapboxLogo={this.state.showMapboxAttribution}+ showOsmBasemapAttribution={true}+ datasetAttributions={datasetAttributions}+ />) : null}</>);diff --git a/src/components/src/types.ts b/src/components/src/types.tsindex 25af10afa..2f2c45969 100644--- a/src/components/src/types.ts+++ b/src/components/src/types.ts@@ -43,3 +43,8 @@ export type SidePanelProps = {panels: SidePanelItem[];version: string;};++export type DatasetAttribution = {+ title: string;+ url: string;+};