Welcome
Last updated
Was this helpful?
Last updated
Was this helpful?
Kepler.gl is a data-agnostic, high-performance web-based application for visual exploration of large-scale geolocation data sets. Built on top of MapLibre GL and deck.gl, kepler.gl can render millions of points representing thousands of trips and perform spatial aggregations on the fly.
Kepler.gl is also a React component that uses Redux to manage its state and data flow. It can be embedded into other React-Redux applications and is highly customizable. For information on how to embed kepler.gl in your app take a look at this step-by-step tutorial on vis.academy.
Use Node 18.18.2 or above, older node versions have not been supported/ tested. For best results, use nvm nvm install
.
Kepler.gl consists of different modules. Each module can be added to the project like this:
kepler.gl is built upon mapbox. You will need a Mapbox Access Token to use it.
If you don't use a module bundler, it's also fine. Kepler.gl npm package includes precompiled production UMD builds in the umd folder. You can add the script tag to your html file as it follows (latest version of Kepler.gl):
or if you would like, you can load a specific version:
Take a look at the development guide to develop kepler.gl locally.
Here are the basic steps to import kepler.gl into your app. You also take a look at the examples folder. Each example in the folder can be installed and run locally.
Kepler.gl uses Redux to manage its internal state, along with react-palm middleware to handle side effects.
You need to add taskMiddleware
of react-palm
to your store too. We are actively working on a solution where react-palm
will not be required, however it is still a very lightweight side effects management tool that is easier to test than react-thunk.
Or if use enhancer:
If you mount kepler.gl reducer in another address instead of keplerGl
, or the kepler.gl reducer is not mounted at root of your state, you will need to specify the path to it when you mount the component with the getState
prop.
Read more about Reducers.
id
String
map
The unique identifier for the KeplerGl instance. Required when multiple KeplerGl instances exist. It maps to the state in the reducer (e.g. component with id foo
can be found instate.keplerGl.foo
).
mapboxApiAccessToken
String
undefined
getState
Function
state => state.keplerGl
Function that specifies the path to the root KeplerGl state in the reducer.
width
Number
800
The width of the KeplerGl UI in pixels.
height
Number
800
The height of the KeplerGl UI in pixels.
appName
String
Kepler.Gl
The app name displayed in the side panel header.
version
String
v1.0
The version displayed in the side panel header.
onSaveMap
Function
undefined
A function called when the "Save Map URL" in side panel header is clicked.
onViewStateChange
Function
undefined
Triggered when the map viewport is updated. Receives viewState
parameter with updated values like longitude, latitude, zoom, etc.
getMapboxRef(mapbox, index)
Function
undefined
Called when KeplerGl
adds or removes a MapContainer with an inner Mapbox map. mapbox
is a MapRef
when added, or null
when removed. index
is 0
for the first map and 1
for the second map in a split view.
actions
Object
{}
Custom action creators to override the default KeplerGl action creators. Only use custom action when you want to modify action payload.
mint
Boolean
true
Determines whether to load a fresh empty state when mounted. When false
, the state persists across remounts. Useful for modal use cases.
theme
Object/String
null
Set to "dark"
, "light"
, or "base"
, or pass a theme object to customize KeplerGl’s style.
mapboxApiUrl
String
https://api.mapbox.com
The Mapbox API URL if you are using a custom Mapbox tile server.
mapStylesReplaceDefault
Boolean
false
Set to true
to replace default map styles with custom ones. (see mapStyles
prop)
mapStyles
Array
[]
initialUiState
Object
undefined
The initial UI state applied to the uiState
reducer.
localeMessages
Object
undefined
Example Custom Map Style
You can supply additional map styles to be displayed in map style selection panel. By default, additional map styles will be added to default map styles. If you pass mapStylesReplaceDefault: true
, they will replace the default ones. kepler.gl will attempt to group layers of your style based on its id
naming convention and use it to allow toggle visibility of base map layers. Supply your own layerGroups
to override default for more accurate layer grouping.
Each mapStyles
should has the following properties:
id
(String, required) unique string that should not be one of these reserved dark
light
muted
. muted_night
label
(String, required) name to be displayed in map style selection panel
url
(String, required) mapbox style url or a url pointing to the map style json object written in Mapbox GL Style Spec.
icon
(String, optional) image icon of the style, it can be a url, or an image data url
layerGroups
(Array, optional)
keplerGl
reducer.One advantage of using the reducer over React component state to handle keplerGl state is the flexibility to customize its behavior. If you only have one KeplerGl
instance in your app or never intend to dispatch actions to KeplerGl from outside the component itself, you don’t need to worry about forwarding dispatch and can move on to the next section. But life is full of customizations, and we want to make yours as enjoyable as possible.
There are multiple ways to dispatch actions to a specific KeplerGl
instance.
In the root reducer, with reducer updaters.
Each action is mapped to a reducer updater in kepler.gl. You can import the reducer updater corresponding to a specific action, and call it with the previous state and action payload to get the updated state. e.g. updateVisDataUpdater
is the updater for ActionTypes.UPDATE_VIS_DATA
(take a look at each reducer reducers/vis-state.js
for action to updater mapping). Here is an example how you can listen to an app action QUERY_SUCCESS
and call updateVisDataUpdater
to load data into Kepler.Gl.
Read more about using updaters to modify kepler.gl state
Using redux connect
You can add a dispatch function to your component that dispatches actions to a specific keplerGl
component, using connect.
Wrap action payload
You can also simply wrap an action into a forward action with the wrapTo
helper
Read more about forward dispatching actions
Kepler.gl implements css styling using Styled-Components. By using said framework Kepler.gl offers the ability to customize its style/theme using the following approaches:
Passing a Theme prop
Styled-Components ThemeProvider
The available properties to customize are listed here theme.
Passing a Theme prop.
You can customize Kepler.gl theme by passing a theme props to Kepler.gl react component as it follows:
As you can see the customTheme object defines certain properties which will override Kepler.gl default style rules.
Styled-Components Theme Provider.
In order to customize Kepler.gl theme using ThemeProvider you can simply wrap Kepler.gl using ThemeProvider as it follows:
Everyone wants the flexibility to render custom kepler.gl components. Kepler.gl has a dependency injection system that allow you to inject components to KeplerGl replacing existing ones. All you need to do is to create a component factory for the one you want to replace, import the original component factory and call injectComponents
at the root component of your app where KeplerGl
is mounted. Take a look at examples/demo-app/src/app.js
and see how it renders a custom side panel header in kepler.gl
Using withState
helper to add reducer state and actions to customized component as additional props.
Read more about replacing UI component
To interact with a kepler.gl instance and add new data to it, you can dispatch the addDataToMap
action from anywhere inside your app. It adds a dataset or multiple datasets to a kepler.gl instance and updates the full configuration (mapState, mapStyle, visState).
Parameters
data
Object *required
options
Object
options.centerMap
boolean default: true
if centerMap
is set to true
kepler.gl will place the map view within the data points boundaries
options.readOnly
boolean default: false
if readOnly
is set to true
the left setting panel will be hidden
options.keepExistingConfig
boolean default: false
whether to keep exiting map config, including layers, filters and splitMaps.
config
Object this object will contain the full kepler.gl instance configuration {mapState, mapStyle, visState}
Kepler.gl provides an easy API KeplerGlSchema.getConfigToSave
to generate a json blob of the current kepler instance configuration.
Examples
Read more about addDataToMap and Saving and loading maps with schema manager.
API token for Mapbox, used for rendering base maps. Create a free token at .
An array of for the map style selection panel. Styles replace the default ones if mapStylesReplaceDefault
is true
.
Used to modify or add new translations. Read more about .