Skip to content

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

[feat] loading indicator improvements (#3097)

Igor Dykhta518c515d1667
diff --git a/src/components/src/loading-indicator.tsx b/src/components/src/loading-indicator.tsx
index 9b0027274..8629936cd 100644
--- a/src/components/src/loading-indicator.tsx
+++ b/src/components/src/loading-indicator.tsx
@@ -4,6 +4,8 @@
import React, {PropsWithChildren} from 'react';
import styled, {withTheme} from 'styled-components';
+import {getNumRasterTilesBeingLoaded} from '@kepler.gl/layers';
+
type StyledContainerProps = {
$isVisible?: boolean;
$left: number;
@@ -33,9 +35,8 @@ type LoadingIndicatorProps = {
/** Extra adjustment for the loading indicator when side panel is visible */
const LEFT_POSITION_ADJUSTMENT = 3;
-const LoadingIndicator: React.FC<PropsWithChildren<LoadingIndicatorProps> & {theme: any}> = ({
+const LoadingIndicator: React.FC<LoadingIndicatorProps & {theme: any}> = ({
isVisible,
- children,
activeSidePanel,
sidePanelWidth,
theme
@@ -44,9 +45,18 @@ const LoadingIndicator: React.FC<PropsWithChildren<LoadingIndicatorProps> & {the
(activeSidePanel ? (sidePanelWidth || 0) + LEFT_POSITION_ADJUSTMENT : 0) +
theme.sidePanel.margin.left;
+ // Helper message to track number of raster tiles that are being loaded
+ const numRasterTilesInProgress = getNumRasterTilesBeingLoaded();
+ const extraMessage =
+ numRasterTilesInProgress < 1
+ ? ''
+ : `${numRasterTilesInProgress} raster tile${
+ numRasterTilesInProgress === 1 ? ' is' : 's are'
+ } being loaded`;
+
return (
<StyledContainer $isVisible={isVisible} $left={left}>
- {children}
+ {`Loading... ${extraMessage}`}
</StyledContainer>
);
};
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index ab0d25c7d..d02441b26 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -31,8 +31,7 @@ import {
LayerBaseConfig,
VisualChannelDomain,
EditorLayerUtils,
- AggregatedBin,
- isRasterTilesBeingLoaded
+ AggregatedBin
} from '@kepler.gl/layers';
import {
DatasetAttribution,
@@ -83,6 +82,7 @@ import {LOCALE_CODES} from '@kepler.gl/localization';
import {MapView} from '@deck.gl/core';
import {
MapStyle,
+ areAnyDeckLayersLoading,
computeDeckLayers,
getLayerHoverProp,
LayerHoverProp,
@@ -100,6 +100,9 @@ import LoadingIndicator from './loading-indicator';
const DEBOUNCE_VIEWPORT_PROPAGATE = 10;
const DEBOUNCE_MOUSE_MOVE_PROPAGATE = 10;
+// How long should we wait between layer loading state changes before triggering a UI update
+const DEBOUNCE_LOADING_STATE_PROPAGATE = 100;
+
const MAP_STYLE: {[key: string]: React.CSSProperties} = {
container: {
display: 'inline-block',
@@ -366,6 +369,8 @@ export default function MapContainerFactory(
class MapContainer extends Component<MapContainerProps> {
displayName = 'MapContainer';
+ private anyActiveLayerLoading = false;
+
static contextType = MapViewStateContext;
declare context: React.ContextType<typeof MapViewStateContext>;
@@ -947,6 +952,12 @@ export default function MapContainerFactory(
if (typeof deckRenderCallbacks?.onDeckAfterRender === 'function') {
deckRenderCallbacks.onDeckAfterRender(allDeckGlProps);
}
+
+ const anyActiveLayerLoading = areAnyDeckLayersLoading(allDeckGlProps.layers);
+ if (anyActiveLayerLoading !== this.anyActiveLayerLoading) {
+ this._onLayerLoadingStateChange();
+ this.anyActiveLayerLoading = anyActiveLayerLoading;
+ }
}}
>
{children}
@@ -1002,6 +1013,11 @@ export default function MapContainerFactory(
this.props.visStateActions.onMouseMove(normalizeEvent(event, viewport));
}, DEBOUNCE_MOUSE_MOVE_PROPAGATE);
+ _onLayerLoadingStateChange = debounce(() => {
+ // trigger loading indicator update without any change to update UI
+ this.props.uiStateActions.setLoadingIndicator({change: 0});
+ }, DEBOUNCE_LOADING_STATE_PROPAGATE);
+
_toggleMapControl = panelId => {
const {index, uiStateActions} = this.props;
@@ -1158,12 +1174,10 @@ export default function MapContainerFactory(
{this._renderMapPopover()}
{primary !== isSplit ? (
<LoadingIndicator
- isVisible={isLoadingIndicatorVisible || isRasterTilesBeingLoaded()}
+ isVisible={Boolean(isLoadingIndicatorVisible || this.anyActiveLayerLoading)}
activeSidePanel={Boolean(activeSidePanel)}
sidePanelWidth={sidePanelWidth}
- >
- Loading...
- </LoadingIndicator>
+ />
) : null}
{this.props.primary ? (
<Attribution
diff --git a/src/layers/src/index.ts b/src/layers/src/index.ts
index b21f93d41..14e0473e9 100644
--- a/src/layers/src/index.ts
+++ b/src/layers/src/index.ts
@@ -49,7 +49,7 @@ import {default as RasterTileLayer} from './raster-tile/raster-tile-layer';
export {default as RasterTileIcon} from './raster-tile/raster-tile-icon';
export {
default as RasterTileLayer,
- isTilesBeingLoaded as isRasterTilesBeingLoaded
+ getNumRasterTilesBeingLoaded
} from './raster-tile/raster-tile-layer';
export {
CATEGORICAL_COLORMAP_ID,
diff --git a/src/layers/src/raster-tile/raster-tile-layer.ts b/src/layers/src/raster-tile/raster-tile-layer.ts
index 96e3d4c41..8cb41fc21 100644
--- a/src/layers/src/raster-tile/raster-tile-layer.ts
+++ b/src/layers/src/raster-tile/raster-tile-layer.ts
@@ -69,9 +69,9 @@ const devicePixelRatio: number = Math.min(
// Global counter that represents the number of tiles currently being loaded across all the raster tile layers
let tilesBeingLoaded = 0;
-// This is a temp solution, as we don't have proper logic to track loading of asycn layers atm in Kepler.gl
-export const isTilesBeingLoaded = () => {
- return tilesBeingLoaded > 0;
+// This is a temp solution to track loading
+export const getNumRasterTilesBeingLoaded = () => {
+ return tilesBeingLoaded;
};
export const LOAD_ELEVATION_AFTER_ZOOM = 8.9;
diff --git a/src/reducers/src/layer-utils.ts b/src/reducers/src/layer-utils.ts
index 36139c102..b9dd9268d 100644
--- a/src/reducers/src/layer-utils.ts
+++ b/src/reducers/src/layer-utils.ts
@@ -484,3 +484,11 @@ export function getLayerHoverPropValue(
if (data instanceof DataRow) return data.valueAt(fieldIndex);
return data[fieldIndex];
}
+
+/** Checks if any Deck layers are in the process of loading. */
+export function areAnyDeckLayersLoading(layers: DeckLayer[]): boolean {
+ return layers.some(
+ // layer.isLoaded changes frequently in Deck (even on hover) so we check additional properties
+ layer => layer.internalState && !layer.isLoaded
+ );
+}