Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
import * as React from 'react';
import {useState, useEffect} from 'react';
import ReactDOM from 'react-dom/client';
import {Provider, useDispatch} from 'react-redux';
import {applyMiddleware, combineReducers, compose, createStore} from 'redux';
import 'maplibre-gl/dist/maplibre-gl.css';
import keplerGlReducer, {enhanceReduxMiddleware} from '@kepler.gl/reducers';
import KeplerGl from '@kepler.gl/components';
import {initApplicationConfig} from '@kepler.gl/utils';
// Annotations require a custom MapControl that mounts AnnotationManager.
// Charts are enabled by default but still need ChartControl + ChartManager injected
// (see demo-app) so stock MapControl never shows a dead charts button.
initApplicationConfig({
enableAnnotations: false
});
const reducers = combineReducers({
keplerGl: keplerGlReducer.initialState({
uiState: {
readOnly: false,
currentModal: null
}
})
});
const middleWares = enhanceReduxMiddleware([]);
const enhancers = applyMiddleware(...middleWares);
const store = createStore(reducers, {}, compose(enhancers));
function useWindowSize() {
const [size, setSize] = useState({width: window.innerWidth, height: window.innerHeight});
useEffect(() => {
const onResize = () => setSize({width: window.innerWidth, height: window.innerHeight});
window.addEventListener('resize', onResize);
return () => window.removeEventListener('resize', onResize);
}, []);
return size;
}
const App = () => {
const dispatch = useDispatch();
const {width, height} = useWindowSize();
return (
<KeplerGl
mapboxApiAccessToken="pk.xxx.yyy" // Replace with your mapbox token
id="map"
width={width}
height={height}
/>
);
};
const Root = () => (
<Provider store={store}>
<App />
</Provider>
);
const container = document.getElementById('root');
const root = ReactDOM.createRoot(container!);
root.render(<Root />);