Layer Functions

The Map SDK provides a variety of layer functions, allowing you to add, remove, and configure the visibility of layers on your map.


Add Layer

Add a new layer to the map.

This function requires the user to supply at least one valid layer configuration object.

📝

Note:

For Typescript, we recommend using addLayerFromConfig().
For Python users, we recommend using add_layer_from_config() and specialized layer classes. See Python layer guide

map.addLayer({
  id: "test-layer-01",
  type: "point",
  dataId: "test-dataset-01",
  label: "New Layer",
  isVisible: true,
  fields: {
    lat: "latitude",
    lng: "longitude",
  },
  config: {
    visualChannels: {
      colorField: {
        name: "cityName",
        type: "string",
      },
      colorScale: "ordinal",
    },
  },
});
map.add_layer(
    LayerCreationProps(
        id="test-layer-01",
        type=LayerType.POINT
        data_id="test-dataset-01",
        label="New Layer",
        is_visible=True,
        fields={"lat": "latitude", "lng": "longitude"},
        config={
            "visual_channels": {
                "color_field": {"name": "city_name", "type": "string"},
                "color_scale":"ordinal",
            }
        },
    )
)

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
layerobjectAn object containing layer details.
layer.idstringUnique identifier of the layer.
layer.typestringType of the layer. See all available layers in the LayerType documentation.
layer.dataIdstringUnique identifier of the dataset this layer visualizes.
layer.fieldsRecord<string, string>Dictionary that maps fields that the layer requires for visualization to appropriate dataset fields.
layer.labelstringCanonic label of this layer.
layer.isVisiblebooleanFlag indicating whether layer is visible or not.
layer.configLayerConfigJSON layer configuration.

For more information, including full Python documentation, see addLayer() in the full API reference.


Add Layer From Config

Adds a layer using the specified config. Provides improved typing over addLayer(), and can work with JSON objects from the JSON editor for layers directly.

👍

Note:

Use addLayerFromConfig() over addLayer() when working with large, non-trivial layer configurations.
For more information, see the full Python layer guide.


Editing the layer configuration via the config editor.
map.addLayerFromConfig({
  type: 'point',
  config: {
    dataId: myDataset.id,
    columnMode: 'points',
    columns: {
      lat: 'lat',
      lng: 'lon'
    },
    visConfig: {},
    color: [0, 255, 0],
    textLabel: []
  }
});
# layer config as a dict
map.add_layer_from_config(
  {
    "id": "sample-layer",
    "type": "point",
    "config": {
      "dataId": "sample-data",
      "label": "Sample layer",
      "columnMode": "points",
      "columns": {"lat": "Latitude", "lng": "Longitude"},
      "visConfig": {},
      "color": [0, 255, 0],
      "textLabel": [],
    },
  }
)

# or layer config as a JSON string
map.add_layer_from_config("""
  {
    "id": "sample-layer",
    "type": "point",
    "config": {
      # ...
    },
  }
""")

By using JSON editor for layers, you can create and adjust your layer directly through the UI, and once you're satisfied, you can simply open the layer config editor and copy the JSON from it and paste it as a parameter into this SDK function.

# create a layer by using a JSON string straight from the JSON editor
map.add_layer_from_config("""
{
  "id": "sample-layer-json-str",
  "type": "point",
  "config": {
    "dataId": "sample-data",
    "label": "Sample layer str",
    # ...
    # ...
    "columnMode": "points",
    "columns": {
    "lat": "Latitude",
    "lng": "Longitude"
    }
  },
  "visualChannels": {
    "colorField": null,
    "colorScale": "quantile",
    "strokeColorField": null,
    "strokeColorScale": "quantile",
    "sizeField": null,
    "sizeScale": "linear"
  }
}
""")

This allows for some very ergonomic and fast workflows, where you can combine code and changes made in the UI to get to a desired state as fast as possible, without any guesswork either for how things might look like or what the parameters should be, and the full type safety guarantees this.

Arguments

Note: in both Javascript and Python version of this function, camelCase is being used.

ArgumentTypeDescription
layerConfigobjectA layer config.

For more information, including full Python documentation, see addLayerFromConfig() in the full API reference.


Add Layer Group

Add a new layer group to the map.

Layer groups do not impact the visualization itself, and instead serve as folders that organize layers within the sidebar. Assign layerIds to be a member of the layer group.

map.addLayerGroup({
  id: "layer-group-1",
  label: "Layer Group 1",
  isVisible: true,
  layerIds: ["layer1", "layer2", "layer3"],
});
map.add_layer_group(LayerGroupCreationProps(
    id="layer-group-1",
    label="Layer Group 1",
    is_visible=True,
    layer_ids=["layer1", "layer2", "layer3"]
))

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
layerGroupobjectAn object containing layer group options.
layerGroup.idstringUnique identifier of the layer group.
layerGroup.labelstringCanonical label of this group.
layerGroup.isVisiblebooleanFlag indicating whether layer group is visible or not.
layerGroup.layerIdsstring[]Layers referenced by layerId that are part of this group, sorted in the order in which they are shown.

For more information, including full Python documentation, see addLayerGroup() in the full API reference.


Get Layer by ID

Retrieve a Layer object by passing a valid layer layerId.

layer = map.getLayerById("test-layer-01");
layer = map.get_layer_by_id('test-layer-01')

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
layerIdstringUnique identifier of the layer.

For more information, including full Python documentation, see getLayerById() in the full API reference.


Get Layer Group by ID

Retrieve a LayerGroup object by passing a valid layer group LayerGroupId.

layerGroup = map.getLayerGroupById("layer-group-1");
layer_group = map.get_layer_group_by_id("layer-group-1")

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
layerGroupIdstringUnique identifier of the layer group.

For more information, including full Python documentation, see getLayerGroupById() in the full API reference.


Get Layer Groups

Retrieve all LayerGroups present on the map.

layerGroups = map.getLayerGroups();
layer_groups = map.get_layer_groups()

For more information, including full Python documentation, see getLayerGroups() in the full API reference.


Get Layers

Gets all the Layers currently available on the map.

layers = map.getLayers();
layers = map.get_layers()

For more information, including full Python documentation, see getLayers() in the full API reference.


Get Layer Timeline

Retrieve the LayerTimeline object associated with the map.

layerTimeline = map.getLayerTimeline();
layer_timeline = map.get_layer_timeline()

For more information, including full Python documentation, see getLayerTimeline() in the full API reference.


Remove Layer

Remove a layer from the map by passing a valid layerId.

map.removeLayer("test-layer-01");
map.remove_layer('test-layer-01')

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
layerIdstringUnique identifier of the layer to remove.

For more information, including full Python documentation, see removeLayer() in the full API reference.


Remove Layer Group

Remove a layer group by passing a valid layerGroupId.

map.removeLayerGroup("layer-group-1");
map.remove_layer_group("layer-group-1")

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
layerGroupIdstringUnique identifier of the layer group to remove.

For more information, including full Python documentation, see removeLayerGroup() in the full API reference.


Update Layer

Update an existing layer with the given values. Pass the layerId to target the layer you wish to update, then provide new Layer parameters in a values object.

map.updateLayer("test-layer-01", {
  type: "point",
  dataId: "test-dataset-01",
  label: "Updated Layer",
  isVisible: true,
  fields: {
    lat: "latitude",
    lng: "longitude",
    alt: "altitude",
  },
  config: {
    visualChannels: {
      colorField: {
        name: "cityName",
        type: "string",
      },
    },
    visConfig: {
      radius: 10,
      fixedRadius: false,
      opacity: 0.8,
      outline: false,
      thickness: 2,
    },
  },
});
map.update_layer('layer-id', LayerUpdateProps(
    label="My new label"
))

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
layerIdstringUnique identifier of the layer to update.
layerobjectAn object containing layer details.
layer.typestringType of the layer. See all available layers in the LayerType documentation.
layer.dataIdstringUnique identifier of the dataset this layer visualizes.
layer.fieldsRecord<string, string>Dictionary that maps fields that the layer requires for visualization to appropriate dataset fields.
layer.labelstringCanonic label of this layer.
layer.isVisiblebooleanFlag indicating whether layer is visible or not.
layer.configLayerConfigJSON layer configuration.

For more information, including full Python documentation, see updateLayer() in the full API reference.


Update Layer Group

Update an existing layer group with the given values. Pass the layerGroupId to target the layer you wish to update, then provide new LayerGroup parameters in a values object.

map.updateLayerGroup(
    "layer-group-1",
    {
      id: "layer-group-1",
      label: "Layer Group 1",
      isVisible: false,
      layerIds: ["layer1", "layer2". "layer3"]
    }
);
map.update_layer_group(LayerGroupUpdateProps(
    "layer-group-1",
    label = "New Layer Group 1",
    layers = ["layer1", "layer2"]
))

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
layerGroupIdstringUnique identifier of the layer group.
layerGroupobjectAn object containing layer group options.
layerGroup.labelstringCanonical label of this group.
layerGroup.isVisiblebooleanFlag indicating whether layer group is visible or not.
layerGroup.layerIdsstring[]Layers referenced by layerId that are part of this group, sorted in the order in which they are shown.

For more information, including full Python documentation, see updateLayerGroup() in the full API reference.


Update Layer Timeline

Updates the current layer timeline configuration. Pass LayerTimeline parameters in a values object.

map.updateLayerTimeline({
  currentTime: 1660637600498,
  isAnimating: true,
  isVisible: true,
  animationSpeed: 1,
  timeFormat: "YYYY-MM-DDTHH:mm:ss",
  timezone: "America/Los_Angeles",
});
map.update_layer_timeline(LayerTimelineUpdateProps(
    current_time=1660637600498,
    is_animating=True,
    is_visible=True,
    animation_speed=1,
    time_format="YYYY-MM-DDTHH:mm:ss",
    timezone="America/Los_Angeles"
))

Arguments

Note: Python Arguments require Python syntax and snake_case parameter names.

ArgumentTypeDescription
valuesobjectAn object containing layer timeline settings to pass as an update.
values.currentTimenumberCurrent time on the timeline in milliseconds.
values.domaintimeRangeRange of time that the timeline shows.
values.isAnimatingbooleanFlag indicating whether the timeline is animating or not.
values.isVisiblebooleanFlag indicating whether the timeline is visible or not.
values.animationSpeednumberSpeed at which timeline is animating.
values.timeFormatstringTime format that the timeline is using in day.js supported format.
values.timezonestringTimezone that the timeline is using in tz format.
values.timeStepsnumber[]Step duration for all the animation keyframes in milliseconds.

For more information, including full Python documentation, see updateLayerTimeline() in the full API reference.