Skip to content

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

[Enhancement] (#762) Generate custom map style icon from style url

Shan He2acfba5f75a6
diff --git a/README.md b/README.md
index ed49b8c44..7525bcfc2 100644
--- a/README.md
+++ b/README.md
@@ -243,6 +243,54 @@ Read more about [Components][components].
You can pass theme name or object used to customize Kepler.gl style. Kepler.gl provide an `'light'` theme besides the default 'dark' theme. When pass in a theme object Kepler.gl will use the value passed as input to override values from [theme](https://github.com/keplergl/kepler.gl/blob/master/src/styles/base.js).
+#### `mapboxApiUrl` (String, optional)
+
+- Default: `https://api.mapbox.com`
+
+If you are using your own mapbox tile server, you can pass in your own tile server api url.
+
+#### `mapStylesReplaceDefault` (Boolean, optional)
+
+- Default: `false`
+
+kepler.gl provide 4 map styles to choose from. Pass `true` if you want to supply your own `mapStyles`. See Below.
+
+#### `mapStyles` (Array, optional)
+
+- Default: `[]`
+
+You can supply additional map styles to be displayed in [map style selection panel](https://github.com/keplergl/kepler.gl/blob/master/docs/user-guides/f-map-styles/1-base-map-styles.md). By default, additional map styles will be added to default map styles. If pass `mapStylesReplaceDefault: true`, they will replace the default ones. kepler.gl will attempt to group layers of your style based on its `id` naming convention and use it to allow toggle visibility of [base map layers](https://github.com/keplergl/kepler.gl/blob/master/docs/user-guides/f-map-styles/2-map-layers.md). Supply your own `layerGroups` to override default for more accurate layer grouping.
+
+Each `mapStyles` should has the following properties:
+ - `id` (String, required) unique string that should **not** be one of these reserved `dark` `light` `muted`. `muted_night`
+ - `label` (String, required) name to be displayed in map style selection panel
+ - `url` (String, required) mapbox style url or a url pointing to the map style json object
+ - `icon` (String, optional) image icon of the style, it can be a url, or an [image data url](https://flaviocopes.com/data-urls/#how-does-a-data-url-look)
+ - `layerGroups` (Array, optional)
+
+```js
+ const mapStyles = [
+ {
+ id: 'my_dark_map',
+ label: 'Dark Streets 9',
+ url: 'mapbox://styles/mapbox/dark-v9',
+ icon: `${apiHost}/styles/v1/mapbox/dark-v9/static/-122.3391,37.7922,9.19,0,0/400x300?access_token=${accessToken}&logo=false&attribution=false`,
+ layerGroups: [{
+ slug: 'label',
+ filter: ({id}) => id.match(/(?=(label|place-|poi-))/),
+ defaultVisibility: true
+ }, {
+ // adding this will keep the 3d building option
+ slug: '3d building',
+ filter: () => false,
+ defaultVisibility: false
+ }]
+ }
+ ];
+
+```
+
+
### 3. Dispatch custom actions to `keplerGl` reducer.
One advantage of using the reducer over React component state to handle keplerGl state is the flexibility
diff --git a/src/actions/map-style-actions.js b/src/actions/map-style-actions.js
index 510aa3e50..81f3a726d 100644
--- a/src/actions/map-style-actions.js
+++ b/src/actions/map-style-actions.js
@@ -43,11 +43,12 @@ export const addCustomMapStyle = createAction(
* @param {string} inputStyle.name - style name
* @param {Object} inputStyle.layerGroups - layer groups that can be used to set map layer visibility
* @param {Object} inputStyle.icon - icon image data url
+ * @param {Object} mapState - mapState is optional
* @public
*/
export const inputMapStyle = createAction(
ActionTypes.INPUT_MAP_STYLE,
- inputStyle => inputStyle
+ (inputStyle, mapState) => ({inputStyle, mapState})
);
/**
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index 62249433c..cbefbd65f 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -35,7 +35,8 @@ import {
DIMENSIONS,
KEPLER_GL_NAME,
KEPLER_GL_VERSION,
- THEME
+ THEME,
+ DEFAULT_MAPBOX_API_URL
} from 'constants/default-settings';
import {MISSING_MAPBOX_TOKEN} from 'constants/user-feedbacks';
@@ -103,6 +104,7 @@ function KeplerGlFactory(
static defaultProps = {
mapStyles: [],
mapStylesReplaceDefault: false,
+ mapboxApiUrl: DEFAULT_MAPBOX_API_URL,
width: 800,
height: 800,
appName: KEPLER_GL_NAME,
diff --git a/src/components/modals/add-map-style-modal.js b/src/components/modals/add-map-style-modal.js
index 2c6824ce7..1c8d3e104 100644
--- a/src/components/modals/add-map-style-modal.js
+++ b/src/components/modals/add-map-style-modal.js
@@ -23,8 +23,11 @@ import PropTypes from 'prop-types';
import classnames from 'classnames';
import styled from 'styled-components';
import MapboxGLMap from 'react-map-gl';
-import {findDOMNode} from 'react-dom';
-import {StyledModalContent, InputLight, StyledMapContainer} from 'components/common/styled-components';
+import {
+ StyledModalContent,
+ InputLight,
+ StyledMapContainer
+} from 'components/common/styled-components';
import {media} from 'styles/media-breakpoints';
// Utils
@@ -33,7 +36,8 @@ import {transformRequest} from 'utils/map-style-utils/mapbox-utils';
const MapH = 190;
const MapW = 264;
const ErrorMsg = {
- styleError : 'Failed to load map style, make sure it is published. For private style, paste in your access token.'
+ styleError:
+ 'Failed to load map style, make sure it is published. For private style, paste in your access token.'
};
const InstructionPanel = styled.div`
@@ -41,14 +45,14 @@ const InstructionPanel = styled.div`
flex-direction: column;
justify-content: space-around;
font-size: 12px;
-
+
.modal-section:first-child {
margin-top: 24px;
${media.palm`
margin-top: 0;
`};
}
-
+
input {
margin-right: 8px;
}
@@ -63,11 +67,11 @@ const StyledModalSection = styled.div`
.modal-section-subtitle {
color: ${props => props.theme.subtextColorLT};
}
-
+
input {
margin-top: 8px;
}
-
+
${media.portable`
margin-bottom: 24px;
`};
@@ -89,15 +93,15 @@ const PreviewMap = styled.div`
font-size: 10px;
padding: 8px 0px;
}
-
+
.preview-title.error {
color: ${props => props.theme.errorColor};
}
-
+
${media.portable`
margin-left: 32px;
`};
-
+
${media.palm`
margin-left: unset;
.preview-title {
@@ -109,11 +113,11 @@ const PreviewMap = styled.div`
const StyledPreviewImage = styled.div`
background: ${props => props.theme.modalImagePlaceHolder};
border-radius: 4px;
- box-shadow: 0 8px 16px 0 rgba(0,0,0,0.18);
+ box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.18);
width: ${MapW}px;
height: ${MapH}px;
position: relative;
-
+
.preview-image-placeholder {
position: absolute;
top: 0;
@@ -129,7 +133,7 @@ const StyledPreviewImage = styled.div`
const InlineLink = styled.a`
font-weight: 500;
-
+
:hover {
cursor: pointer;
}
@@ -137,10 +141,12 @@ const InlineLink = styled.a`
class AddMapStyleModal extends Component {
static propTypes = {
- mapState: PropTypes.object.isRequired,
inputMapStyle: PropTypes.func.isRequired,
+ inputStyle: PropTypes.object.isRequired,
loadCustomMapStyle: PropTypes.func.isRequired,
- inputStyle: PropTypes.object.isRequired
+ mapboxApiAccessToken: PropTypes.string.isRequired,
+ mapboxApiUrl: PropTypes.string.isRequired,
+ mapState: PropTypes.object.isRequired
};
state = {
@@ -148,7 +154,9 @@ class AddMapStyleModal extends Component {
};
componentWillReceiveProps(nextProps) {
- if (this.props.inputStyle.accessToken !== nextProps.inputStyle.accessToken) {
+ if (
+ this.props.inputStyle.accessToken !== nextProps.inputStyle.accessToken
+ ) {
// toke has changed
// ReactMapGl doesn't re-create map when token has changed
// here we force the map to update
@@ -158,7 +166,7 @@ class AddMapStyleModal extends Component {
}
}
- componentDidUpdate() {
+ componentDidUpdate(prevProps) {
const map = this.mapRef && this.mapRef.getMap();
if (map && this._map !== map) {
this._map = map;
@@ -168,65 +176,81 @@ class AddMapStyleModal extends Component {
this.loadMapStyleJson(style);
});
- map.on('render', () => {
- if (map.isStyleLoaded()) {
- this.loadMapStyleIcon();
- }
- });
-
map.on('error', () => {
- this.loadMaoStyleError();
- })
+ this.loadMapStyleError();
+ });
}
}
- loadMapStyleJson = (style) => {
+ loadMapStyleJson = style => {
this.props.loadCustomMapStyle({style, error: false});
};
- loadMapStyleIcon = () => {
- if (this.mapRef) {
- const canvas = findDOMNode(this.mapRef).querySelector('.mapboxgl-canvas');
- const dataUri = canvas.toDataURL();
- this.props.loadCustomMapStyle({
- icon: dataUri
- });
- }
- };
-
- loadMaoStyleError = () => {
+ loadMapStyleError = () => {
this.props.loadCustomMapStyle({error: true});
};
render() {
- const {inputStyle, mapState} = this.props;
+ const {
+ inputStyle,
+ mapState,
+ mapboxApiUrl
+ } = this.props;
- const mapProps = {
- ...mapState,
- preserveDrawingBuffer: true,
- mapboxApiAccessToken: inputStyle.accessToken || this.props.mapboxApiAccessToken,
- transformRequest
- };
+ const mapboxApiAccessToken = inputStyle.accessToken || this.props.mapboxApiAccessToken;
+ const mapProps = {
+ ...mapState,
+ mapboxApiUrl,
+ mapboxApiAccessToken,
+ preserveDrawingBuffer: true,
+ transformRequest
+ };
return (
<div className="add-map-style-modal">
<StyledModalContent>
<InstructionPanel>
<StyledModalSection className="modal-section">
- <div className="modal-section-title">1. Publish your style at mapbox or provide access token</div>
+ <div className="modal-section-title">
+ 1. Publish your style at mapbox or provide access token
+ </div>
<div className="modal-section-subtitle">
You can create your own map style at
- <InlineLink target="_blank" href="https://www.mapbox.com/studio/styles/"> mapbox</InlineLink> and
- <InlineLink target="_blank" href="https://www.mapbox.com/help/studio-manual-publish/"> publish</InlineLink> it.
+ <InlineLink
+ target="_blank"
+ href="https://www.mapbox.com/studio/styles/"
+ >
+ {' '}
+ mapbox
+ </InlineLink>{' '}
+ and
+ <InlineLink
+ target="_blank"
+ href="https://www.mapbox.com/help/studio-manual-publish/"
+ >
+ {' '}
+ publish
+ </InlineLink>{' '}
+ it.
</div>
<div className="modal-section-subtitle">
To use private style, paste your
- <InlineLink target="_blank" href="https://www.mapbox.com/help/how-access-tokens-work/"> access token</InlineLink> here. *kepler.gl is a client-side application, data stays in your browser..
+ <InlineLink
+ target="_blank"
+ href="https://www.mapbox.com/help/how-access-tokens-work/"
+ >
+ {' '}
+ access token
+ </InlineLink>{' '}
+ here. *kepler.gl is a client-side application, data stays in
+ your browser..
</div>
<InputLight
type="text"
value={inputStyle.accessToken || ''}
- onChange={({target: {value}}) => this.props.inputMapStyle({...inputStyle, accessToken: value})}
+ onChange={({target: {value}}) =>
+ this.props.inputMapStyle({accessToken: value})
+ }
placeholder="e.g. pk.abcdefg.xxxxxx"
/>
</StyledModalSection>
@@ -234,12 +258,20 @@ class AddMapStyleModal extends Component {
<div className="modal-section-title">2. Paste style url</div>
<div className="modal-section-subtitle">
What is a
- <InlineLink target="_blank" href="https://www.mapbox.com/help/studio-manual-publish/#style-url"> style URL</InlineLink>
+ <InlineLink
+ target="_blank"
+ href="https://www.mapbox.com/help/studio-manual-publish/#style-url"
+ >
+ {' '}
+ style URL
+ </InlineLink>
</div>
<InputLight
type="text"
value={inputStyle.url || ''}
- onChange={({target: {value}}) => this.props.inputMapStyle({...inputStyle, url: value})}
+ onChange={({target: {value}}) =>
+ this.props.inputMapStyle({url: value})
+ }
placeholder="e.g. mapbox://styles/uberdataviz/abcdefghijklmnopq"
/>
</StyledModalSection>
@@ -248,17 +280,24 @@ class AddMapStyleModal extends Component {
<InputLight
type="text"
value={inputStyle.label || ''}
- onChange={({target: {value}}) => this.props.inputMapStyle({...inputStyle, label: value})}
+ onChange={({target: {value}}) =>
+ this.props.inputMapStyle({label: value})
+ }
/>
</StyledModalSection>
</InstructionPanel>
<PreviewMap>
- <div className={classnames('preview-title', {error: inputStyle.error})}>
- {inputStyle.error ? ErrorMsg.styleError :
- (inputStyle.style && inputStyle.style.name) || ''}</div>
+ <div
+ className={classnames('preview-title', {error: inputStyle.error})}
+ >
+ {inputStyle.error
+ ? ErrorMsg.styleError
+ : (inputStyle.style && inputStyle.style.name) || ''}
+ </div>
<StyledPreviewImage className="preview-image">
- {!inputStyle.isValid ?
- <div className="preview-image-spinner"/> :
+ {!inputStyle.isValid ? (
+ <div className="preview-image-spinner" />
+ ) : (
<StyledMapContainer>
<MapboxGLMap
{...mapProps}
@@ -268,9 +307,10 @@ class AddMapStyleModal extends Component {
key={this.state.reRenderKey}
width={MapW}
height={MapH}
- mapStyle={inputStyle.url}/>
+ mapStyle={inputStyle.url}
+ />
</StyledMapContainer>
- }
+ )}
</StyledPreviewImage>
</PreviewMap>
</StyledModalContent>
diff --git a/src/components/modals/export-map-modal.js b/src/components/modals/export-map-modal.js
index cede6aa67..adf833b6e 100644
--- a/src/components/modals/export-map-modal.js
+++ b/src/components/modals/export-map-modal.js
@@ -47,7 +47,7 @@ const StyledInput = styled.input`
height: ${props => props.theme.inputBoxHeight};
outline: 0;
font-size: ${props => props.theme.inputFontSize};
-
+
:active,
:focus,
&.focus,
@@ -166,7 +166,7 @@ const StyledJsonExportSection = styled(ExportMapStyledExportSection)`
color: ${props => props.theme.errorColor};
font-size: 11px;
}
-
+
.viewer {
border: 1px solid ${props => props.theme.selectBorderColorLT};
background-color: white;
@@ -180,6 +180,10 @@ const StyledJsonExportSection = styled(ExportMapStyledExportSection)`
height: 180px;
width: 100%;
overflow-y: scroll;
+ overflow-x: auto;
+ white-space: pre-wrap;
+ word-wrap: break-word;
+ max-width: 600px;
}
`;
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index b663f3dfd..41b76275f 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -33,6 +33,7 @@ import {
export const ACTION_PREFIX = '@@kepler.gl/';
export const CLOUDFRONT = 'https://d1a3f4spazzrp4.cloudfront.net/kepler.gl';
export const ICON_PREFIX = `${CLOUDFRONT}/geodude`;
+export const DEFAULT_MAPBOX_API_URL = 'https://api.mapbox.com';
// Modal Ids
/**
diff --git a/src/layers/trip-layer/trip-layer.js b/src/layers/trip-layer/trip-layer.js
index 0fbbfa4a8..35ddde128 100644
--- a/src/layers/trip-layer/trip-layer.js
+++ b/src/layers/trip-layer/trip-layer.js
@@ -330,8 +330,10 @@ export default class TripLayer extends Layer {
rounded: true,
pickable: true,
autoHighlight: true,
- parameters: {depthTest: mapState.dragRotate},
-
+ parameters: {
+ depthTest: mapState.dragRotate,
+ depthMask: false
+ },
trailLength: visConfig.trailLength * 1000,
currentTime: animationConfig.currentTime - animationConfig.domain[0],
updateTriggers
diff --git a/src/reducers/map-style-updaters.js b/src/reducers/map-style-updaters.js
index 16ec286db..1dce262a3 100644
--- a/src/reducers/map-style-updaters.js
+++ b/src/reducers/map-style-updaters.js
@@ -28,11 +28,13 @@ import {
getStyleDownloadUrl,
mergeLayerGroupVisibility,
editTopMapStyle,
- editBottomMapStyle
+ editBottomMapStyle,
+ getStyleImageIcon
} from 'utils/map-style-utils/mapbox-gl-style-editor';
import {
DEFAULT_MAP_STYLES,
- DEFAULT_LAYER_GROUPS
+ DEFAULT_LAYER_GROUPS,
+ DEFAULT_MAPBOX_API_URL
} from 'constants/default-settings';
import {generateHashId} from 'utils/utils';
import {LOAD_MAP_STYLE_TASK} from 'tasks/tasks';
@@ -60,7 +62,7 @@ const getDefaultState = () => {
),
// save mapbox access token
mapboxApiAccessToken: null,
- mapboxApiUrl: null,
+ mapboxApiUrl: DEFAULT_MAPBOX_API_URL,
mapStylesReplaceDefault: false,
inputStyle: getInitialInputStyle(),
threeDBuildingColor: hexToRgb(DEFAULT_BLDG_COLOR),
@@ -235,7 +237,7 @@ export const initMapStyleUpdater = (state, action) => ({
...state,
// save mapbox access token to map style state
mapboxApiAccessToken: (action.payload || {}).mapboxApiAccessToken,
- mapboxApiUrl: (action.payload || {}).mapboxApiUrl,
+ mapboxApiUrl: (action.payload || {}).mapboxApiUrl || state.mapboxApiUrl,
mapStyles:
action.payload && !action.payload.mapStylesReplaceDefault
? state.mapStyles
@@ -448,6 +450,7 @@ export const resetMapConfigMapStyleUpdater = state => {
...INITIAL_MAP_STYLE,
mapboxApiAccessToken: state.mapboxApiAccessToken,
mapboxApiUrl: state.mapboxApiUrl,
+ mapStylesReplaceDefault: state.mapStylesReplaceDefault,
...state.initialState,
mapStyles: state.mapStyles,
initialState: state.initialState
@@ -506,13 +509,29 @@ export const loadCustomMapStyleUpdater = (
* @returns {Object} nextState
* @public
*/
-export const inputMapStyleUpdater = (state, {payload: inputStyle}) => ({
- ...state,
- inputStyle: {
- ...inputStyle,
- isValid: isValidStyleUrl(inputStyle.url)
+export const inputMapStyleUpdater = (state, {payload: {inputStyle, mapState}}) => {
+ const updated = {
+ ...state.inputStyle,
+ ...inputStyle
+ };
+
+ const isValid = isValidStyleUrl(updated.url);
+ const icon = isValid ? getStyleImageIcon({
+ mapState,
+ styleUrl: updated.url,
+ mapboxApiAccessToken: updated.accessToken || state.mapboxApiAccessToken,
+ mapboxApiUrl: state.mapboxApiUrl || DEFAULT_MAPBOX_API_URL
+ }) : state.inputStyle.icon;
+
+ return {
+ ...state,
+ inputStyle: {
+ ...updated,
+ isValid,
+ icon
+ }
}
-});
+};
/**
* Add map style from user input to reducer and set it to current style
@@ -551,6 +570,7 @@ export function getInitialInputStyle() {
label: null,
style: null,
url: null,
+ icon: null,
custom: true
};
}
diff --git a/src/utils/map-style-utils/mapbox-gl-style-editor.js b/src/utils/map-style-utils/mapbox-gl-style-editor.js
index d1af46f7e..1582feae1 100644
--- a/src/utils/map-style-utils/mapbox-gl-style-editor.js
+++ b/src/utils/map-style-utils/mapbox-gl-style-editor.js
@@ -23,9 +23,13 @@ import clondDeep from 'lodash.clonedeep';
import {
DEFAULT_LAYER_GROUPS,
RESOLUTIONS,
- RESOLUTION_OPTIONS
+ RESOLUTION_OPTIONS,
+ DEFAULT_MAPBOX_API_URL
} from 'constants/default-settings';
+const mapUrlRg = /^mapbox:\/\/styles\/[-a-z0-9]{2,256}\/[-a-z0-9]{2,256}/;
+const httpRg = /^(?=(http:|https:))/;
+
export function getDefaultLayerGroupVisibility({layerGroups = []}) {
return layerGroups.reduce(
(accu, layer) => ({
@@ -45,9 +49,9 @@ const resolver = ({id, mapStyle, visibleLayerGroups = {}}) =>
/**
* Edit preset map style to keep only visible layers
*
- * @param {object} mapStyle - preset map style
- * @param {object} visibleLayerGroups - visible layers of top map
- * @returns {object} top map style
+ * @param {Object} mapStyle - preset map style
+ * @param {Object} visibleLayerGroups - visible layers of top map
+ * @returns {Object} top map style
*/
export const editTopMapStyle = memoize(({id, mapStyle, visibleLayerGroups}) => {
const visibleFilters = (mapStyle.layerGroups || [])
@@ -69,9 +73,9 @@ export const editTopMapStyle = memoize(({id, mapStyle, visibleLayerGroups}) => {
/**
* Edit preset map style to filter out invisible layers
*
- * @param {object} mapStyle - preset map style
- * @param {object} visibleLayerGroups - visible layers of bottom map
- * @returns {object} bottom map style
+ * @param {Object} mapStyle - preset map style
+ * @param {Object} visibleLayerGroups - visible layers of bottom map
+ * @returns {Object} bottom map style
*/
export const editBottomMapStyle = memoize(
({id, mapStyle, visibleLayerGroups}) => {
@@ -85,7 +89,6 @@ export const editBottomMapStyle = memoize(
invisibleFilters.every(match => !match(layer))
);
- // console.log(filteredLayers)
return {
...mapStyle.style,
layers: filteredLayers
@@ -94,10 +97,6 @@ export const editBottomMapStyle = memoize(
resolver
);
-const mapUrlRg = /^mapbox:\/\/styles\/[-a-z0-9]{2,256}\/[-a-z0-9]{2,256}/;
-const httpRg = /^(?=(http:|https:))/;
-const defaultMapboxApiUrl = 'https://api.mapbox.com';
-
// valid style url
// mapbox://styles/uberdata/cjfyl03kp1tul2smf5v2tbdd4
// lowercase letters, numbers and dashes only.
@@ -115,13 +114,43 @@ export function getStyleDownloadUrl(styleUrl, accessToken, mapboxApiUrl) {
const styleId = styleUrl.replace('mapbox://styles/', '');
// https://api.mapbox.com/styles/v1/heshan0131/cjg1bfumo1cwm2rlrjxkinfgw?pluginName=Keplergl&access_token=<token>
- return `${mapboxApiUrl || defaultMapboxApiUrl}/styles/v1/${styleId}?pluginName=Keplergl&access_token=${accessToken}`
+ return `${mapboxApiUrl || DEFAULT_MAPBOX_API_URL}/styles/v1/${styleId}?pluginName=Keplergl&access_token=${accessToken}`
}
// style url not recognized
return null;
}
+/**
+ * Generate static map image from style Url to be used as icon
+ * @param {Object} param
+ * @param {string} param.styleUrl
+ * @param {string} param.mapboxApiAccessToken
+ * @param {string} param.mapboxApiUrl
+ * @param {Object} param.mapState
+ * @param {numbers} param.mapW
+ * @param {numbers} param.mapH
+ */
+export function getStyleImageIcon({
+ styleUrl,
+ mapboxApiAccessToken,
+ mapboxApiUrl = DEFAULT_MAPBOX_API_URL,
+ mapState = {
+ longitude: -122.3391,
+ latitude: 37.7922,
+ zoom: 9
+ },
+ mapW = 400,
+ mapH = 300
+}) {
+ const styleId = styleUrl.replace('mapbox://styles/', '');
+
+ return `${mapboxApiUrl}/styles/v1/${styleId}/static/` +
+ `${mapState.longitude},${mapState.latitude},${mapState.zoom},0,0/` +
+ `${mapW}x${mapH}` +
+ `?access_token=${mapboxApiAccessToken}&logo=false&attribution=false`;
+}
+
export function scaleMapStyleByResolution(mapboxStyle, resolution) {
const labelLayerGroup = DEFAULT_LAYER_GROUPS.find(lg => lg.slug === 'label');
const {filter: labelLayerFilter} = labelLayerGroup;
@@ -167,9 +196,9 @@ export function scaleMapStyleByResolution(mapboxStyle, resolution) {
/**
* When switch to a new style, try to keep current layer group visibility
* by merging default and current
- * @param {object} defaultLayerGroup
- * @param {object} currentLayerGroup
- * @return {object} mergedLayerGroups
+ * @param {Object} defaultLayerGroup
+ * @param {Object} currentLayerGroup
+ * @return {Object} mergedLayerGroups
*/
export function mergeLayerGroupVisibility(defaultLayerGroup, currentLayerGroup) {
return Object.keys(currentLayerGroup)
diff --git a/test/browser/components/container-test.js b/test/browser/components/container-test.js
index d4f90d792..04e5b7256 100644
--- a/test/browser/components/container-test.js
+++ b/test/browser/components/container-test.js
@@ -32,6 +32,7 @@ import coreReducer from 'reducers/core';
import {keplerGlInit} from 'actions/actions';
import Container, {errorMsg} from 'components/container';
+import {DEFAULT_MAPBOX_API_URL} from 'constants/default-settings';
const initialCoreState = coreReducer(undefined, keplerGlInit());
const initialState = {
keplerGl: {}
@@ -191,7 +192,7 @@ test('Components -> Container -> Mount with mint:false', t => {
let actions = store.getActions();
- let expectedActions0 = {type: '@@kepler.gl/REGISTER_ENTRY', payload: {id: 'milkshake', mint: false, mapboxApiAccessToken: 'hello.world', mapboxApiUrl: undefined, mapStylesReplaceDefault: undefined}};
+ const expectedActions0 = {type: '@@kepler.gl/REGISTER_ENTRY', payload: {id: 'milkshake', mint: false, mapboxApiAccessToken: 'hello.world', mapboxApiUrl: undefined, mapStylesReplaceDefault: undefined}};
t.deepEqual(
actions,
@@ -209,7 +210,7 @@ test('Components -> Container -> Mount with mint:false', t => {
...initialCoreState.mapStyle,
// should replace access token
mapboxApiAccessToken: 'hello.world',
- mapboxApiUrl: undefined
+ mapboxApiUrl: DEFAULT_MAPBOX_API_URL
}
}
}
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index 2c465f797..f984eefb9 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -272,7 +272,6 @@ function mockStateWithCustomMapStyle() {
accessToken: 'secret_token',
isValid: true,
label: 'Smoothie the Cat',
- icon: 'data:image/png;base64,xyz',
style: {
version: 'v8',
id: 'smoothie_the_cat',
diff --git a/test/node/reducers/map-style-test.js b/test/node/reducers/map-style-test.js
index 766d97ea9..de2e2096a 100644
--- a/test/node/reducers/map-style-test.js
+++ b/test/node/reducers/map-style-test.js
@@ -22,10 +22,10 @@ import test from 'tape';
import {drainTasksForTesting, succeedTaskWithValues} from 'react-palm/tasks';
import reducer from 'reducers/map-style';
-import {INITIAL_MAP_STYLE, loadMapStylesUpdater} from 'reducers/map-style-updaters';
+import {INITIAL_MAP_STYLE, loadMapStylesUpdater, getInitialInputStyle} from 'reducers/map-style-updaters';
import {keplerGlInit, receiveMapConfig} from 'actions/actions';
import SchemaManager from 'schemas';
-import {DEFAULT_MAP_STYLES} from 'constants/default-settings';
+import {DEFAULT_MAP_STYLES, DEFAULT_MAPBOX_API_URL} from 'constants/default-settings';
// helpers
import {StateWCustomMapStyle} from 'test/helpers/mock-state';
@@ -50,7 +50,10 @@ test('#mapStyleReducer', t => {
test('#mapStyleReducer -> INIT', t => {
const newState = reducer(
InitialMapStyle,
- keplerGlInit({mapboxApiAccessToken: 'smoothies_secret_token'})
+ keplerGlInit({
+ mapboxApiAccessToken: 'smoothies_secret_token',
+ mapboxApiUrl: 'http://mydomain.com'
+ })
);
t.deepEqual(
@@ -59,7 +62,7 @@ test('#mapStyleReducer -> INIT', t => {
...INITIAL_MAP_STYLE,
initialState: {},
mapboxApiAccessToken: 'smoothies_secret_token',
- mapboxApiUrl: undefined
+ mapboxApiUrl: 'http://mydomain.com'
},
'initialize map style with mapboxApiAccessToken'
);
@@ -89,7 +92,7 @@ test('#mapStyleReducer -> INIT & LOAD_MAP_STYLES', t => {
mapStyles: {},
initialState: {},
mapboxApiAccessToken: 'smoothies_secret_token',
- mapboxApiUrl: undefined,
+ mapboxApiUrl: DEFAULT_MAPBOX_API_URL,
mapStylesReplaceDefault: true
},
'initialize map style with mapboxApiAccessToken and mapStylesReplaceDefault; mapStyles empty'
@@ -145,7 +148,7 @@ test('#mapStyleReducer -> RECEIVE_MAP_CONFIG', t => {
smoothie_the_cat: {
accessToken: 'secret_token',
custom: true,
- icon: 'data:image/png;base64,xyz',
+ icon: 'https://api.mapbox.com/styles/v1/shanhe/smoothie.the.cat/static/-122.3391,37.7922,9,0,0/400x300?access_token=secret_token&logo=false&attribution=false',
id: 'smoothie_the_cat',
label: 'Smoothie the Cat',
url: 'mapbox://styles/shanhe/smoothie.the.cat'
@@ -153,17 +156,9 @@ test('#mapStyleReducer -> RECEIVE_MAP_CONFIG', t => {
...defaultMapStyles
},
mapboxApiAccessToken: 'smoothies_secret_token',
- mapboxApiUrl: undefined,
+ mapboxApiUrl: DEFAULT_MAPBOX_API_URL,
mapStylesReplaceDefault: false,
- inputStyle: {
- accessToken: null,
- error: false,
- isValid: false,
- label: null,
- style: null,
- url: null,
- custom: true
- },
+ inputStyle: getInitialInputStyle(),
threeDBuildingColor: [1, 2, 3],
custom3DBuildingColor: true,
initialState: {}
@@ -206,7 +201,7 @@ test('#mapStyleReducer -> RECEIVE_MAP_CONFIG', t => {
smoothie_the_cat: {
accessToken: 'secret_token',
custom: true,
- icon: 'data:image/png;base64,xyz',
+ icon: 'https://api.mapbox.com/styles/v1/shanhe/smoothie.the.cat/static/-122.3391,37.7922,9,0,0/400x300?access_token=secret_token&logo=false&attribution=false',
id: 'smoothie_the_cat',
label: 'Smoothie the Cat',
url: 'mapbox://styles/shanhe/smoothie.the.cat',
@@ -222,17 +217,9 @@ test('#mapStyleReducer -> RECEIVE_MAP_CONFIG', t => {
topLayerGroups: {},
mapStyles: expectedMapStyles,
mapboxApiAccessToken: 'smoothies_secret_token',
- mapboxApiUrl: undefined,
+ mapboxApiUrl: DEFAULT_MAPBOX_API_URL,
mapStylesReplaceDefault: false,
- inputStyle: {
- accessToken: null,
- error: false,
- isValid: false,
- label: null,
- style: null,
- url: null,
- custom: true
- },
+ inputStyle: getInitialInputStyle(),
threeDBuildingColor: [1, 2, 3],
custom3DBuildingColor: true,
initialState: {},
diff --git a/test/node/schemas/map-style-schema-test.js b/test/node/schemas/map-style-schema-test.js
index 13408d178..a6e0c0757 100644
--- a/test/node/schemas/map-style-schema-test.js
+++ b/test/node/schemas/map-style-schema-test.js
@@ -76,7 +76,7 @@ test('#mapStyleSchema -> v1 -> save load mapStyle with custom style', t => {
id: 'smoothie_the_cat',
accessToken: 'secret_token',
label: 'Smoothie the Cat',
- icon: 'data:image/png;base64,xyz',
+ icon: 'https://api.mapbox.com/styles/v1/shanhe/smoothie.the.cat/static/-122.3391,37.7922,9,0,0/400x300?access_token=secret_token&logo=false&attribution=false',
custom: true,
url: 'mapbox://styles/shanhe/smoothie.the.cat'
}