Search code examples
pythonkepler.gl

Changing the default start location of a map in keper.gl


No matter where you data are located on the map, each time a kepler.gl map is visualised, the starting location is by default San Francisco.

For example:

import pandas as pd
from keplergl import KeplerGl

df = pd.read_csv("<dataset.csv>")
# df contains data in France
map_1 = KeplerGl(height=400, data={"data_1": df}, config=config)
map_1

map_1 will look like:

default location of the Kepler.gl map, regardless of the data location

Which means that you have to manually pan to where the uploaded data are in the map (to France in this case).

Is there a way to change the default starting point to where the data are located?


Solution

  • I found the solution shortly after posting the question: The initial coordinates can be embedded in the config dictionary:

    custom_config = {
      "version": "v1",
      "config": {
        "visState": {
          "filters": [],
          "layers": [],
          "interactionConfig": {}
        },
        "mapState": {
          "bearing": -4.928571428571431,
          "dragRotate": True,
          "latitude": 52.253971373306165,
          "longitude": -2.6899063817571394,
          "pitch": 49.18440507924836,
          "zoom": 6.655984704565685,
          "isSplit": False
        },
        "mapStyle": {
          "styleType": "muted_night",
          "topLayerGroups": {},
          "visibleLayerGroups": {
            "label": False,
            "road": False,
            "border": False,
            "building": False,
            "water": True,
            "land": True
          }
        }
      }
    }
    
    map_1 = KeplerGl(
        height=800,
        config=custom_config
    )
    map_1
    

    Note that if the config dictionary is defective, then the value will be set to the standard ones with no warnings raised.