Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

feat(export): add icon and name color branding (#3854)

Igor Dykhta5a55bc326841
diff --git a/src/actions/src/ui-state-actions.ts b/src/actions/src/ui-state-actions.ts
index 32cd4ea9e..605734d4b 100644
--- a/src/actions/src/ui-state-actions.ts
+++ b/src/actions/src/ui-state-actions.ts
@@ -481,12 +481,14 @@ export type SetExportMapBrandingUpdaterAction = {
payload: {
appName?: string;
appWebsite?: string;
+ appIcon?: string;
+ appNameColor?: string;
};
};
/**
* Set application branding overrides for exported maps
* @memberOf uiStateActions
- * @param payload - application name and/or website overrides
+ * @param payload - application name, website, icon, and/or name color overrides
*/
export const setExportMapBranding: (
payload: SetExportMapBrandingUpdaterAction['payload']
diff --git a/src/components/src/modal-container.tsx b/src/components/src/modal-container.tsx
index 71c8dda95..ced760252 100644
--- a/src/components/src/modal-container.tsx
+++ b/src/components/src/modal-container.tsx
@@ -348,7 +348,15 @@ export default function ModalContainerFactory(
_onExportMap = () => {
const {uiState} = this._propsWithMapInfoDraft();
- const {format, includeLayerApiKeys, fileName, appName, appWebsite} = uiState.exportMap;
+ const {
+ format,
+ includeLayerApiKeys,
+ fileName,
+ appName,
+ appWebsite,
+ appIcon,
+ appNameColor
+ } = uiState.exportMap;
(format === EXPORT_MAP_FORMATS.HTML ? exportHtml : exportJson)(
this._propsWithMapInfoDraft(),
{
@@ -356,7 +364,9 @@ export default function ModalContainerFactory(
includeLayerApiKeys,
fileName,
appName,
- appWebsite
+ appWebsite,
+ appIcon,
+ appNameColor
}
);
this._commitMapInfoDraft();
diff --git a/src/components/src/modals/export-map-modal/export-map-modal.spec.tsx b/src/components/src/modals/export-map-modal/export-map-modal.spec.tsx
index e7d22f2b5..5987b790e 100644
--- a/src/components/src/modals/export-map-modal/export-map-modal.spec.tsx
+++ b/src/components/src/modals/export-map-modal/export-map-modal.spec.tsx
@@ -7,7 +7,7 @@ import {fireEvent, within} from '@testing-library/react';
import {EXPORT_HTML_MAP_DOC, EXPORT_HTML_MAP_MODES, EXPORT_MAP_FORMATS} from '@kepler.gl/constants';
import {messages} from '@kepler.gl/localization';
import {INITIAL_UI_STATE} from '@kepler.gl/reducers';
-import {initApplicationConfig} from '@kepler.gl/utils';
+import {exportMapToHTML, initApplicationConfig} from '@kepler.gl/utils';
import {IntlProvider} from 'react-intl';
import {renderWithTheme} from 'test/helpers/component-jest-utils';
@@ -116,7 +116,10 @@ describe('ExportMapModal', () => {
expect(getByLabelText('Description')).toHaveValue('A city map');
expect(getByRole('region', {name: 'Map details'})).toBeInTheDocument();
expect(queryByLabelText('Application name')).toBeNull();
+ expect(queryByLabelText('Application name color')).toBeNull();
expect(queryByLabelText('Website')).toBeNull();
+ expect(queryByLabelText('Icon URL')).toBeNull();
+ expect(queryByRole('group', {name: 'Preview'})).toBeNull();
fireEvent.change(getByLabelText('Name'), {target: {value: 'Updated map'}});
expect(defaultProps.onMapInfoDraft).toHaveBeenCalledWith({
@@ -216,15 +219,42 @@ describe('ExportMapModal', () => {
expect(queryByRole('button', {name: 'Branding'})).toBeNull();
expect(detailsButton).toHaveAttribute('aria-expanded', 'false');
expect(queryByLabelText('Application name')).toBeNull();
+ expect(queryByLabelText('Application name color')).toBeNull();
expect(queryByLabelText('Website')).toBeNull();
+ expect(queryByLabelText('Icon URL')).toBeNull();
fireEvent.click(detailsButton);
expect(detailsButton).toHaveAttribute('aria-expanded', 'true');
expect(getByLabelText('Application name')).toHaveValue('Acme Maps');
+ expect(getByLabelText('Application name color')).toHaveValue('#1fbad6');
expect(getByLabelText('Website')).toHaveValue('https://maps.acme.test');
- ['Name', 'Description', 'Application name', 'Website'].forEach(label =>
- expectCenteredRowLabel(getByLabelText(label))
+ expect(getByLabelText('Icon URL')).toHaveValue('');
+ const iconHelp = getByRole('button', {name: 'Icon requirements'});
+ expect(iconHelp.parentElement).toHaveTextContent('Icon URL');
+ expect(iconHelp).toHaveAttribute('aria-describedby', 'export-map-app-icon-help');
+ expect(getByLabelText('Icon URL')).toHaveAttribute(
+ 'aria-describedby',
+ 'export-map-app-icon-help'
);
+ const iconRequirements = document.getElementById('export-map-app-icon-help');
+ expect(iconRequirements).toHaveTextContent('direct, publicly accessible HTTP(S) URL');
+ expect(iconRequirements).toHaveTextContent('SVG or PNG');
+ expect(iconRequirements).toHaveTextContent('22 × 15 px and keep their proportions');
+ expect(iconRequirements).toHaveTextContent('transparent background is recommended');
+ expect(iconRequirements).toHaveTextContent('Leave blank for the default kepler.gl icon');
+ [
+ 'Name',
+ 'Description',
+ 'Application name',
+ 'Application name color',
+ 'Website',
+ 'Icon URL'
+ ].forEach(label => expectCenteredRowLabel(getByLabelText(label)));
+ const nameInput = getByLabelText('Application name');
+ const colorInput = getByLabelText('Application name color');
+ expect(nameInput.nextElementSibling).toBe(colorInput);
+ expect(getComputedStyle(nameInput.parentElement as Element).display).toBe('flex');
+ expect(queryByText('Application name color')).toBeNull();
fireEvent.change(getByLabelText('Application name'), {target: {value: 'Atlas'}});
expect(defaultProps.onChangeExportMapBranding).toHaveBeenCalledWith({appName: 'Atlas'});
@@ -233,6 +263,20 @@ describe('ExportMapModal', () => {
expect(defaultProps.onChangeExportMapBranding).toHaveBeenCalledWith({
appWebsite: 'https://atlas.test'
});
+
+ fireEvent.change(getByLabelText('Icon URL'), {
+ target: {value: 'https://atlas.test/icon.svg'}
+ });
+ expect(defaultProps.onChangeExportMapBranding).toHaveBeenCalledWith({
+ appIcon: 'https://atlas.test/icon.svg'
+ });
+
+ fireEvent.change(getByLabelText('Application name color'), {
+ target: {value: '#123456'}
+ });
+ expect(defaultProps.onChangeExportMapBranding).toHaveBeenCalledWith({
+ appNameColor: '#123456'
+ });
});
test('keeps an empty application name while clearing and retyping', () => {
@@ -264,11 +308,91 @@ describe('ExportMapModal', () => {
fireEvent.change(appNameInput, {target: {value: ''}});
expect(appNameInput).toHaveValue('');
+ expect(within(getByRole('group', {name: 'Preview'})).getByRole('link')).toHaveTextContent(
+ 'Acme Maps'
+ );
fireEvent.change(appNameInput, {target: {value: 'Atlas'}});
expect(appNameInput).toHaveValue('Atlas');
});
+ test('updates the branding preview with the same icon, link, name, and color as exported maps', () => {
+ initApplicationConfig({enableCustomExportBranding: true});
+
+ function ControlledExportMapModal() {
+ const [options, setOptions] = React.useState(INITIAL_UI_STATE.exportMap);
+ return (
+ <ExportMapModal
+ {...defaultProps}
+ options={options}
+ onChangeExportMapBranding={branding => setOptions(current => ({...current, ...branding}))}
+ />
+ );
+ }
+
+ const {getByLabelText, getByRole} = renderWithTheme(
+ <IntlProvider locale="en" messages={messages.en}>
+ <ControlledExportMapModal />
+ </IntlProvider>
+ );
+ fireEvent.click(getByRole('button', {name: 'Map details'}));
+
+ const branding = {
+ appName: 'Atlas',
+ appWebsite: 'atlas.test/maps',
+ appIcon: 'atlas.test/icon.svg',
+ appNameColor: '#123456'
+ };
+ fireEvent.change(getByLabelText('Application name'), {target: {value: branding.appName}});
+ fireEvent.change(getByLabelText('Website'), {target: {value: branding.appWebsite}});
+ fireEvent.change(getByLabelText('Icon URL'), {target: {value: branding.appIcon}});
+ fireEvent.change(getByLabelText('Application name color'), {
+ target: {value: branding.appNameColor}
+ });
+
+ const html = exportMapToHTML(branding);
+ const brandingMatch = html.match(/const branding = (.+);/);
+ if (!brandingMatch) {
+ throw new Error('Exported HTML did not serialize branding');
+ }
+ const exportedBranding = JSON.parse(brandingMatch[1]);
+ const preview = getByRole('group', {name: 'Preview'});
+ const link = within(preview).getByRole('link', {name: exportedBranding.appName});
+ expect(link).toHaveAttribute('href', exportedBranding.appWebsite);
+ expect(link).toHaveAttribute('title', exportedBranding.appWebsite);
+ expect(link).toHaveAttribute('rel', 'noopener noreferrer');
+ expect(link).toHaveStyle({color: exportedBranding.appNameColor});
+ expect(preview.querySelector('img')).toHaveAttribute('src', exportedBranding.appIcon);
+ expect(preview.querySelector('img')).toHaveAttribute('width', '22');
+ expect(preview.querySelector('img')).toHaveAttribute('height', '15');
+ expect(
+ getByLabelText('Icon URL').compareDocumentPosition(preview) & Node.DOCUMENT_POSITION_FOLLOWING
+ ).toBeTruthy();
+
+ fireEvent.change(getByLabelText('Icon URL'), {target: {value: ''}});
+ expect(preview.querySelector('img')).toBeNull();
+ expect(preview.querySelector('svg')).toBeInTheDocument();
+ });
+
+ test('uses exported branding fallbacks in the preview for invalid values', () => {
+ initApplicationConfig({enableCustomExportBranding: true});
+ const options = {
+ ...INITIAL_UI_STATE.exportMap,
+ appName: '',
+ appWebsite: 'javascript:alert(1)',
+ appIcon: 'not an icon URL',
+ appNameColor: 'red'
+ };
+ const {getByRole} = renderModal({options});
+ fireEvent.click(getByRole('button', {name: 'Map details'}));
+ const preview = getByRole('group', {name: 'Preview'});
+ const link = within(preview).getByRole('link', {name: 'Acme Maps'});
+ expect(link).toHaveAttribute('href', 'http://kepler.gl/');
+ expect(link).toHaveStyle({color: '#1FBAD6'});
+ expect(preview.querySelector('img')).toBeNull();
+ expect(preview.querySelector('svg')).toBeInTheDocument();
+ });
+
test('shows the security notice when a custom Mapbox token is embedded', () => {
const options = {
...INITIAL_UI_STATE.exportMap,
@@ -292,7 +416,9 @@ describe('ExportMapModal', () => {
...INITIAL_UI_STATE.exportMap,
format: EXPORT_MAP_FORMATS.JSON,
appName: 'Atlas JSON',
- appWebsite: 'https://json.atlas.test'
+ appWebsite: 'https://json.atlas.test',
+ appIcon: 'https://json.atlas.test/icon.svg',
+ appNameColor: '#654321'
};
const {container, getByLabelText, getByRole, getByText, queryByText} = renderModal({options});
const inactivePanel = container.querySelector('[inert]') as HTMLElement;
@@ -324,7 +450,9 @@ describe('ExportMapModal', () => {
fireEvent.click(getByRole('button', {name: 'Map details'}));
expect(getByLabelText('Application name')).toHaveValue('Atlas JSON');
+ expect(getByLabelText('Application name color')).toHaveValue('#654321');
expect(getByLabelText('Website')).toHaveValue('https://json.atlas.test');
+ expect(getByLabelText('Icon URL')).toHaveValue('https://json.atlas.test/icon.svg');
fireEvent.change(getByLabelText('Application name'), {target: {value: 'Updated Atlas'}});
expect(defaultProps.onChangeExportMapBranding).toHaveBeenCalledWith({
diff --git a/src/components/src/modals/export-map-modal/export-map-modal.tsx b/src/components/src/modals/export-map-modal/export-map-modal.tsx
index 11c892829..6b59f3536 100644
--- a/src/components/src/modals/export-map-modal/export-map-modal.tsx
+++ b/src/components/src/modals/export-map-modal/export-map-modal.tsx
@@ -43,6 +43,8 @@ interface ExportMapModalOptions {
fileName?: string;
appName?: string;
appWebsite?: string;
+ appIcon?: string;
+ appNameColor?: string;
[key: string]: any;
}
@@ -68,6 +70,76 @@ const MapInfoInput = styled(InputLight)`
max-width: 380px;
`;
+const ApplicationNameInputs = styled.div`
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ max-width: 380px;
+
+ ${MapInfoInput} {
+ flex: 1;
+ min-width: 0;
+ }
+`;
+
+const ApplicationColorInput = styled(InputLight)`
+ flex: 0 0 36px;
+ width: 36px;
+ padding: 2px;
+ cursor: pointer;
+`;
+
+const BrandingPreview = styled.div`
+ display: flex;
+ align-items: center;
+ max-width: 380px;
+
+ img {
+ object-fit: contain;
+ }
+
+ a {
+ margin-left: 6px;
+ font-family: ff-clan-web-pro, 'Helvetica Neue', Helvetica, sans-serif;
+ font-size: 14px;
+ font-weight: 600;
+ letter-spacing: 1.17px;
+ text-decoration: none;
+ }
+`;
+
+const DEFAULT_APP_NAME_COLOR = '#1FBAD6';
+
+function getAppNameColorInputValue(value: unknown): string {
+ return typeof value === 'string' && /^#[\da-f]{6}$/i.test(value)
+ ? value
+ : DEFAULT_APP_NAME_COLOR;
+}
+
+function getBrandingURL(value: unknown, fallback: string | null): string | null {
+ if (typeof value !== 'string' || !value.trim()) {
+ return fallback;
+ }
+
+ const trimmedValue = value.trim();
+ if (/^[a-z][a-z\d+.-]*:/i.test(trimmedValue) && !/^https?:/i.test(trimmedValue)) {
+ return fallback;
+ }
+
+ const absoluteValue = /^https?:/i.test(trimmedValue)
+ ? trimmedValue
+ : trimmedValue.startsWith('//')
+ ? `https:${trimmedValue}`
+ : `https://${trimmedValue}`;
+
+ try {
+ const url = new URL(absoluteValue);
+ return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : fallback;
+ } catch {
+ return fallback;
+ }
+}
+
const style = {width: '100%'};
const FormatSelector = styled.div`
@@ -141,6 +213,11 @@ function ExportMapModalFactory(
const [draftDescription, setDraftDescription] = useState(mapInfo?.description ?? '');
const htmlOptions = options[EXPORT_MAP_FORMATS.HTML] || {};
const showCustomExportBranding = getApplicationConfig().enableCustomExportBranding;
+ const previewName = options.appName || appName || KEPLER_GL_NAME;
+ const previewWebsite =
+ getBrandingURL(options.appWebsite ?? appWebsite, KEPLER_GL_WEBSITE) || KEPLER_GL_WEBSITE;
+ const previewIcon = getBrandingURL(options.appIcon, null);
+ const previewColor = getAppNameColorInputValue(options.appNameColor);
return (
<StyledExportMapModalContent className="export-map-modal">
<div style={style}>
@@ -268,13 +345,25 @@ function ExportMapModalFactory(
</div>
</div>
<div className="selection">
- <MapInfoInput
- id="export-map-app-name"
- type="text"
- value={options.appName ?? appName ?? KEPLER_GL_NAME}
- aria-label={intl.formatMessage({id: 'modal.exportMap.appNameTitle'})}
- onChange={event => onChangeExportMapBranding({appName: event.target.value})}
- />
+ <ApplicationNameInputs>
+ <MapInfoInput
+ id="export-map-app-name"
+ type="text"
+ value={options.appName ?? appName ?? KEPLER_GL_NAME}
+ aria-label={intl.formatMessage({id: 'modal.exportMap.appNameTitle'})}
+ onChange={event => onChangeExportMapBranding({appName: event.target.value})}
+ />
+ <ApplicationColorInput
+ id="export-map-app-name-color"
+ type="color"
+ value={previewColor}
+ aria-label={intl.formatMessage({id: 'modal.exportMap.appNameColorTitle'})}
+ title={intl.formatMessage({id: 'modal.exportMap.appNameColorTitle'})}
+ onChange={event =>
+ onChangeExportMapBranding({appNameColor: event.target.value})
+ }
+ />
+ </ApplicationNameInputs>
</div>
</StyledExportMapSection>
<StyledExportMapSection>
@@ -295,6 +384,64 @@ function ExportMapModalFactory(
/>
</div>
</StyledExportMapSection>
+ <StyledExportMapSection>
+ <div className="description description--centered">
+ <ExportMapSectionTitle>
+ <FormattedMessage id="modal.exportMap.appIconTitle" />
+ <ExportMapHelp
+ id="export-map-app-icon-help"
+ label={intl.formatMessage({id: 'modal.exportMap.appIconHelpLabel'})}
+ >
+ <FormattedMessage id="modal.exportMap.appIconHelp" />
+ </ExportMapHelp>
+ </ExportMapSectionTitle>
+ </div>
+ <div className="selection">
+ <MapInfoInput
+ id="export-map-app-icon"
+ type="url"
+ value={options.appIcon ?? ''}
+ aria-label={intl.formatMessage({id: 'modal.exportMap.appIconTitle'})}
+ aria-describedby="export-map-app-icon-help"
+ onChange={event => onChangeExportMapBranding({appIcon: event.target.value})}
+ />
+ </div>
+ </StyledExportMapSection>
+ <StyledExportMapSection>
+ <div className="description description--centered">
+ <div className="title">
+ <FormattedMessage id="modal.exportMap.brandingPreviewTitle" />
+ </div>
+ </div>
+ <div className="selection">
+ <BrandingPreview
+ role="group"
+ aria-label={intl.formatMessage({id: 'modal.exportMap.brandingPreviewTitle'})}
+ >
+ <div>
+ {previewIcon ? (
+ <img src={previewIcon} alt="" aria-hidden width="22" height="15" />
+ ) : (
+ <svg width="22" height="15" viewBox="0 0 22 15" aria-hidden>
+ <g transform="translate(11, -3) rotate(45.000000)">
+ <rect fill="#535C6C" x="0" y="5" width="10" height="10" />
+ <rect fill="#1FBAD6" x="5" y="0" width="10" height="10" />
+ </g>
+ </svg>
+ )}
+ </div>
+ <a
+ href={previewWebsite}
+ title={previewWebsite}
+ target="_blank"
+ rel="noopener noreferrer"
+ style={{color: previewColor}}
+ >
+ <span style={{color: previewColor}}>{previewName}</span>
+ </a>
+ </BrandingPreview>
+ </div>
+ </StyledExportMapSection>
</>
) : null}
</CollapsibleExportMapSection>
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index bc70b688f..e4228135d 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -832,7 +832,13 @@ export default {
nameTitle: 'Name',
descriptionTitle: 'Description',
appNameTitle: 'Application name',
+ appNameColorTitle: 'Application name color',
appWebsiteTitle: 'Website',
+ appIconTitle: 'Icon URL',
+ appIconHelpLabel: 'Icon requirements',
+ appIconHelp:
+ 'Use a direct, publicly accessible HTTP(S) URL to an image, such as SVG or PNG. Icons fit within 22 × 15 px and keep their proportions. A transparent background is recommended. Leave blank for the default kepler.gl icon.',
+ brandingPreviewTitle: 'Preview',
includeApiKeysTitle: 'Layer API keys',
includeApiKeys: 'Include layer API keys',
includeApiKeysHelpLabel: 'About layer API keys',
diff --git a/src/reducers/src/ui-state-updaters.ts b/src/reducers/src/ui-state-updaters.ts
index 138d99d1c..b2073cc6f 100644
--- a/src/reducers/src/ui-state-updaters.ts
+++ b/src/reducers/src/ui-state-updaters.ts
@@ -868,7 +868,7 @@ export const setExportMapHTMLModeUpdater = (
* Set application branding overrides for exported maps.
* @param state - `uiState`
* @param action
- * @param action.payload application name and/or website overrides
+ * @param action.payload application name, website, icon, and/or name color overrides
* @return nextState
*/
export const setExportMapBrandingUpdater = (
diff --git a/src/schemas/src/schema-manager.ts b/src/schemas/src/schema-manager.ts
index abeb027a0..818b58170 100644
--- a/src/schemas/src/schema-manager.ts
+++ b/src/schemas/src/schema-manager.ts
@@ -90,6 +90,8 @@ export type SavedMap = {
source?: string;
appName?: string;
appWebsite?: string;
+ appIcon?: string;
+ appNameColor?: string;
};
};
diff --git a/src/types/reducers.d.ts b/src/types/reducers.d.ts
index 1c3b367c6..190c4777e 100644
--- a/src/types/reducers.d.ts
+++ b/src/types/reducers.d.ts
@@ -585,6 +585,10 @@ export type ExportMap = {
appName?: string;
/** Optional application website override for exported HTML and JSON. */
appWebsite?: string;
+ /** Optional application icon URL override for exported HTML and JSON. */
+ appIcon?: string;
+ /** Optional application name color override for exported HTML and JSON. */
+ appNameColor?: string;
};
export type ExportVideo = {
diff --git a/src/types/schemas.d.ts b/src/types/schemas.d.ts
index c51b9cb2a..14b25da1f 100644
--- a/src/types/schemas.d.ts
+++ b/src/types/schemas.d.ts
@@ -301,6 +301,8 @@ export type SavedMap = {
source?: string;
appName?: string;
appWebsite?: string;
+ appIcon?: string;
+ appNameColor?: string;
};
};
diff --git a/src/utils/src/export-map-html.spec.ts b/src/utils/src/export-map-html.spec.ts
new file mode 100644
index 000000000..80e899a69
--- /dev/null
+++ b/src/utils/src/export-map-html.spec.ts
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import {EXPORT_HTML_MAP_MODES} from '@kepler.gl/constants';
+import {registerEntry} from '@kepler.gl/actions';
+import keplerGlReducer, {INITIAL_UI_STATE} from '@kepler.gl/reducers';
+import {combineReducers} from 'redux';
+
+import {exportMapToHTML} from './export-map-html';
+
+function getBranding(options: Record<string, unknown> = {}) {
+ const html = exportMapToHTML({
+ datasets: [],
+ config: {version: 'v1', config: {}},
+ mode: EXPORT_HTML_MAP_MODES.READ,
+ ...options
+ });
+ const match = html.match(/const branding = (.+);/);
+ if (!match) {
+ throw new Error('Exported HTML did not serialize branding');
+ }
+ return {branding: JSON.parse(match[1]), html};
+}
+
+describe('exportMapToHTML branding', () => {
+ test('normalizes custom icon and color branding for read-only and editable exports', () => {
+ const {branding, html} = getBranding({
+ appName: 'Atlas',
+ appWebsite: 'atlas.example/maps',
+ appIcon: 'atlas.example/icon.svg',
+ appNameColor: '#123abc'
+ });
+
+ expect(branding).toEqual({
+ appName: 'Atlas',
+ appWebsite: 'https://atlas.example/maps',
+ appIcon: 'https://atlas.example/icon.svg',
+ appNameColor: '#123abc'
+ });
+ expect(html).toContain('src: branding.appIcon');
+ expect(html).toContain(
+ 'react.createElement("span", {style: {color: branding.appNameColor}}, branding.appName)'
+ );
+ expect(html).toContain('react.createElement(BrandLogo, {fixed: true})');
+ expect(html).toContain('Object.assign({}, props, {logoComponent: BrandLogo})');
+ expect(html).toContain('!fixed && props && props.version');
+ expect(html).toContain('className: "logo__version"');
+ });
+
+ test('falls back safely for missing or invalid icon and color values', () => {
+ expect(getBranding().branding).toEqual({
+ appName: 'kepler.gl',
+ appWebsite: 'http://kepler.gl/',
+ appIcon: null,
+ appNameColor: '#1FBAD6'
+ });
+ expect(
+ getBranding({appIcon: 'javascript:alert(1)', appNameColor: 'red'}).branding
+ ).toMatchObject({appIcon: null, appNameColor: '#1FBAD6'});
+ });
+
+ test('preserves branding and default export options when an editable map is exported again', () => {
+ const {branding, html} = getBranding({
+ mode: EXPORT_HTML_MAP_MODES.EDIT,
+ appName: 'Atlas',
+ appWebsite: 'atlas.test/maps',
+ appIcon: 'atlas.test/icon.svg',
+ appNameColor: '#123456'
+ });
+ const reducerMatch = html.match(/const reducers = ([\s\S]*?);\s+const middleWares/);
+ if (!reducerMatch) {
+ throw new Error('Exported HTML did not initialize its reducers');
+ }
+ const reducerScript = reducerMatch[1];
+ const reducer = new Function(
+ 'Redux',
+ 'KeplerGl',
+ 'savedStyleType',
+ 'branding',
+ `return ${reducerScript}`
+ )({combineReducers}, {keplerGlReducer, INITIAL_UI_STATE}, null, branding);
+ const state = reducer(undefined, registerEntry({id: 'map'}));
+ const exportOptions = state.keplerGl.map.uiState.exportMap;
+
+ expect(exportOptions).toEqual({...INITIAL_UI_STATE.exportMap, ...branding});
+ expect(getBranding(exportOptions).branding).toEqual(branding);
+ });
+
+ test('keeps icon branding script-safe', () => {
+ const {branding, html} = getBranding({
+ appIcon: 'https://example.test/icon.svg?next=</script><script>window.pwned=1</script>'
+ });
+
+ expect(html).not.toContain('<script>window.pwned');
+ expect(branding.appIcon).toBe(
+ 'https://example.test/icon.svg?next=%3C/script%3E%3Cscript%3Ewindow.pwned=1%3C/script%3E'
+ );
+ });
+});
diff --git a/src/utils/src/export-map-html.ts b/src/utils/src/export-map-html.ts
index 413cc0d6f..9935d1c59 100644
--- a/src/utils/src/export-map-html.ts
+++ b/src/utils/src/export-map-html.ts
@@ -23,6 +23,7 @@ const STYLED_COMPONENTS_VERSION = '6.1.19';
// es-module-shims lets the exported map keep working as a standalone file://
// document (native ES modules/import maps are blocked under the file:// origin).
const ES_MODULE_SHIMS_VERSION = '2.8.1';
+const DEFAULT_APP_NAME_COLOR = '#1FBAD6';
/** Escape serialized JSON for interpolation into an inline `<script>`. */
function escapeScriptJSON(serialized: string): string {
@@ -58,15 +59,15 @@ function escapeHTML(value: string): string {
}
/** Resolve user-entered branding links to an absolute HTTP(S) URL. */
-function normalizeAppWebsite(value: unknown): string {
+function normalizeHTTPURL(value: unknown, fallback: string | null): string | null {
if (typeof value !== 'string' || !value.trim()) {
- return KEPLER_GL_WEBSITE;
+ return fallback;
}
const trimmedValue = value.trim();
const hasScheme = /^[a-z][a-z\d+.-]*:/i.test(trimmedValue);
if (hasScheme && !/^https?:/i.test(trimmedValue)) {
- return KEPLER_GL_WEBSITE;
+ return fallback;
}
const absoluteValue = /^https?:/i.test(trimmedValue)
@@ -77,12 +78,26 @@ function normalizeAppWebsite(value: unknown): string {
try {
const url = new URL(absoluteValue);
- return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : KEPLER_GL_WEBSITE;
+ return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : fallback;
} catch {
- return KEPLER_GL_WEBSITE;
+ return fallback;
}
}
+function normalizeAppWebsite(value: unknown): string {
+ return normalizeHTTPURL(value, KEPLER_GL_WEBSITE) || KEPLER_GL_WEBSITE;
+}
+
+function normalizeAppIcon(value: unknown): string | null {
+ return normalizeHTTPURL(value, null);
+}
+
+function normalizeAppNameColor(value: unknown): string {
+ return typeof value === 'string' && /^#[\da-f]{6}$/i.test(value)
+ ? value
+ : DEFAULT_APP_NAME_COLOR;
+}
+
/**
* This method is used to create an html file which will inlcude kepler and map data
* @param {Object} options Object that collects all necessary data to create the html file
@@ -92,13 +107,17 @@ function normalizeAppWebsite(value: unknown): string {
* @param {Object} [options.info] map title and description
* @param {string} [options.appName] application name used by the exported map
* @param {string} [options.appWebsite] application website linked by the exported map
+ * @param {string} [options.appIcon] application icon URL used by the exported map
+ * @param {string} [options.appNameColor] application name color used by the exported map
* @param {string} version which version of Kepler.gl to load.
*/
export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
const appName =
typeof options.appName === 'string' && options.appName ? options.appName : KEPLER_GL_NAME;
const appWebsite = normalizeAppWebsite(options.appWebsite);
- const branding = {appName, appWebsite};
+ const appIcon = normalizeAppIcon(options.appIcon);
+ const appNameColor = normalizeAppNameColor(options.appNameColor);
+ const branding = {appName, appWebsite, appIcon, appNameColor};
const mapboxApiAccessToken = options.mapboxApiAccessToken || 'PROVIDE_MAPBOX_TOKEN';
const keplerStyleUrl = `https://unpkg.com/kepler.gl@${version}/umd/keplergl.min.css`;
const keplerScriptUrl = `https://unpkg.com/kepler.gl@${version}/umd/keplergl.min.js`;
@@ -345,7 +364,8 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
keplerGl: keplerGl.keplerGlReducer.initialState({
uiState: {
readOnly: ${options.mode === EXPORT_HTML_MAP_MODES.READ},
- currentModal: null
+ currentModal: null,
+ exportMap: Object.assign({}, keplerGl.INITIAL_UI_STATE.exportMap, branding)
},
...(styleType ? {mapStyle: {styleType}} : {})
})
@@ -372,6 +392,76 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
/** END STORE **/
/** COMPONENTS **/
+ var BrandLogo = (function createBrandLogo(react, branding) {
+ return function BrandLogo(props) {
+ var fixed = Boolean(props && props.fixed);
+ var icon = branding.appIcon
+ ? react.createElement("img", {
+ src: branding.appIcon,
+ alt: "",
+ "aria-hidden": true,
+ style: {width: "22px", height: "15px", objectFit: "contain"}
+ })
+ : react.createElement(
+ "svg",
+ {width: "22px", height: "15px", viewBox: "0 0 22 15", "aria-hidden": true},
+ react.createElement(
+ "g",
+ {transform: "translate(11, -3) rotate(45.000000)"},
+ react.createElement("rect", {fill: "#535C6C", x: "0", y: "5", width: "10", height: "10"}),
+ react.createElement("rect", {fill: "#1FBAD6", x: "5", y: "0", width: "10", height: "10"})
+ )
+ );
+
+ return react.createElement(
+ "div",
+ {
+ className: fixed ? "logo-container" : "side-panel-logo",
+ style: fixed
+ ? {position: "fixed", zIndex: 10000, padding: "4px", display: "flex", alignItems: "center"}
+ : {display: "flex", alignItems: "flex-start"}
+ },
+ react.createElement(
+ "div",
+ {style: {marginTop: fixed ? 0 : "3px"}},
+ icon
+ ),
+ react.createElement(
+ "div",
+ {className: "logo__title", style: {marginLeft: "6px"}},
+ react.createElement(
+ "a",
+ {
+ className: "kepler_gl__logo logo__link",
+ href: branding.appWebsite,
+ target: "_blank",
+ rel: "noopener noreferrer",
+ style: {
+ color: branding.appNameColor,
+ fontFamily: "ff-clan-web-pro, 'Helvetica Neue', Helvetica, sans-serif",
+ fontSize: "14px",
+ fontWeight: 600,
+ letterSpacing: "1.17px",
+ textDecoration: "none"
+ }
+ },
+ react.createElement("span", {style: {color: branding.appNameColor}}, branding.appName)
+ ),
+ !fixed && props && props.version
+ ? react.createElement(
+ "div",
+ {
+ className: "logo__version",
+ style: {fontSize: "10px", color: "#a0a7b4", letterSpacing: "0.83px", lineHeight: "14px"}
+ },
+ props.version
+ )
+ : null
+ )
+ );
+ };
+ }(React, branding));
+
/** Custom map control factory to restore export editing and chart display. **/
var CustomMapControlFactory = (function createCustomMapControl(react, keplerGl) {
var EffectControlFactory = keplerGl.EffectControlFactory;
@@ -475,49 +565,32 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
return [MapControlFactory, ExportMapControlFactory];
}(React, KeplerGl));
- var KeplerGlComponent = CustomMapControlFactory
- ? KeplerGl.injectComponents([CustomMapControlFactory])
- : KeplerGl.KeplerGl;
+ var CustomPanelHeaderFactory = (function createCustomPanelHeader(react, keplerGl, BrandLogo) {
+ var PanelHeaderFactory = keplerGl.PanelHeaderFactory;
+ if (!PanelHeaderFactory) {
+ console.warn('kepler.gl: Panel header factory not available, skipping branding injection');
+ return null;
+ }
- var KeplerElement = (function makeKeplerElement(react, keplerGl, mapboxToken, branding) {
- var BrandLogo = function BrandLogo() {
- return react.createElement(
- "div",
- { className: "logo-container", style: {position: 'fixed', zIndex: 10000, padding: '4px'} },
- react.createElement(
- "a",
- {
- className: "kepler_gl__logo",
- href: branding.appWebsite,
- target: "_blank",
- rel: "noopener noreferrer",
- style: {
- display: 'flex',
- alignItems: 'center',
- gap: '6px',
- color: '#1FBAD6',
- fontFamily: "ff-clan-web-pro, 'Helvetica Neue', Helvetica, sans-serif",
- fontSize: '14px',
- fontWeight: 600,
- letterSpacing: '1.17px',
- textDecoration: 'none'
- }
- },
- react.createElement(
- "svg",
- {width: "22px", height: "15px", viewBox: "0 0 22 15", "aria-hidden": true},
- react.createElement(
- "g",
- {transform: "translate(11, -3) rotate(45.000000)"},
- react.createElement("rect", {fill: "#535C6C", x: "0", y: "5", width: "10", height: "10"}),
- react.createElement("rect", {fill: "#1FBAD6", x: "5", y: "0", width: "10", height: "10"})
- )
- ),
- react.createElement("span", null, branding.appName)
- )
+ function ExportPanelHeaderFactory() {
+ var PanelHeader = PanelHeaderFactory.apply(null, arguments);
+ return function ExportPanelHeader(props) {
+ return react.createElement(
+ PanelHeader,
+ Object.assign({}, props, {logoComponent: BrandLogo})
);
};
+ }
+ ExportPanelHeaderFactory.deps = PanelHeaderFactory.deps;
+ return [PanelHeaderFactory, ExportPanelHeaderFactory];
+ }(React, KeplerGl, BrandLogo));
+ var CustomFactories = [CustomMapControlFactory, CustomPanelHeaderFactory].filter(Boolean);
+ var KeplerGlComponent = CustomFactories.length
+ ? KeplerGl.injectComponents(CustomFactories)
+ : KeplerGl.KeplerGl;
+
+ var KeplerElement = (function makeKeplerElement(react, keplerGl, mapboxToken, branding, BrandLogo) {
return function App() {
var rootElm = react.useRef(null);
var _useState = react.useState({
@@ -543,7 +616,11 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
return react.createElement(
'div',
{style: {position: 'absolute', left: 0, width: '100vw', height: '100vh'}},
- ${options.mode === EXPORT_HTML_MAP_MODES.READ ? 'BrandLogo(),' : ''}
+ ${
+ options.mode === EXPORT_HTML_MAP_MODES.READ
+ ? "react.createElement(BrandLogo, {fixed: true}),"
+ : ''
+ }
react.createElement(KeplerGlComponent, {
mapboxApiAccessToken: mapboxToken,
id: "map",
@@ -554,7 +631,7 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
})
)
}
- }(React, KeplerGl, MAPBOX_TOKEN, branding));
+ }(React, KeplerGl, MAPBOX_TOKEN, branding, BrandLogo));
const app = (function createReactReduxProvider(react, reactRedux, KeplerElement) {
return react.createElement(
diff --git a/src/utils/src/export-utils.spec.ts b/src/utils/src/export-utils.spec.ts
index f03448744..dc1e099d3 100644
--- a/src/utils/src/export-utils.spec.ts
+++ b/src/utils/src/export-utils.spec.ts
@@ -37,7 +37,11 @@ describe('exportJson', () => {
value: saveBlob
});
- exportJson(state, {hasData: false});
+ exportJson(state, {
+ hasData: false,
+ appIcon: 'https://example.test/icon.svg',
+ appNameColor: '#123456'
+ });
expect(await readJsonBlob(saveBlob.mock.calls[0][0])).toEqual(configOnlyMap);
@@ -52,5 +56,23 @@ describe('exportJson', () => {
source: 'kepler.gl'
}
});
+
+ exportJson(state, {
+ hasData: true,
+ appIcon: 'https://example.test/icon.svg',
+ appNameColor: '#123456'
+ });
+
+ expect(await readJsonBlob(saveBlob.mock.calls[2][0])).toEqual({
+ ...dataInclusiveMap,
+ info: {
+ ...dataInclusiveMap.info,
+ appName: 'kepler.gl',
+ appWebsite: 'http://kepler.gl/',
+ appIcon: 'https://example.test/icon.svg',
+ appNameColor: '#123456',
+ source: 'kepler.gl'
+ }
+ });
});
});
diff --git a/src/utils/src/export-utils.ts b/src/utils/src/export-utils.ts
index afe2972a5..e488f8233 100644
--- a/src/utils/src/export-utils.ts
+++ b/src/utils/src/export-utils.ts
@@ -230,6 +230,10 @@ type MapJsonOptions = {
appName?: string;
/** Optional application website to preserve in exported JSON metadata. */
appWebsite?: string;
+ /** Optional application icon URL to preserve in exported JSON metadata. */
+ appIcon?: string;
+ /** Optional application name color to preserve in exported JSON metadata. */
+ appNameColor?: string;
};
export function getMapJSON(
@@ -247,13 +251,20 @@ export function getMapJSON(
if (includeLayerApiKeys === false) {
mapToSave = omitLayerApiKeys(mapToSave);
}
- if (options.appName !== undefined || options.appWebsite !== undefined) {
+ if (
+ options.appName !== undefined ||
+ options.appWebsite !== undefined ||
+ options.appIcon !== undefined ||
+ options.appNameColor !== undefined
+ ) {
mapToSave = {
...mapToSave,
info: {
...mapToSave.info,
...(options.appName !== undefined ? {appName: options.appName} : {}),
- ...(options.appWebsite !== undefined ? {appWebsite: options.appWebsite} : {})
+ ...(options.appWebsite !== undefined ? {appWebsite: options.appWebsite} : {}),
+ ...(options.appIcon !== undefined ? {appIcon: options.appIcon} : {}),
+ ...(options.appNameColor !== undefined ? {appNameColor: options.appNameColor} : {})
}
};
}
@@ -285,8 +296,16 @@ export function resolveMapboxTokenForExport(
}
export function exportHtml(state, options) {
- const {userMapboxToken, exportMapboxAccessToken, mode, includeLayerApiKeys, appName, appWebsite} =
- options;
+ const {
+ userMapboxToken,
+ exportMapboxAccessToken,
+ mode,
+ includeLayerApiKeys,
+ appName,
+ appWebsite,
+ appIcon,
+ appNameColor
+ } = options;
const exportAppName = appName || state.appName || KEPLER_GL_NAME;
const exportAppWebsite = appWebsite ?? state.appWebsite ?? KEPLER_GL_WEBSITE;
@@ -295,7 +314,9 @@ export function exportHtml(state, options) {
mapboxApiAccessToken: resolveMapboxTokenForExport(userMapboxToken, exportMapboxAccessToken),
mode,
appName: exportAppName,
- appWebsite: exportAppWebsite
+ appWebsite: exportAppWebsite,
+ appIcon,
+ appNameColor
};
const fileBlob = new Blob([exportMapToHTML(data)], {type: 'text/html'});
diff --git a/test/node/reducers/ui-state-test.js b/test/node/reducers/ui-state-test.js
index ce49c802e..4d7e5aa3c 100644
--- a/test/node/reducers/ui-state-test.js
+++ b/test/node/reducers/ui-state-test.js
@@ -329,7 +329,11 @@ test('#uiStateReducer -> SET_EXPORT_MAP_BRANDING', t => {
const withWebsite = reducer(
withAppName,
- setExportMapBranding({appWebsite: 'https://atlas.example.com'})
+ setExportMapBranding({
+ appWebsite: 'https://atlas.example.com',
+ appIcon: 'https://atlas.example.com/icon.svg',
+ appNameColor: '#123456'
+ })
);
t.deepEqual(
@@ -337,9 +341,11 @@ test('#uiStateReducer -> SET_EXPORT_MAP_BRANDING', t => {
{
...INITIAL_UI_STATE.exportMap,
appName: 'Atlas Lab',
- appWebsite: 'https://atlas.example.com'
+ appWebsite: 'https://atlas.example.com',
+ appIcon: 'https://atlas.example.com/icon.svg',
+ appNameColor: '#123456'
},
- 'should merge a partial website update without replacing the application name'
+ 'should merge partial branding updates without replacing the application name'
);
t.end();
diff --git a/test/node/utils/export-utils-test.js b/test/node/utils/export-utils-test.js
index 3387f43bf..c9abd81b4 100644
--- a/test/node/utils/export-utils-test.js
+++ b/test/node/utils/export-utils-test.js
@@ -24,7 +24,9 @@ test('exportUtils -> ExportJson', t => {
const map = getMapJSON(state, {
hasData: true,
appName: '</script> Atlas',
- appWebsite: 'https://atlas.example.com/?next="map"'
+ appWebsite: 'https://atlas.example.com/?next="map"',
+ appIcon: 'https://atlas.example.com/icon.svg',
+ appNameColor: '#123456'
});
const body = exportToJsonString(map);
getScaleFromImageSize;
@@ -40,6 +42,12 @@ test('exportUtils -> ExportJson', t => {
'https://atlas.example.com/?next="map"',
'should preserve the application website'
);
+ t.equal(
+ map.info.appIcon,
+ 'https://atlas.example.com/icon.svg',
+ 'should preserve the application icon'
+ );
+ t.equal(map.info.appNameColor, '#123456', 'should preserve the application name color');
t.deepEqual(JSON.parse(body).info, map.info, 'should safely serialize branding as JSON metadata');
t.end();
@@ -227,7 +235,9 @@ test('exportUtils -> ExportHtml preserves nullish dataset and config values', t
test('exportUtils -> ExportHtml preserves custom branding', t => {
const branding = {
appName: 'Atlas Lab',
- appWebsite: 'https://atlas.example.com/maps'
+ appWebsite: 'https://atlas.example.com/maps',
+ appIcon: 'https://atlas.example.com/icon.svg',
+ appNameColor: '#123456'
};
const html = exportMapToHTML({
datasets: [],
@@ -252,10 +262,26 @@ test('exportUtils -> ExportHtml preserves custom branding', t => {
'the read-only logo should link to the app website'
);
t.ok(
- html.includes('react.createElement("span", null, branding.appName)'),
- 'the read-only logo should render the app name'
+ html.includes('react.createElement("span", {style: {color: branding.appNameColor}}, branding.appName)'),
+ 'the exported logo should render the app name using its selected color'
+ );
+ t.ok(
+ html.includes('react.createElement(BrandLogo, {fixed: true})'),
+ 'a read-only export should render the branding badge'
+ );
+ t.ok(
+ html.includes('src: branding.appIcon'),
+ 'the exported logo should render the normalized custom icon'
+ );
+ t.ok(
+ html.includes('Object.assign({}, props, {logoComponent: BrandLogo})'),
+ 'editable exports should inject the same branding badge into the side panel'
+ );
+ t.ok(
+ html.includes('!fixed && props && props.version') &&
+ html.includes('className: "logo__version"'),
+ 'editable exports should preserve the side-panel version label'
);
- t.ok(html.includes('BrandLogo(),'), 'a read-only export should render the branding badge');
t.ok(
html.includes('appName: branding.appName') && html.includes('appWebsite: branding.appWebsite'),
'the embedded component should receive the branding props'
@@ -311,7 +337,12 @@ test('exportUtils -> ExportHtml uses default branding', t => {
t.ok(brandingMatch, 'exported html should define default branding settings');
t.deepEqual(
JSON.parse(brandingMatch[1]),
- {appName: 'kepler.gl', appWebsite: 'http://kepler.gl/'},
+ {
+ appName: 'kepler.gl',
+ appWebsite: 'http://kepler.gl/',
+ appIcon: null,
+ appNameColor: '#1FBAD6'
+ },
'exported html should retain the Kepler defaults'
);
t.ok(
@@ -326,12 +357,16 @@ test('exportUtils -> ExportHtml safely serializes branding', t => {
const appName = '</title><script>window.brandPwned=1;</script> & Map\u2028\u2029';
const appWebsite =
'https://example.com/?next=</script><script>window.websitePwned=1;</script>\u2028\u2029';
+ const appIcon =
+ 'https://example.com/icon.svg?next=</script><script>window.iconPwned=1;</script>\u2028\u2029';
const html = exportMapToHTML({
datasets: [],
config: {version: 'v1', config: {}},
mode: 'READ',
appName,
- appWebsite
+ appWebsite,
+ appIcon,
+ appNameColor: '</script><script>window.colorPwned=1</script>'
});
const brandingMatch = html.match(/const branding = (.+);/);
@@ -343,6 +378,14 @@ test('exportUtils -> ExportHtml safely serializes branding', t => {
html.includes('<script>window.websitePwned'),
'the app website should not be able to close the inline script'
);
+ t.notOk(
+ html.includes('<script>window.iconPwned'),
+ 'the app icon should not be able to close the inline script'
+ );
+ t.notOk(
+ html.includes('<script>window.colorPwned'),
+ 'an invalid app name color should not be serialized'
+ );
t.ok(
html.includes(
'<title>&lt;/title&gt;&lt;script&gt;window.brandPwned=1;&lt;/script&gt; &amp; Map\u2028\u2029 embedded map</title>'
@@ -360,7 +403,10 @@ test('exportUtils -> ExportHtml safely serializes branding', t => {
{
appName,
appWebsite:
- 'https://example.com/?next=%3C/script%3E%3Cscript%3Ewindow.websitePwned=1;%3C/script%3E'
+ 'https://example.com/?next=%3C/script%3E%3Cscript%3Ewindow.websitePwned=1;%3C/script%3E',
+ appIcon:
+ 'https://example.com/icon.svg?next=%3C/script%3E%3Cscript%3Ewindow.iconPwned=1;%3C/script%3E',
+ appNameColor: '#1FBAD6'
},
'escaped branding should retain its normalized values at runtime'
);