Skip to content

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

[chore] add cdnUrl option to application config (#3093)

Igor Dykhta3d3bb9b54bff
diff --git a/src/components/src/effects/effect-type-list-item.tsx b/src/components/src/effects/effect-type-list-item.tsx
index 8aa718d6b..348c5f8e8 100644
--- a/src/components/src/effects/effect-type-list-item.tsx
+++ b/src/components/src/effects/effect-type-list-item.tsx
@@ -5,8 +5,8 @@ import React from 'react';
import styled, {withTheme} from 'styled-components';
import classNames from 'classnames';
-import {KEPLER_UNFOLDED_BUCKET} from '@kepler.gl/constants';
import {FormattedMessage} from '@kepler.gl/localization';
+import {getApplicationConfig} from '@kepler.gl/utils';
import {Add} from '../common/icons';
@@ -30,9 +30,6 @@ const StyledListItem = styled.div`
.effect-type-selector__item__icon {
display: flex;
- background-image: url(${`${KEPLER_UNFOLDED_BUCKET}/images/kepler.gl-layer-icon-bg.png`});
- background-size: ${props => props.theme.effectTypeIconSizeL}px
- ${props => props.theme.effectTypeIconSizeL}px;
height: ${props => props.theme.effectTypeIconSizeL}px;
width: ${props => props.theme.effectTypeIconSizeL}px;
border-radius: 2px;
@@ -80,7 +77,7 @@ const getImageUrl = type => {
/[A-Z]+(?![a-z])|[A-Z]/g,
($, ofs) => (ofs ? '-' : '') + $.toLowerCase()
);
- return `${KEPLER_UNFOLDED_BUCKET}/images/effects/${kebab}.png`;
+ return `${getApplicationConfig().cdnUrl}/images/effects/${kebab}.png`;
};
export function EffectTypeListItemFactory() {
diff --git a/src/components/src/modals/add-map-style-modal.tsx b/src/components/src/modals/add-map-style-modal.tsx
index 0566708a0..c7886ca0c 100644
--- a/src/components/src/modals/add-map-style-modal.tsx
+++ b/src/components/src/modals/add-map-style-modal.tsx
@@ -224,7 +224,7 @@ function AddMapStyleModalFactory() {
this.props.inputMapStyle({
url: value,
id: 'Custom Style',
- icon: NO_BASEMAP_ICON
+ icon: `${getApplicationConfig().cdnUrl}/${NO_BASEMAP_ICON}`
})
}
placeholder="e.g. https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
diff --git a/src/components/src/side-panel/layer-panel/layer-type-list-item.tsx b/src/components/src/side-panel/layer-panel/layer-type-list-item.tsx
index b7424098a..17ec0cd37 100644
--- a/src/components/src/side-panel/layer-panel/layer-type-list-item.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-type-list-item.tsx
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
+import classNames from 'classnames';
import React, {ComponentType} from 'react';
import styled, {withTheme} from 'styled-components';
-import {KEPLER_UNFOLDED_BUCKET} from '@kepler.gl/constants';
-import classNames from 'classnames';
+
import {FormattedMessage} from '@kepler.gl/localization';
+import {getApplicationConfig} from '@kepler.gl/utils';
+
import {BaseProps} from '../../common/icons';
export type LayerTypeListItemProps = {
@@ -21,7 +23,11 @@ type WithThemeProps = LayerTypeListItemProps & {theme: Record<string, string>};
export type LayerTypeListItemType = React.FC<LayerTypeListItemProps>;
-const StyledListItem = styled.div`
+type StyledListItemProps = {
+ cdnUrl: string;
+};
+
+const StyledListItem = styled.div<StyledListItemProps>`
&.list {
display: flex;
align-items: center;
@@ -46,7 +52,7 @@ const StyledListItem = styled.div`
.layer-type-selector__item__icon {
color: ${props => props.theme.labelColor};
display: flex;
- background-image: url(${`${KEPLER_UNFOLDED_BUCKET}/images/kepler.gl-layer-icon-bg.png`});
+ background-image: url(${props => `${props.cdnUrl}/images/kepler.gl-layer-icon-bg.png`});
background-size: ${props => props.theme.layerTypeIconSizeL}px
${props => props.theme.layerTypeIconSizeL}px;
height: ${props => props.theme.layerTypeIconSizeL}px;
@@ -68,6 +74,7 @@ export function LayerTypeListItemFactory() {
className={classNames('layer-type-selector__item__inner', className, {
list: !isTile
})}
+ cdnUrl={getApplicationConfig().cdnUrl}
>
<div className="layer-type-selector__item__icon">
<value.icon height={`${isTile ? theme.layerTypeIconSizeL : theme.layerTypeIconSizeSM}px`} />
diff --git a/src/components/src/side-panel/layer-panel/raster-tile-colormap-list-item.tsx b/src/components/src/side-panel/layer-panel/raster-tile-colormap-list-item.tsx
index cecb5fba2..dc97d8edb 100644
--- a/src/components/src/side-panel/layer-panel/raster-tile-colormap-list-item.tsx
+++ b/src/components/src/side-panel/layer-panel/raster-tile-colormap-list-item.tsx
@@ -4,8 +4,7 @@
import React from 'react';
import styled from 'styled-components';
-import {RasterLayerResources as cdnUrls} from '@kepler.gl/constants';
-import {getCategoricalColormapDataUrl} from '@kepler.gl/layers';
+import {getCategoricalColormapDataUrl, RasterLayerResources} from '@kepler.gl/layers';
import type {CategoricalColormapOptions} from '@kepler.gl/layers';
const StyledColorMapListItem = styled.div`
@@ -40,7 +39,7 @@ const ColorMapImg: React.FC<{id: string; categoricalOptions: CategoricalColormap
}
url = dataUrl;
} else {
- url = cdnUrls.rasterColorMap(id);
+ url = RasterLayerResources.rasterColorMap(id);
}
return <img src={url} style={{width: '100%', height: '100%'}} />;
};
diff --git a/src/components/src/side-panel/map-style-panel/map-style-selector.tsx b/src/components/src/side-panel/map-style-panel/map-style-selector.tsx
index 4a2ecd6f5..a19bd7df4 100644
--- a/src/components/src/side-panel/map-style-panel/map-style-selector.tsx
+++ b/src/components/src/side-panel/map-style-panel/map-style-selector.tsx
@@ -9,6 +9,7 @@ import {FormattedMessage} from '@kepler.gl/localization';
import {MapStyle} from '@kepler.gl/reducers';
import {NO_BASEMAP_ICON} from '@kepler.gl/constants';
import {MapStyles} from '@kepler.gl/types';
+import {getApplicationConfig} from '@kepler.gl/utils';
import {ArrowDown} from '../../common/icons';
import PanelHeaderActionFactory from '../panel-header-action';
@@ -113,7 +114,12 @@ function MapStyleSelectorFactory(PanelHeaderAction: ReturnType<typeof PanelHeade
</PanelLabel>
{Object.values(mapStyles).map(
- ({id, custom, icon = NO_BASEMAP_ICON, label = 'Untitled'}) => (
+ ({
+ id,
+ custom,
+ icon = `${getApplicationConfig().cdnUrl}/${NO_BASEMAP_ICON}`,
+ label = 'Untitled'
+ }) => (
<StyledMapDropdown
className={classnames('map-dropdown-option', {
collapsed: !isSelecting && id !== styleType,
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index fd311a216..79309ff51 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -25,7 +25,7 @@ import {TOOLTIP_FORMAT_TYPES} from './tooltip';
export const ACTION_PREFIX = '@@kepler.gl/';
export const KEPLER_UNFOLDED_BUCKET = 'https://studio-public-data.foursquare.com/statics/keplergl';
-export const BASEMAP_ICON_PREFIX = `${KEPLER_UNFOLDED_BUCKET}/geodude`;
+export const BASEMAP_ICON_PREFIX = `geodude`;
export const DEFAULT_MAPBOX_API_URL = 'https://api.mapbox.com';
export const TRANSITION_DURATION = 0;
@@ -1594,12 +1594,6 @@ export enum GEOARROW_EXTENSIONS {
WKB = 'geoarrow.wkb'
}
-export const RasterLayerResources = {
- rasterColorMap: (colormapId: string) => {
- return `${KEPLER_UNFOLDED_BUCKET}/raster/colormaps/${colormapId}.png`;
- }
-};
-
export const LOADERS_CDN_URL = 'https://unpkg.com/@loaders.gl';
export const getLoaderOptions = () => {
diff --git a/src/layers/src/icon-layer/icon-layer.ts b/src/layers/src/icon-layer/icon-layer.ts
index ac8cccad6..5176b1dc8 100644
--- a/src/layers/src/icon-layer/icon-layer.ts
+++ b/src/layers/src/icon-layer/icon-layer.ts
@@ -7,14 +7,14 @@ import GL from '@luma.gl/constants';
import {SvgIconLayer} from '@kepler.gl/deckgl-layers';
import IconLayerIcon from './icon-layer-icon';
-import {ICON_FIELDS, KEPLER_UNFOLDED_BUCKET} from '@kepler.gl/constants';
+import {ICON_FIELDS} from '@kepler.gl/constants';
import IconInfoModalFactory from './icon-info-modal';
import Layer, {LayerBaseConfig, LayerBaseConfigPartial} from '../base-layer';
import {assignPointPairToLayerColumn, FindDefaultLayerPropsReturnValue} from '../layer-utils';
import {isTest} from '@kepler.gl/utils';
import {getTextOffsetByRadius, formatTextLabelData} from '../layer-text-label';
import {default as KeplerTable} from '@kepler.gl/table';
-import {DataContainerInterface} from '@kepler.gl/utils';
+import {getApplicationConfig, DataContainerInterface} from '@kepler.gl/utils';
import {
ColorRange,
VisConfigBoolean,
@@ -60,8 +60,6 @@ export type IconLayerData = {index: number; icon: string};
const brushingExtension = new BrushingExtension();
-export const SVG_ICON_URL = `${KEPLER_UNFOLDED_BUCKET}/icons/svg-icons.json`;
-
export const iconPosAccessor =
({lat, lng, altitude}: IconLayerColumnsConfig) =>
(dc: DataContainerInterface) =>
@@ -147,7 +145,7 @@ export default class IconLayer extends Layer {
}
get svgIconUrl() {
- return SVG_ICON_URL;
+ return `${getApplicationConfig().cdnUrl}/icons/svg-icons.json`;
}
get type(): 'icon' {
diff --git a/src/layers/src/index.ts b/src/layers/src/index.ts
index 9f8d4635a..b21f93d41 100644
--- a/src/layers/src/index.ts
+++ b/src/layers/src/index.ts
@@ -57,6 +57,7 @@ export {
RASTER_COLOR_RESET_PARAMS,
PRESET_OPTIONS
} from './raster-tile/config';
+export {RasterLayerResources} from './raster-tile/url';
export {getCategoricalColormapDataUrl} from './raster-tile/image';
export * from './raster-tile/types';
export * from './raster-tile/raster-tile-utils';
diff --git a/src/layers/src/raster-tile/image.ts b/src/layers/src/raster-tile/image.ts
index 1d5b3abb4..682b24b54 100644
--- a/src/layers/src/raster-tile/image.ts
+++ b/src/layers/src/raster-tile/image.ts
@@ -9,7 +9,7 @@ import {load} from '@loaders.gl/core';
import {QuantizedMeshLoader} from '@loaders.gl/terrain';
import memoize from 'lodash/memoize';
-import {getLoaderOptions, RasterLayerResources as cdnUrls} from '@kepler.gl/constants';
+import {getLoaderOptions} from '@kepler.gl/constants';
import {CATEGORICAL_COLORMAP_ID} from './config';
import {
@@ -32,7 +32,8 @@ import {
getTerrainUrl,
getSingleCOGUrlParams,
getStacApiUrlParams,
- getMeshMaxError
+ getMeshMaxError,
+ RasterLayerResources
} from './url';
/**
@@ -128,7 +129,10 @@ async function loadColormap(colormapId: string): Promise<ColormapImageData | nul
return null;
}
- const request = await getAssetRequest({url: cdnUrls.rasterColorMap(colormapId), options: {}});
+ const request = await getAssetRequest({
+ url: RasterLayerResources.rasterColorMap(colormapId),
+ options: {}
+ });
return loadImage(request.url, COLORMAP_TEXTURE_PARAMETERS, request.options);
}
diff --git a/src/layers/src/raster-tile/url.ts b/src/layers/src/raster-tile/url.ts
index fa5b92755..750375456 100644
--- a/src/layers/src/raster-tile/url.ts
+++ b/src/layers/src/raster-tile/url.ts
@@ -222,3 +222,9 @@ export function getTerrainUrl(
export function getMeshMaxError(z: number, multiplier: number): number {
return (77067.34 / (1 << z)) * multiplier;
}
+
+export const RasterLayerResources = {
+ rasterColorMap: (colormapId: string) => {
+ return `${getApplicationConfig().cdnUrl}/raster/colormaps/${colormapId}.png`;
+ }
+};
diff --git a/src/reducers/src/index.ts b/src/reducers/src/index.ts
index f2c46c166..40203f9c4 100644
--- a/src/reducers/src/index.ts
+++ b/src/reducers/src/index.ts
@@ -60,6 +60,7 @@ export * from './vis-state-updaters';
export {INITIAL_UI_STATE} from './ui-state-updaters';
+export {getDefaultMapStyles} from './map-style-updaters';
export type {MapboxStyleUrl, MapStyle} from './map-style-updaters';
export * from './data-utils';
diff --git a/src/reducers/src/map-style-updaters.ts b/src/reducers/src/map-style-updaters.ts
index 3fa8175de..b08338ebd 100644
--- a/src/reducers/src/map-style-updaters.ts
+++ b/src/reducers/src/map-style-updaters.ts
@@ -15,7 +15,8 @@ import {
getStyleImageIcon,
isPlainObject,
hexToRgb,
- colorMaybeToRGB
+ colorMaybeToRGB,
+ getApplicationConfig
} from '@kepler.gl/utils';
import {generateHashId} from '@kepler.gl/common-utils';
import {
@@ -71,6 +72,19 @@ export type MapStyle = {
};
};
+export const getDefaultMapStyles = (cdnUrl: string) => {
+ return DEFAULT_MAP_STYLES.reduce(
+ (accu, curr) => ({
+ ...accu,
+ [curr.id]: {
+ ...curr,
+ icon: `${cdnUrl}/${curr.icon}`
+ }
+ }),
+ {}
+ );
+};
+
const getDefaultState = (): MapStyle => {
const visibleLayerGroups = {};
const topLayerGroups = {};
@@ -79,13 +93,7 @@ const getDefaultState = (): MapStyle => {
styleType: DEFAULT_BASE_MAP_STYLE,
visibleLayerGroups,
topLayerGroups,
- mapStyles: DEFAULT_MAP_STYLES.reduce(
- (accu, curr) => ({
- ...accu,
- [curr.id]: curr
- }),
- {}
- ),
+ mapStyles: getDefaultMapStyles(getApplicationConfig().cdnUrl),
// save mapbox access token
mapboxApiAccessToken: null,
mapboxApiUrl: DEFAULT_MAPBOX_API_URL,
diff --git a/src/utils/src/application-config.ts b/src/utils/src/application-config.ts
index 1167a6f99..cea436b33 100644
--- a/src/utils/src/application-config.ts
+++ b/src/utils/src/application-config.ts
@@ -3,6 +3,7 @@
import {MapLib, MapRef} from 'react-map-gl';
+import {KEPLER_UNFOLDED_BUCKET} from '@kepler.gl/constants';
import type {BaseMapLibraryType} from '@kepler.gl/constants';
import type {DatabaseAdapter} from './application-config-types';
@@ -47,6 +48,9 @@ export type KeplerApplicationConfig = {
// especially if large Arrow files are split into relatively small batches (should be fixed in the future).
useOnFilteredItemsChange?: boolean;
+ // A URL to the CDN where the kepler.gl assets are hosted.
+ cdnUrl?: string;
+
// Raster Tile layer config
// Raster Tile layer is under development and not ready for production use. Disabled by default.
enableRasterTileLayer?: boolean;
@@ -84,6 +88,8 @@ const DEFAULT_APPLICATION_CONFIG: Required<KeplerApplicationConfig> = {
}
},
+ cdnUrl: KEPLER_UNFOLDED_BUCKET,
+
plugins: [],
// The default table class is KeplerTable.
// TODO include KeplerTable here when the circular dependency with @kepler.gl/table and @kepler.gl/utils are resolved.
diff --git a/test/browser/components/kepler-gl-test.js b/test/browser/components/kepler-gl-test.js
index 0fd7d393f..1479b6b3b 100644
--- a/test/browser/components/kepler-gl-test.js
+++ b/test/browser/components/kepler-gl-test.js
@@ -10,7 +10,7 @@ import {drainTasksForTesting, succeedTaskWithValues} from 'react-palm/tasks';
import configureStore from 'redux-mock-store';
import {Provider} from 'react-redux';
-import {keplerGlReducerCore as coreReducer} from '@kepler.gl/reducers';
+import {keplerGlReducerCore as coreReducer, getDefaultMapStyles} from '@kepler.gl/reducers';
import {keplerGlInit, ActionTypes} from '@kepler.gl/actions';
import {
appInjector,
@@ -23,7 +23,12 @@ import {
GeocoderPanelFactory,
NotificationPanelFactory
} from '@kepler.gl/components';
-import {DEFAULT_MAP_STYLES, EXPORT_IMAGE_ID, GEOCODER_DATASET_NAME} from '@kepler.gl/constants';
+import {
+ DEFAULT_MAP_STYLES,
+ EXPORT_IMAGE_ID,
+ GEOCODER_DATASET_NAME,
+ KEPLER_UNFOLDED_BUCKET
+} from '@kepler.gl/constants';
// mock state
import {StateWithGeocoderDataset} from 'test/helpers/mock-state';
@@ -235,7 +240,7 @@ test('Components -> KeplerGl -> Mount -> Load default map style task', t => {
{
type: ActionTypes.LOAD_MAP_STYLES,
payload: {
- newStyles: DEFAULT_MAP_STYLES.reduce((accu, curr) => ({...accu, [curr.id]: curr}), {}),
+ newStyles: getDefaultMapStyles(KEPLER_UNFOLDED_BUCKET),
onSuccess: undefined
}
}
@@ -269,6 +274,7 @@ test('Components -> KeplerGl -> Mount -> Load default map style task', t => {
...tmpState.mapStyle.mapStyles,
'dark-matter': {
...DEFAULT_MAP_STYLES[1],
+ icon: `${KEPLER_UNFOLDED_BUCKET}/${DEFAULT_MAP_STYLES[1].icon}`,
style: {layers: [], name: 'dark'}
}
};
diff --git a/test/node/reducers/map-style-test.js b/test/node/reducers/map-style-test.js
index 2888d3c6e..2703db576 100644
--- a/test/node/reducers/map-style-test.js
+++ b/test/node/reducers/map-style-test.js
@@ -8,6 +8,7 @@ import {
mapStyleReducer as reducer,
INITIAL_MAP_STYLE,
loadMapStylesUpdater,
+ getDefaultMapStyles,
getInitialInputStyle
} from '@kepler.gl/reducers';
import {
@@ -21,7 +22,7 @@ import {
removeCustomMapStyle
} from '@kepler.gl/actions';
import SchemaManager from '@kepler.gl/schemas';
-import {DEFAULT_MAP_STYLES, DEFAULT_MAPBOX_API_URL, NO_MAP_ID} from '@kepler.gl/constants';
+import {DEFAULT_MAPBOX_API_URL, KEPLER_UNFOLDED_BUCKET, NO_MAP_ID} from '@kepler.gl/constants';
// helpers
import {
@@ -195,13 +196,7 @@ test("#mapStyleReducer -> RECEIVE_MAP_CONFIG (custom: 'LOCAL')", t => {
const tmpStateWithConfig = reducer(stateWithToken, receiveMapConfig(stateLoaded));
- const defaultMapStyles = DEFAULT_MAP_STYLES.reduce(
- (accu, st) => ({
- ...accu,
- [st.id]: st
- }),
- {}
- );
+ const defaultMapStyles = getDefaultMapStyles(KEPLER_UNFOLDED_BUCKET);
const expectedStateWithConfig = {
styleType: 'smoothie_the_cat',
@@ -365,13 +360,7 @@ test("#mapStyleReducer -> RECEIVE_MAP_CONFIG (custom: 'MANAGED')", t => {
const tmpStateWithConfig = reducer(stateWithToken, receiveMapConfig(stateLoaded));
- const defaultMapStyles = DEFAULT_MAP_STYLES.reduce(
- (accu, st) => ({
- ...accu,
- [st.id]: st
- }),
- {}
- );
+ const defaultMapStyles = getDefaultMapStyles(KEPLER_UNFOLDED_BUCKET);
const expectedStateWithConfig = {
styleType: 'smoothie_the_cat',
@@ -466,13 +455,7 @@ test('#mapStyleReducer -> RECEIVE_MAP_CONFIG (custom: true (legacy backwards sup
const stateWithConfig = reducer(stateWithToken, receiveMapConfig(stateLoaded));
- const defaultMapStyles = DEFAULT_MAP_STYLES.reduce(
- (accu, st) => ({
- ...accu,
- [st.id]: st
- }),
- {}
- );
+ const defaultMapStyles = getDefaultMapStyles(KEPLER_UNFOLDED_BUCKET);
const expectedStateWithConfig = {
styleType: 'smoothie_the_cat',