Working with Layers
Add a Layer
Using addLayer(...)
function you can add a new layer to the map.
To learn about configuring a specific layer programmatically, visit the Layer Format Reference.
The dataset specified in dataId must be added to the map in advance. In this example we already added a dataset to the map.
addLayer(layer: LayerCreationProps): Layer;
/**
* A set of properties used to create a layer.
*/
type LayerCreationProps = Omit<
Optional<Layer, 'id' | 'dataId' | 'label' | 'isVisible'>,
'config'
> & {
config?: Partial<LayerConfig>;
};
/**
* Type encapsulating layer properties.
*/
type Layer = {
/** Unique identifier of the layer. */
id: string;
/** Type of the layer. */
type: LayerType | null;
/** Unique identifier of the dataset this layer visualizes. */
dataId: string | null;
/** Dictionary that maps fields that the layer requires for visualization to appropriate dataset fields. */
fields: Record<string, string | null>;
/** Canonical label of this layer. */
label: string;
/** Flag indicating whether layer is visible or not. */
isVisible: boolean;
/** Layer configuration specific to its type. */
config: LayerConfig;
};
/**
* Internal layer configuration.
*/
type LayerConfig = {
/** Dictionary of visualization properties that the layer supports. */
visualChannels: VisualChannels;
/** General layer settings. */
visConfig: Record<string, unknown>;
};
Parameters
Name Description id string
Unique identifier of the layer dataId string
Dataset id label string
(Optional)
Layer nameisVisible boolean
default: true
(Optional)
Iftrue
Studio will attempt to create layers automatically
Set Layer Visibility
While you can set the initial visibility when adding the layer, you can always toggle the visibility of the already added layers using the updateLayer(...)
function.
updateLayer(layerId: string, {isVisible: boolean}): void
Parameters
Name Description id string
Unique identifier of the layer isVisible boolean
Layer visibility
Get Available Layers
Gets all the layers currently available in the map.
getLayers(): Layer[];
Get Layer by id
Retrieves a layer by its identifier if it exists.
getLayerById(layerId: string): Layer | null;
Name Description layerId string
Unique identifier of the layer
Remove Layers
Using removeLayer(...)
function you can add a remove an existing layer from the map.
removeLayer(layerId: string): void
Parameters
Name Description id string
Unique identifier of the layer