Get Started
Last updated
Was this helpful?
Was this helpful?
import * as React from "react";
import ReactDOM from "react-dom/client";
import document from "global/document";
import { applyMiddleware, combineReducers, compose, createStore } from "redux";
import { connect, Provider } from "react-redux";
import keplerGlReducer, { enhanceReduxMiddleware } from "@kepler.gl/reducers";
import KeplerGl from "@kepler.gl/components";
import AutoSizer from "react-virtualized/dist/commonjs/AutoSizer";
const reducers = combineReducers({
keplerGl: keplerGlReducer.initialState({
uiState: {
readOnly: false,
currentModal: null,
},
}),
});
const middleWares = enhanceReduxMiddleware([
// Add other middlewares here
]);
const enhancers = applyMiddleware(...middleWares);
const initialState = {};
const store = createStore(reducers, initialState, compose(enhancers));
const App = () => (
<div
style={{
position: "absolute",
top: "0px",
left: "0px",
width: "100%",
height: "100%",
}}
>
<AutoSizer>
{({ height, width }) => (
<KeplerGl
mapboxApiAccessToken="xxx" // Replace with your mapbox token
id="map"
width={width}
height={height}
/>
)}
</AutoSizer>
</div>
);
const mapStateToProps = (state) => state;
const dispatchToProps = (dispatch) => ({ dispatch });
const ConnectedApp = connect(mapStateToProps, dispatchToProps)(App);
const Root = () => (
<Provider store={store}>
<ConnectedApp />
</Provider>
);
export default Root;import keplerGlReducer from '@kepler.gl/reducers';
import {createStore, combineReducers, applyMiddleware} from 'redux';
import {taskMiddleware} from 'react-palm/tasks';
const reducer = combineReducers({
// <-- mount kepler.gl reducer in your app
keplerGl: keplerGlReducer,
// Your other reducers here
app: appReducer
});
// create store
const store = createStore(reducer, {}, applyMiddleware(taskMiddleware));import KeplerGl from '@kepler.gl/components';
const Map = props => (
<KeplerGl
id="foo"
mapboxApiAccessToken={token}
width={width}
height={height}/>
);import {addDataToMap} from '@kepler.gl/actions';
this.props.dispatch(
addDataToMap({
// datasets
datasets: {
info: {
label: 'Sample Taxi Trips in New York City',
id: 'test_trip_data'
},
data: sampleTripData
},
// option
option: {
centerMap: true,
readOnly: false
},
// config
config: {
mapStyle: {styleType: 'light'}
}
})
);