Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
add map style modal to input custom mapbox style url
Shan Hecb6908c86d31
diff --git a/src/actions/map-style-actions.js b/src/actions/map-style-actions.jsindex 139e8d241..6fa4de1a9 100644--- a/src/actions/map-style-actions.js+++ b/src/actions/map-style-actions.js@@ -22,28 +22,40 @@ import {createAction} from 'redux-actions';import ActionTypes from 'constants/action-types';const {+ ADD_CUSTOM_MAP_STYLE,+ INPUT_MAP_STYLE,MAP_CONFIG_CHANGE,MAP_STYLE_CHANGE,LOAD_MAP_STYLES,- LOAD_MAP_STYLE_ERR+ LOAD_MAP_STYLE_ERR,+ LOAD_CUSTOM_MAP_STYLE} = ActionTypes;// second argument of createAction is expected to be payloadCreator or undefinedconst [+ addCustomMapStyle,+ inputMapStyle,mapConfigChange,loadMapStyles,loadMapStyleErr,- mapStyleChange+ mapStyleChange,+ loadCustomMapStyle] = [+ ADD_CUSTOM_MAP_STYLE,+ INPUT_MAP_STYLE,MAP_CONFIG_CHANGE,LOAD_MAP_STYLES,LOAD_MAP_STYLE_ERR,- MAP_STYLE_CHANGE+ MAP_STYLE_CHANGE,+ LOAD_CUSTOM_MAP_STYLE].map(a => createAction(a));export {+ addCustomMapStyle,+ inputMapStyle,mapConfigChange,mapStyleChange,loadMapStyles,- loadMapStyleErr+ loadMapStyleErr,+ loadCustomMapStyle};diff --git a/src/components/common/modal.js b/src/components/common/modal.jsindex 86fe73032..93672a619 100644--- a/src/components/common/modal.js+++ b/src/components/common/modal.js@@ -58,6 +58,7 @@ const defaultProps = {const ModalContentWrapper = styled.div`width: 60%;+ max-width: 960px;padding: 40px 96px;position: absolute;top: 92px;@@ -127,8 +128,8 @@ export const ModalFooter = ({cancelButton,confirmButton}) => {- const cancelButtonProps = {...defaultProps.cancelButton, cancelButton};- const confirmButtonProps = {...defaultProps.confirmButton, confirmButton};+ const cancelButtonProps = {...defaultProps.cancelButton, ...cancelButton};+ const confirmButtonProps = {...defaultProps.confirmButton, ...confirmButton};return (<StyledModalFooter className="modal--footer"><FooterActionWrapper>diff --git a/src/components/common/styled-components.js b/src/components/common/styled-components.jsindex eef49c7d6..5b9531e0f 100644--- a/src/components/common/styled-components.js+++ b/src/components/common/styled-components.js@@ -193,6 +193,8 @@ export const Button = styled.div.attrs({transition: ${props => props.theme.transition};vertical-align: middle;width: ${props => props.width || 'auto'};+ opacity: ${props => (props.disabled ? 0.4 : 1)};+ pointer-events: ${props => (props.disabled ? 'none' : 'all')};:hover,:focus,@@ -226,6 +228,10 @@ export const Input = styled.input`props.secondary ? props.theme.secondaryInput : props.theme.input};`;+export const InputLight = styled.input`+ ${props => props.theme.inputLT}+`;+export const InlineInput = Input.extend`${props => props.theme.inlineInput};`;@@ -305,3 +311,25 @@ export const Table = styled.table`}}`;++export const StyledModalContent = styled.div`+ background: ${props => props.theme.panelBackgroundLT};+ color: ${props => props.theme.textColorLT};+ display: flex;+ flex-direction: row;+ font-size: 10px;+ margin: 0 -96px;+ padding: 30px 96px;+ justify-content: space-between;+`;++/**+ * Newer versions of mapbox.gl display an error message banner on top of the map by default+ * which will cause the map to display points in the wrong locations+ * This workaround will hide the error banner.+ */+export const StyledMapContainer = styled.div`+ .mapboxgl-map .mapboxgl-missing-css {+ display: none;+ }+`;diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.jsindex 398c8f9aa..73a229d53 100644--- a/src/components/kepler-gl.js+++ b/src/components/kepler-gl.js@@ -127,35 +127,32 @@ function KeplerGlFactory(});}- _loadMapStyle() {+ _loadMapStyle = () => {[...this.props.mapStyles, ...Object.values(DEFAULT_MAP_STYLES)].forEach(style => {if (style.style) {- this.props.dispatch(- MapStyleActions.loadMapStyles({- [style.id]: style- })- );+ this.props.mapStyleActions.loadMapStyles({+ [style.id]: style+ })} else {this._requestMapStyle(style);}});- }+ };- _requestMapStyle(mapStyle) {+ _requestMapStyle = (mapStyle) => {const {url, id} = mapStyle;requestJson(url, (error, result) => {if (error) {Console.warn(`Error loading map style ${mapStyle.url}`);- }- this.props.dispatch(- MapStyleActions.loadMapStyles({+ } else {+ this.props.mapStyleActions.loadMapStyles({[id]: {...mapStyle, style: result}- })- );+ });+ }});- }+ };render() {const {@@ -292,10 +289,14 @@ function KeplerGlFactory(containerW={containerW}/><ModalWrapper+ mapStyle={mapStyle}visState={visState}+ mapState={mapState}uiState={uiState}+ mapboxApiAccessToken={mapboxApiAccessToken}visStateActions={visStateActions}uiStateActions={uiStateActions}+ mapStyleActions={mapStyleActions}rootNode={this.root}containerW={containerW}containerH={mapState.height}diff --git a/src/components/map-container.js b/src/components/map-container.jsindex 2ab2ffb37..a3a26e882 100644--- a/src/components/map-container.js+++ b/src/components/map-container.js@@ -20,7 +20,6 @@// librariesimport React, {Component} from 'react';-import styled from 'styled-components';import PropTypes from 'prop-types';import MapboxGLMap from 'react-map-gl';import DeckGL from 'deck.gl';@@ -29,6 +28,7 @@ import {GL} from 'luma.gl';// componentsimport MapPopoverFactory from 'components/map/map-popover';import MapControlFactory from 'components/map/map-control';+import {StyledMapContainer} from 'components/common/styled-components';// Overlay typeimport {generateMapboxLayers, updateMapboxLayers} from '../layers/mapbox-utils';@@ -46,17 +46,6 @@ const MAP_STYLE = {}};-/**- * Newer versions of mapbox.gl display an error message banner on top of the map by default- * which will cause the map to display points in the wrong locations- * This workaround will hide the error banner.- */-const StyledMapContainer = styled.div`- .mapboxgl-map .mapboxgl-missing-css {- display: none;- }-`;-const getGlConst = d => GL[d];const propTypes = {diff --git a/src/components/modal-container.js b/src/components/modal-container.jsindex cc634bc05..7c3a07235 100644--- a/src/components/modal-container.js+++ b/src/components/modal-container.js@@ -35,6 +35,7 @@ import DataTableModalFactory from './modals/data-table-modal';import LoadDataModalFactory from './modals/load-data-modal';import ExportImageModalFactory from './modals/export-image-modal';import ExportDataModalFactory from './modals/export-data-modal';+import AddMapStyleModalFactory from './modals/add-map-style-modal';import {ADD_DATA_ID,@@ -43,17 +44,22 @@ import {DELETE_DATA_ID,EXPORT_DATA_ID,EXPORT_DATA_TYPE,- EXPORT_IMAGE_ID+ EXPORT_IMAGE_ID,+ ADD_MAP_STYLE_ID} from 'constants/default-settings';const propTypes = {rootNode: PropTypes.object,containerW: PropTypes.number,containerH: PropTypes.number,+ mapboxApiAccessToken: PropTypes.string.isRequired,+ mapState: PropTypes.object.isRequired,+ mapStyle: PropTypes.object.isRequired,uiState: PropTypes.object.isRequired,visState: PropTypes.object.isRequired,visStateActions: PropTypes.object.isRequired,- uiStateActions: PropTypes.object.isRequired+ uiStateActions: PropTypes.object.isRequired,+ mapStyleActions: PropTypes.object.isRequired};const DataTableModalStyle = css`@@ -61,6 +67,7 @@ const DataTableModalStyle = css`width: 90%;top: 80px;padding: 32px 0 0 0;+ max-width: unset;`;const DeleteDatasetModalStyled = css`@@ -72,17 +79,14 @@ const LoadDataModalStyle = css`top: 60px;`;-const ExportModalStyle = css`- padding: 20px;-`;-ModalContainerFactory.deps = [DeleteDatasetModalFactory,IconInfoModalFactory,DataTableModalFactory,LoadDataModalFactory,ExportImageModalFactory,- ExportDataModalFactory+ ExportDataModalFactory,+ AddMapStyleModalFactory];export default function ModalContainerFactory(@@ -91,7 +95,8 @@ export default function ModalContainerFactory(DataTableModal,LoadDataModal,ExportImageModal,- ExportDataModal+ ExportDataModal,+ AddMapStyleModal) {class ModalWrapper extends Component {_closeModal = () => {@@ -103,6 +108,11 @@ export default function ModalContainerFactory(this._closeModal();};+ _onAddCustomMapStyle = () => {+ this.props.mapStyleActions.addCustomMapStyle();+ this._closeModal();+ };+_onFileUpload = blob => {this.props.visStateActions.loadFiles(blob);};@@ -117,7 +127,7 @@ export default function ModalContainerFactory(}this.props.uiStateActions.cleanupExportImage();this._closeModal();- }+ };_onExportData = () => {const {datasets} = this.props.visState;@@ -150,12 +160,13 @@ export default function ModalContainerFactory(break;}this._closeModal();- }+ };render() {const {containerW,containerH,+ mapStyle,uiState,visState,rootNode,@@ -243,12 +254,10 @@ export default function ModalContainerFactory(modalProps = {close: false,title: 'Export Image',- cssStyle: ExportModalStyle,footer: true,onCancel: this._closeModal,onConfirm: this._onExportImage,confirmButton: {- negative: true,large: true,children: 'Export'}@@ -272,18 +281,39 @@ export default function ModalContainerFactory(modalProps = {close: false,title: 'Export Data',- cssStyle: ExportModalStyle,footer: true,onCancel: this._closeModal,onConfirm: this._onExportData,confirmButton: {- negative: true,large: true,children: 'Export'}};break;+ case ADD_MAP_STYLE_ID:+ template = (+ <AddMapStyleModal+ mapboxApiAccessToken={this.props.mapboxApiAccessToken}+ mapState={this.props.mapState}+ inputStyle={mapStyle.inputStyle}+ inputMapStyle={this.props.mapStyleActions.inputMapStyle}+ loadCustomMapStyle={this.props.mapStyleActions.loadCustomMapStyle}+ />+ );+ modalProps = {+ close: false,+ title: 'Add Custom Mapbox Style',+ footer: true,+ onCancel: this._closeModal,+ onConfirm: this._onAddCustomMapStyle,+ confirmButton: {+ large: true,+ disabled: !mapStyle.inputStyle.style,+ children: 'Add Style'+ }+ };+ break;default:break;}diff --git a/src/components/modals/add-map-style-modal.js b/src/components/modals/add-map-style-modal.jsnew file mode 100644index 000000000..bad286a4b--- /dev/null+++ b/src/components/modals/add-map-style-modal.js@@ -0,0 +1,226 @@+// Copyright (c) 2018 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++import React, {Component} from 'react';+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';++const MapH = 190;+const MapW = 264;+const ErrorMsg = {+ styleError : 'Failed to load map style, make sure it is published'+};++const InstructionPanel = styled.div`+ display: flex;+ flex-direction: column;+ justify-content: space-around;+ font-size: 12px;+ .modal-section {+ margin-bottom: 32px;+ }+ .modal-section:first-child {+ margin-top: 24px;+ }++ .modal-section {+ .modal-section-title {+ font-weight: 500;+ }+ .modal-section-subtitle {+ color: ${props => props.theme.subtextColorLT};+ }++ input {+ margin-top: 8px;+ }+ }++ input {+ margin-right: 8px;+ }+`;++const PreviewMap = styled.div`+ align-items: center;+ display: flex;+ flex-direction: column;+ justify-content: center;+ margin-left: 116px;+ flex-shrink: 0;++ .preview-title {+ font-weight: 500;+ font-size: 10px;+ padding: 8px 0px;+ }++ .preview-title.error {+ color: ${props => props.theme.errorColor};+ }++ .preview-image {+ background: ${props => props.theme.modalImagePlaceHolder};+ border-radius: 4px;+ 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;+ left: 0;+ }++ .preview-image-spinner {+ position: absolute;+ left: calc(50% - 25px);+ top: calc(50% - 25px);+ }+`;++const InlineLink = styled.a`+ font-weight: 500;++ :hover {+ cursor: pointer;+ }+`;++class AddMapStyleModal extends Component {++ static propTypes = {+ mapState: PropTypes.object.isRequired,+ inputMapStyle: PropTypes.func.isRequired,+ loadCustomMapStyle: PropTypes.func.isRequired,+ inputStyle: PropTypes.object.isRequired+ };++ componentDidUpdate() {+ const map = this.mapRef && this.mapRef.getMap();+ if (map && this._map !== map) {+ this._map = map;++ map.on('style.load', () => {+ const style = map.getStyle();+ this.loadMapStyleJson(style);+ });++ map.on('render', () => {+ if (map.isStyleLoaded()) {+ this.loadMapStyleIcon();+ }+ });++ map.on('error', () => {+ this.loadMaoStyleError();+ })+ }+ }++ loadMapStyleJson = (style) => {+ this.props.loadCustomMapStyle({style, error: false});+ };++ loadMapStyleIcon = () => {+ const canvas = findDOMNode(this.mapRef).querySelector('.mapboxgl-canvas');+ const dataUri = canvas.toDataURL();+ this.props.loadCustomMapStyle({+ icon: dataUri+ });+ };++ loadMaoStyleError = () => {+ this.props.loadCustomMapStyle({error: true});+ };++ render() {+ const {inputStyle, mapState} = this.props;++ return (+ <div className="add-map-style-modal">+ <StyledModalContent>+ <InstructionPanel>+ <div className="modal-section">+ <div className="modal-section-title">1. Publish your style at mapbox</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.+ </div>+ </div>+ <div className="modal-section">+ <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>+ </div>+ <InputLight+ type="text"+ value={inputStyle.url || ''}+ onChange={({target: {value}}) => this.props.inputMapStyle({...inputStyle, url: value})}+ placeholder="e.g. mapbox://styles/uberdataviz/abcdefghijklmnopq"+ />+ </div>+ <div className="modal-section">+ <div className="modal-section-title">3. Name your style</div>+ <InputLight+ type="text"+ value={inputStyle.label || ''}+ onChange={({target: {value}}) => this.props.inputMapStyle({...inputStyle, label: value})}+ />+ </div>+ </InstructionPanel>+ <PreviewMap>+ <div className={classnames('preview-title', {error: inputStyle.error})}>+ {inputStyle.error ? ErrorMsg.styleError :+ (inputStyle.style && inputStyle.style.name) || ''}</div>+ <div className="preview-image">+ {!inputStyle.isValid ?+ <div className="preview-image-spinner"/> :+ <StyledMapContainer>+ <MapboxGLMap+ {...mapState}+ mapboxApiAccessToken={this.props.mapboxApiAccessToken}+ ref={el => {+ this.mapRef = el;+ }}+ preserveDrawingBuffer+ width={MapW}+ height={MapH}+ mapStyle={inputStyle.url}/>+ </StyledMapContainer>+ }+ </div>+ </PreviewMap>+ </StyledModalContent>+ </div>+ );+ }+}++const AddMapStyleModalFactory = () => AddMapStyleModal;+export default AddMapStyleModalFactory;diff --git a/src/components/modals/export-data-modal.js b/src/components/modals/export-data-modal.jsindex f9a52298d..162d10fee 100644--- a/src/components/modals/export-data-modal.js+++ b/src/components/modals/export-data-modal.js@@ -24,15 +24,7 @@ import styled from 'styled-components';import {EXPORT_DATA_TYPE_OPTIONS} from 'constants/default-settings';import {FileType} from 'components/common/icons';--const StyledExportDataModal = styled.div`- background: ${props => props.theme.panelBackgroundLT};- display: flex;- flex-direction: column;- font-size: 10px;- margin: 0 -20px;- padding: 30px 80px;-`;+import {StyledModalContent} from 'components/common/styled-components';const StyledExportDataSection = styled.div`display: flex;@@ -187,7 +179,7 @@ const ExportDataModal = ({onClose}) => (<div className="export-data-modal">- <StyledExportDataModal>+ <StyledModalContent><StyledExportDataSection><div className="description"><div className="title">@@ -249,7 +241,7 @@ const ExportDataModal = ({</StyledFilteredDataOption></div></StyledExportDataSection>- </StyledExportDataModal>+ </StyledModalContent></div>);diff --git a/src/components/modals/export-image-modal.js b/src/components/modals/export-image-modal.jsindex 9180e2bcb..1143f4b3f 100644--- a/src/components/modals/export-image-modal.js+++ b/src/components/modals/export-image-modal.js@@ -29,6 +29,7 @@ import {RESOLUTION_OPTIONS} from 'constants/default-settings';import LoadingSpinner from 'components/common/loading-spinner';+import {StyledModalContent} from 'components/common/styled-components';const ImageOptionList = styled.div`display: flex;@@ -108,15 +109,6 @@ const Button = styled.div`}`;-const StyledExportImageModal = styled.div`- background: ${props => props.theme.panelBackgroundLT};- display: flex;- flex-direction: row;- font-size: 10px;- margin: 0 -20px;- padding: 30px 80px;-`;-class ExportImageModal extends Component {static propTypes = {@@ -153,7 +145,7 @@ class ExportImageModal extends Component {return (<div className="export-image-modal">- <StyledExportImageModal>+ <StyledModalContent><ImageOptionList><div className="image-option-section"><div className="image-option-section-title">Ratio</div>@@ -199,9 +191,8 @@ class ExportImageModal extends Component {<img className="preview-image-placeholder" src={imageDataUri} />}</div>- <div className="instruction">Or drag and drop to export immediately</div></PreviewImageSection>- </StyledExportImageModal>+ </StyledModalContent></div>);}diff --git a/src/components/side-panel.js b/src/components/side-panel.jsindex f7d294808..11ed69da9 100644--- a/src/components/side-panel.js+++ b/src/components/side-panel.js@@ -32,6 +32,7 @@ import PanelToggle from './side-panel/panel-toggle';import {ADD_DATA_ID,+ ADD_MAP_STYLE_ID,DATA_TABLE_ID,EXPORT_IMAGE_ID,EXPORT_DATA_ID,@@ -94,6 +95,10 @@ export default function SidePanelFactory(PanelHeader) {this.props.uiStateActions.toggleModal(ADD_DATA_ID);};+ _showAddMapStyleModal = () => {+ this.props.uiStateActions.toggleModal(ADD_MAP_STYLE_ID);+ };+_removeDataset = key => {// this will show the modal dialog to confirm deletionthis.props.uiStateActions.openDeleteModal(key);@@ -152,9 +157,11 @@ export default function SidePanelFactory(PanelHeader) {};const mapManagerActions = {+ addMapStyleUrl: mapStyleActions.addMapStyleUrl,onConfigChange: mapStyleActions.mapConfigChange,onStyleChange: mapStyleActions.mapStyleChange,- onBuildingChange: mapStyleActions.mapBuildingChange+ onBuildingChange: mapStyleActions.mapBuildingChange,+ showAddMapStyleModal: this._showAddMapStyleModal};return (diff --git a/src/components/side-panel/map-manager.js b/src/components/side-panel/map-manager.jsindex 7f61ca0cb..c7c145cfb 100644--- a/src/components/side-panel/map-manager.js+++ b/src/components/side-panel/map-manager.js@@ -24,6 +24,7 @@ import classnames from 'classnames';import styled from 'styled-components';import {+ Button,PanelLabel,StyledPanelHeader,PanelHeaderTitle,@@ -33,8 +34,9 @@ import {PanelLabelWrapper,CenterFlexbox} from 'components/common/styled-components';+import PanelHeaderAction from 'components/side-panel/panel-header-action';-import {ArrowDown, EyeSeen, EyeUnseen, Upload} from 'components/common/icons';+import {Add, ArrowDown, EyeSeen, EyeUnseen, Upload} from 'components/common/icons';const StyledInteractionPanel = styled.div`padding-bottom: 12px;@@ -45,7 +47,7 @@ export default class MapManager extends Component {mapStyle: PropTypes.object.isRequired,onConfigChange: PropTypes.func.isRequired,onStyleChange: PropTypes.func.isRequired,- onBuildingChange: PropTypes.func.isRequired+ showAddMapStyleModal: PropTypes.func.isRequired};state = {@@ -87,6 +89,11 @@ export default class MapManager extends Component {onChange={this._updateConfig}/>) : null}+ <Button+ onClick={this.props.showAddMapStyleModal}+ secondary>+ <Add height="12px" />Add Map Style+ </Button></div></div>);diff --git a/src/constants/action-types.js b/src/constants/action-types.jsindex 39e096e88..c54761597 100644--- a/src/constants/action-types.js+++ b/src/constants/action-types.js@@ -65,6 +65,9 @@ const ActionTypes = keyMirror({MAP_STYLE_CHANGE: null,LOAD_MAP_STYLES: null,LOAD_MAP_STYLE_ERR: null,+ INPUT_MAP_STYLE: null,+ LOAD_CUSTOM_MAP_STYLE: null,+ ADD_CUSTOM_MAP_STYLE: null,// uiStateTOGGLE_SIDE_PANEL: null,diff --git a/src/constants/default-settings.js b/src/constants/default-settings.jsindex 8ef903e3d..ea06423ec 100644--- a/src/constants/default-settings.js+++ b/src/constants/default-settings.js@@ -35,6 +35,7 @@ export const DELETE_DATA_ID = 'deleteData';export const ADD_DATA_ID = 'addData';export const EXPORT_IMAGE_ID = 'exportImage';export const EXPORT_DATA_ID = 'exportData';+export const ADD_MAP_STYLE_ID = 'addMapStyle';import {Layers,diff --git a/src/reducers/map-style-updaters.js b/src/reducers/map-style-updaters.jsindex 5e5d7ca4d..323e4da78 100644--- a/src/reducers/map-style-updaters.js+++ b/src/reducers/map-style-updaters.js@@ -23,9 +23,12 @@ import Immutable from 'immutable';// Utilsimport {getDefaultLayerGroupVisibility,+ isValidStyleUrl,editTopMapStyle,editBottomMapStyle} from 'utils/map-style-utils/mapbox-gl-style-editor';+import {DEFAULT_LAYER_GROUPS} from 'constants/default-settings';+import {generateHashId} from 'utils/utils';/*** Create two map styles from preset map style, one for top map one for bottom@@ -133,3 +136,47 @@ export const receiveMapConfigUpdater = (state, action) =>action.payload.mapStyle? mapConfigChangeUpdater(state, {payload: action.payload.mapStyle}): state;++export const loadCustomMapStyleUpdater = (state, {payload: {icon, style, error}}) => ({+ ...state,+ inputStyle: {+ ...state.inputStyle,+ // style json and icon will load asynchronously+ ...(style ? {+ id: style.id || generateHashId(),+ style,+ label: style.name,+ layerGroups: DEFAULT_LAYER_GROUPS.filter(lg => style.layers.filter(lg.filter).length)+ } : {}),+ ...(icon ? {icon} : {}),+ ...(error !== undefined ? {error} : {})+ }+});++export const inputMapStyleUpdater = (state, {payload: inputStyle}) => ({+ ...state,+ inputStyle: {+ ...inputStyle,+ isValid: isValidStyleUrl(inputStyle.url)+ }+});++export const addCustomMapStyleUpdater = (state, action) => {+ const styleId = state.inputStyle.id;+ const newState = {+ ...state,+ mapStyles: {+ ...state.mapStyles,+ [styleId]: state.inputStyle+ },+ // set to default+ inputStyle: {+ url: null,+ isValid: false,+ label: null,+ style: null+ }+ };+ // set new style+ return mapStyleChangeUpdater(newState, {payload: styleId});+};diff --git a/src/reducers/map-style.js b/src/reducers/map-style.jsindex d61fa3bf2..5fed23f24 100644--- a/src/reducers/map-style.js+++ b/src/reducers/map-style.js@@ -24,11 +24,14 @@ import {handleActions} from 'redux-actions';import ActionTypes from 'constants/action-types';import {+ inputMapStyleUpdater,mapConfigChangeUpdater,mapStyleChangeUpdater,loadMapStylesUpdater,loadMapStyleErrUpdater,- receiveMapConfigUpdater+ receiveMapConfigUpdater,+ loadCustomMapStyleUpdater,+ addCustomMapStyleUpdater} from './map-style-updaters';// bedrock browserInit flattens our immutable object into a plain object@@ -42,18 +45,28 @@ const getDefaultState = () => {styleType,visibleLayerGroups,topLayerGroups,- mapStyles: {}+ mapStyles: {},++ inputStyle: {+ url: null,+ isValid: false,+ label: null,+ style: null+ }};};export const INITIAL_MAP_STYLE = getDefaultState();const actionHandler = {+ [ActionTypes.INPUT_MAP_STYLE]: inputMapStyleUpdater,[ActionTypes.MAP_CONFIG_CHANGE]: mapConfigChangeUpdater,[ActionTypes.MAP_STYLE_CHANGE]: mapStyleChangeUpdater,[ActionTypes.LOAD_MAP_STYLES]: loadMapStylesUpdater,[ActionTypes.LOAD_MAP_STYLE_ERR]: loadMapStyleErrUpdater,- [ActionTypes.RECEIVE_MAP_CONFIG]: receiveMapConfigUpdater+ [ActionTypes.RECEIVE_MAP_CONFIG]: receiveMapConfigUpdater,+ [ActionTypes.LOAD_CUSTOM_MAP_STYLE]: loadCustomMapStyleUpdater,+ [ActionTypes.ADD_CUSTOM_MAP_STYLE]: addCustomMapStyleUpdater};export const mapStyleReducerFactory = (initialState = {}) =>diff --git a/src/styles/base.js b/src/styles/base.jsindex 259a65ec5..3b4d831e6 100644--- a/src/styles/base.js+++ b/src/styles/base.js@@ -173,6 +173,7 @@ export const tooltipColor = '#333334';export const modalTitleColor = '#3A414C';export const modalTitleFontSize = '24px';export const modalFooterBgd = '#F8F8F9';+export const modalImagePlaceHolder = '#DDDFE3';// Modal Dialog (Dark)export const modalDialogBgd = '#3A414C';@@ -263,6 +264,43 @@ const input = css`}`;+const inputLT = css`+ ${input}++ background-color: ${props => props.theme.selectBackgroundLT};+ border: 1px solid+ ${props =>+ props.active+ ? props.theme.selectActiveBorderColor+ : props.error+ ? props.theme.errorColor+ : props.theme.selectBorderColorLT};+ color: ${props => props.theme.selectColorLT};+ caret-color: ${props => props.theme.selectColorLT};++ ::-webkit-input-placeholder {+ color: ${props => props.theme.subtextColorLT};+ font-weight: 400;+ }++ :active,+ :focus,+ &.focus,+ &.active {+ background-color: ${props => props.theme.selectBackgroundLT};+ border-color: ${props => props.theme.textColorLT};+ }++ :hover {+ background-color: ${props => props.theme.selectBackgroundLT};+ cursor: ${props => ['number', 'text'].includes(props.type) ? 'text' : 'pointer'};+ border-color: ${props =>+ props.active+ ? props.theme.textColorLT+ : props.theme.subtextColor};+ }+`;+const secondaryInput = css`${props => props.theme.input}color: ${props => props.theme.secondaryInputColor};@@ -324,29 +362,6 @@ const inlineInput = css`}`;-const inputLT = css`- ${input}- background-color: ${props => props.theme.selectBackgroundLT};- border: 1px solid- ${props =>- props.active- ? props.theme.selectActiveBorderColor- : props.error- ? props.theme.errorColor- : props.theme.selectBorderColorLT};- color: ${props => props.theme.selectColorLT};-- ::-webkit-input-placeholder {- color: ${props => props.theme.subtextColorLT};- font-weight: 400;- }-- :hover {- cursor: pointer;- background-color: ${props => props.theme.selectBackgroundHoverLT};- }-`;-const switchTrack = css`background: ${props =>props.checked@@ -620,6 +635,7 @@ export const theme = {...DIMENSIONS,// templatesinput,+ inputLT,inlineInput,chickletedInput,secondaryInput,@@ -744,6 +760,7 @@ export const theme = {modalTitleColor,modalTitleFontSize,modalFooterBgd,+ modalImagePlaceHolder,modalDialogBgd,modalDialogColor,diff --git a/src/utils/map-style-utils/mapbox-gl-style-editor.js b/src/utils/map-style-utils/mapbox-gl-style-editor.jsindex ca93e9b5c..c2e9efe4f 100644--- a/src/utils/map-style-utils/mapbox-gl-style-editor.js+++ b/src/utils/map-style-utils/mapbox-gl-style-editor.js@@ -87,3 +87,12 @@ export const editBottomMapStyle = memoize(},resolver);++const mapUrlRg = /^mapbox:\/\/styles\/[-a-z0-9]{2,256}\/[-a-z0-9]{2,256}/;++// valid style url+// mapbox://styles/uberdata/cjfyl03kp1tul2smf5v2tbdd4+// lowercase letters, numbers and dashes only.+export function isValidStyleUrl(url) {+ return typeof url === 'string' && Boolean(url.match(mapUrlRg));+}