Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
Handle loading map style gracefully (#2005)
Igor Dykhta6692585e80a1
diff --git a/src/actions/src/map-style-actions.ts b/src/actions/src/map-style-actions.tsindex fac67198c..2970cac71 100644--- a/src/actions/src/map-style-actions.ts+++ b/src/actions/src/map-style-actions.ts@@ -26,7 +26,8 @@ import {Merge,RGBColor,MapState,- VisibleLayerGroups+ VisibleLayerGroups,+ LayerGroup} from '@kepler.gl/types';/**@@ -108,7 +109,7 @@ export type RequestMapStylesUpdaterAction = {label?: string;url: string;icon?: string;- layerGroups?: string;+ layerGroups?: LayerGroup[];};};};diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsxindex 74b420664..635ec910a 100644--- a/src/components/src/map-container.tsx+++ b/src/components/src/map-container.tsx@@ -51,6 +51,7 @@ import {observeDimensions,unobserveDimensions,hasMobileWidth,+ EMPTY_MAPBOX_STYLE,getMapLayersFromSplitMaps,onViewPortChange} from '@kepler.gl/utils';@@ -660,7 +661,7 @@ export default function MapContainerFactory(<MapComponentkey="bottom"{...mapProps}- mapStyle={mapStyle.bottomMapStyle}+ mapStyle={mapStyle.bottomMapStyle ?? EMPTY_MAPBOX_STYLE}{...bottomMapContainerProps}ref={this._setMapboxMap}getCursor={hoverInfo ? () => 'pointer' : undefined}@@ -691,10 +692,9 @@ export default function MapContainerFactory(}render() {- const {mapStyle} = this.props;return (<StyledMapContainer ref={this._ref} style={MAP_STYLE.container}>- {mapStyle.bottomMapStyle && this._renderMap()}+ {this._renderMap()}</StyledMapContainer>);}diff --git a/src/utils/src/index.ts b/src/utils/src/index.tsindex 247e157d9..cd2d2bda9 100644--- a/src/utils/src/index.ts+++ b/src/utils/src/index.ts@@ -113,7 +113,8 @@ export {getStyleDownloadUrl,getStyleImageIcon,scaleMapStyleByResolution,- mergeLayerGroupVisibility+ mergeLayerGroupVisibility,+ EMPTY_MAPBOX_STYLE} from './map-style-utils/mapbox-gl-style-editor';export {isValidMapInfo} from './map-info-utils';export {diff --git a/src/utils/src/map-style-utils/mapbox-gl-style-editor.ts b/src/utils/src/map-style-utils/mapbox-gl-style-editor.tsindex 48ee4c8ac..637b7e580 100644--- a/src/utils/src/map-style-utils/mapbox-gl-style-editor.ts+++ b/src/utils/src/map-style-utils/mapbox-gl-style-editor.ts@@ -26,6 +26,14 @@ import {BaseMapStyle, LayerGroup, MapState} from '@kepler.gl/types';const mapUrlRg = /^mapbox:\/\/styles\/[-a-z0-9]{2,256}\/[-a-z0-9]{2,256}/;const httpRg = /^(?=(http:|https:))/;+// Fallback style to use when styles are being fetched, or when+// a style fails to fetch+export const EMPTY_MAPBOX_STYLE = {+ version: 8,+ sources: {},+ layers: []+};+export function getDefaultLayerGroupVisibility({layerGroups = []}: {layerGroups: LayerGroup[]}) {return layerGroups.reduce((accu, layer) => ({