Layers in Angular Diagram Component

30 Aug 202524 minutes to read

Layers provide a powerful organizational system for managing diagram elements by grouping related shapes into named categories. This functionality enables developers to build complex diagrams with selective viewing, interaction control, and bulk property management across multiple elements simultaneously.

Core Layer Properties

In a diagram, Layers enable modification of properties for all shapes assigned to a specific layer. The primary configurable properties include:

  • Objects - Define which elements belong to the layer
  • Visible - Control layer visibility
  • Lock - Prevent interactions with layer elements
  • AddInfo - Store additional custom information

Objects

The layer’s objects property specifies which diagram elements belong to that layer. This property contains a collection of element IDs that defines the categories of nodes and connectors the layer encompasses.

Use case: Separate different types of diagram elements for independent management - for example, keeping background elements in one layer and interactive elements in another.

In the following example, basic shapes are categorized in layer 1, and flow shapes are categorized in layer 2:

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramModule,DiagramComponent,LayerModel,BasicShapeModel,FlowShapeModel } from '@syncfusion/ej2-angular-diagrams';


@Component({
imports: [
             DiagramModule
    ],
providers: [ ],
standalone: true,
    selector: "app-container",
    template: `
    <ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-nodes>
            <e-node id='node1' [width]=100 [height]=100 [offsetX]=100 [offsetY]=100 [shape]='shape1' >
                <e-node-annotations>
                    <e-node-annotation content="Basic Rectangle">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node2' [width]=100 [height]=100 [offsetX]=250 [offsetY]=100 [shape]='shape2'>
                <e-node-annotations>
                    <e-node-annotation content="Basic Ellipse">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node3' [width]=100 [height]=100 [offsetX]=400 [offsetY]=100 [shape]='shape3' >
                <e-node-annotations>
                    <e-node-annotation content="Basic RightTriangle">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node4' [width]=100 [height]=100 [offsetX]=550 [offsetY]=100 [shape]='shape4' >
                <e-node-annotations>
                    <e-node-annotation content="Basic Plus">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node5' [width]=100 [height]=100 [offsetX]=100 [offsetY]=300 [shape]='shape5' >
                <e-node-annotations>
                    <e-node-annotation content="Flow Terminator">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node6' [width]=100 [height]=100 [offsetX]=250 [offsetY]=300 [shape]='shape6' >
                <e-node-annotations>
                    <e-node-annotation content="Flow Process">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node7' [width]=100 [height]=100 [offsetX]=400 [offsetY]=300 [shape]='shape7' >
                <e-node-annotations>
                    <e-node-annotation content="Flow Decision">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node8' [width]=100 [height]=100 [offsetX]=550 [offsetY]=300 [shape]='shape8' >
                <e-node-annotations>
                    <e-node-annotation content="Flow Document">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node> 
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram?: DiagramComponent;
    public layers: LayerModel[] =[];

    ngOnInit(): void {
        this.layers = [
            {
                id: 'layer1',
                visible: true,
                //Layer 1 objects
                objects: ['node1','node2','node3','node4'],
                lock: false
            },
            {
                id: 'layer2',
                visible: true,
                //Layer 2 objects
                objects: ['node5','node6','node7','node8'],
                lock: false
            }
        ]
    }
    public shape1: BasicShapeModel = {
        type: 'Basic',
        shape: 'Rectangle',
    };
    public shape2: BasicShapeModel = {
        type: 'Basic',
        shape: 'Ellipse',
    };
    public shape3: BasicShapeModel = {
        type: 'Basic',
        shape: 'RightTriangle',
    };
    public shape4: BasicShapeModel = {
        type: 'Basic',
        shape: 'Plus',
    };
    public shape5: FlowShapeModel = {
        type: 'Flow',
        shape: 'Terminator',
    };
    public shape6: FlowShapeModel = {
        type: 'Flow',
        shape: 'Process',
    };
    public shape7: FlowShapeModel = {
        type: 'Flow',
        shape: 'Decision',
    };
    public shape8: FlowShapeModel = {
        type: 'Flow',
        shape: 'Document',
    };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Visible

The layer’s visible property controls the visibility of all elements assigned to the layer. This allows selective display of different diagram sections without removing elements permanently.

Use case: Create diagrams with multiple views where users can toggle between different information layers, such as showing only critical path items in a project diagram.

In the following example, the visibility of layer one is set to false. By default, the visible property of a layer is set to true:

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramModule,DiagramComponent,PointModel,LayerModel} from '@syncfusion/ej2-angular-diagrams';

@Component({
imports: [
             DiagramModule
    ],
providers: [ ],
standalone: true,
    selector: "app-container",
    template: `
    <ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-nodes>
            <e-node id='node1' [width]=100 [height]=100 [offsetX]=100 [offsetY]=100 >
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node2' [width]=100 [height]=100 [offsetX]=300 [offsetY]=100>
                <e-node-annotations>
                    <e-node-annotation content="Layer 2 object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-connectors>
                <e-connector id='connector' type='Straight' [sourcePoint]='sourcePoint' [targetPoint]='targetPoint'>
                <e-connector-annotations>
                    <e-connector-annotation content="Layer 2 object">
                    </e-connector-annotation>
                </e-connector-annotations>
                </e-connector>
            </e-connectors>
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram?: DiagramComponent;
    public layers: LayerModel[] =[];
    public sourcePoint?: PointModel;
    public targetPoint?: PointModel;

    ngOnInit(): void {
        this.sourcePoint = { x: 100, y: 300 };
        this.targetPoint = { x: 200, y: 400 };
        this.layers = [
            {
                id: 'layer1',
                //Layer 1 visibility set as false.
                visible: false,
                objects: ['node1']
            },
            {
                id: 'layer2',
                //Layer 1 visibility set as true.
                visible: true,
                objects: ['node2', 'connector'],
            },
        ]
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Lock

The layer’s lock property prevents or allows changes to element dimensions and positions. When a layer is locked, all interactions with objects in that layer are disabled, including selecting, dragging, rotating, and connecting operations.

Use case: Protect template elements or background graphics from accidental modification while allowing users to work with other diagram elements.

In the following example, the objects in layer one are locked. By default, the lock property of a layer is set to false:

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramModule,DiagramComponent,PointModel,LayerModel } from '@syncfusion/ej2-angular-diagrams';

@Component({
imports: [
             DiagramModule
    ],
providers: [ ],
standalone: true,
    selector: "app-container",
    template: `
    <ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-nodes>
            <e-node id='node1' [width]=100 [height]=100 [offsetX]=100 [offsetY]=100 >
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 object locked">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node2' [width]=100 [height]=100 [offsetX]=300 [offsetY]=100>
                <e-node-annotations>
                    <e-node-annotation content="Layer 2 object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-connectors>
                <e-connector id='connector' type='Straight' [sourcePoint]='sourcePoint' [targetPoint]='targetPoint'>
                <e-connector-annotations>
                    <e-connector-annotation content="Layer 2 object">
                    </e-connector-annotation>
                </e-connector-annotations>
                </e-connector>
            </e-connectors>
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram?: DiagramComponent;
    public layers: LayerModel[] =[];
    public sourcePoint?: PointModel;
    public targetPoint?: PointModel;

    ngOnInit(): void {
        this.sourcePoint = { x: 100, y: 300 };
        this.targetPoint = { x: 200, y: 400 };
        this.layers = [
            {
                id: 'layer1',
                visible: true,
                objects: ['node1'],
                //Locks the layer1 and prevents any interactions to the objects in layer1
                lock: true,
            },
            {
                id: 'layer2',
                visible: true,
                objects: ['node2', 'connector'],
                lock: false
            },
        ]
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

AddInfo

The addInfo property allows storage of additional custom information with layers. This can be useful for storing metadata, configuration settings, or application-specific data associated with the layer.

Use case: Store layer descriptions, creation timestamps, owner information, or custom application data for enhanced layer management.

The following code illustrates how to add additional information to layers:

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramComponent, Diagram, NodeModel, ConnectorModel, PointModel, LayerModel } from '@syncfusion/ej2-angular-diagrams';

@Component({
    selector: "app-container",
    template: `<ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-connectors>
            <e-connector id='connector' type='Straight' [sourcePoint]='sourcePoint' [targetPoint]='targetPoint'>
            </e-connector>
    </e-connectors>
    <e-nodes>
            <e-node id='node1' [offsetX]=150 [offsetY]=150></e-node>
            <e-node id='node2' [offsetX]=350 [offsetY]=350></e-node>
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram: DiagramComponent;
    public sourcePoint: PointModel;
    public targetPoint: PointModel;
    public layers: LayerModel[];
    public addInfo: Object = { Description: 'Layer1' };
    ngOnInit(): void {
        this.sourcePoint = { x: 100, y: 100 };
        this.targetPoint = { x: 200, y: 200 };
        this.layers = [{
            id: 'layer1',
            visible: true,
            objects: ['node1', 'connector'],
            lock: true,
            addInfo: this.addInfo

        },
        {
            id: 'layer2',
            visible: true,
            objects: ['node2'],
            lock: false
        }];
    }
}

Add Layer at Runtime

Layers can be added at runtime by using the addLayer public method.

The layer’s ID property defines the ID of the layer, which is used to find the layer at runtime and apply any customizations. You can also add new objects to the new layer using the addLayer method.

The following code illustrates how to add a layer.

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent,LayerModel } from '@syncfusion/ej2-angular-diagrams';

@Component({
imports: [
             DiagramModule
    ],
providers: [ ],
standalone: true,
    selector: "app-container",
    template: `
    <button (click)="addLayer()">addLayer</button>
    <ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-nodes>
            <e-node id='node1' [width]=100 [height]=100 [offsetX]=100 [offsetY]=100 >
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node2' [width]=100 [height]=100 [offsetX]=100 [offsetY]=300>
                <e-node-annotations>
                    <e-node-annotation content="Layer 2 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram?: DiagramComponent;
    public layers: LayerModel[] =[];
    ngOnInit(): void {
        this.layers = [
            {
                id: 'layer1',
                objects: ['node1']
            },
            {
                id: 'layers2',
                objects:['node2']
            }
        ]
    }

    /**
     * Add the layers to the existing diagram layer collection
     * newLayer - representing the layer to be added to the diagram.
     * layerObject -  An optional array of objects associated with the layer.
     */
    addLayer() {
        (this.diagram as any).addLayer({
            id: 'newlayer',
            visible: true,
            lock: false,
        }, [{
            type: 'Straight',
            sourceID: 'node1',
            targetID: 'node2',
            
        }]);
    }
   
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Remove Layer at Runtime

Layers can be removed at runtime by using the removeLayer public method.

To remove a layer, pass the ID of the layer you want to remove as a parameter to the removeLayer method.

The following code illustrates how to remove a layer.

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent,LayerModel } from '@syncfusion/ej2-angular-diagrams';

@Component({
imports: [
             DiagramModule
    ],
providers: [ ],
standalone: true,
    selector: "app-container",
    template: `
    <button (click)="removeLayer()">removeLayer</button>
    <ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-nodes>
            <e-node id='node1' [width]=100 [height]=100 [offsetX]=100 [offsetY]=100 >
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node2' [width]=100 [height]=100 [offsetX]=100 [offsetY]=300>
                <e-node-annotations>
                    <e-node-annotation content="Layer 2 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram?: DiagramComponent;
    public layers: LayerModel[] =[];

    ngOnInit(): void {
        this.layers = [
            {
                id: 'layer1',
                objects: ['node1']
            },
            {
                id: 'layer2',
                objects:['node2']
            },
        ]
    }

    /**
     * Remove the layer from the existing diagram layer collection
     * layerId - representing the id of the layer to be removed from the diagram.
     */
     removeLayer() {
        (this.diagram as any).removeLayer('layer1');
    }
    
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

MoveObjects

You can move objects from one layer to another dynamically using the moveObjects public method of the diagram control. This can be useful for managing complex diagrams with multiple layers where you need to update the categorization of elements based on user interaction or other dynamic conditions.

The following code illustrates how to move objects from one layer to another layer from the diagram.

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramModule,DiagramComponent, LayerModel } from '@syncfusion/ej2-angular-diagrams';

@Component({
imports: [
             DiagramModule
    ],
providers: [ ],
standalone: true,
    selector: "app-container",
    template: `
    <button (click)="moveObjects()">moveObjects</button>
    <ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-nodes>
            <e-node id='node1' [width]=100 [height]=100 [offsetX]=100 [offsetY]=100 >
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node2' [width]=100 [height]=100 [offsetX]=100 [offsetY]=300>
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node3' [width]=100 [height]=100 [offsetX]=300 [offsetY]=300>
                <e-node-annotations>
                    <e-node-annotation content="Layer 2 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram?: DiagramComponent;
    public layers: LayerModel[] =[];

    ngOnInit(): void {
        this.layers = [
            {
                id: 'layer1',
                objects: ['node1','node2']
            },
            {
                id: 'layers2',
                objects:['node3']
            },
        ]
    }

    /**
     * Move objects from one layer to another layer
     * Parameter 1 - An array of object IDs represented as strings to be moved
     * parameter 2 -  The ID of the target layer to which the objects should be moved.
     */
     moveObjects() {
        (this.diagram as any).moveObjects(['node1'], 'layer2');
        console.log(this.layers);
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Z-Index and Layer Ordering

The zIndex property of a layer defines its position in the stacking order within the diagram. Higher z-index values render above lower values, allowing control over which layers appear in front of others.

Bring layer forward

Move a layer forward in the stacking order using the bringLayerForward public method:

// Move the specified layer forward in the stacking order
this.diagram.bringLayerForward('layer1');

Send Layer Backward

Move a layer backward in the stacking order using the sendLayerBackward public method:

// Move the specified layer backward in the stacking order
this.diagram.sendLayerBackward('layer1');

The following code illustrates how to send the layer forward/backward to another layer.

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, LayerModel } from '@syncfusion/ej2-angular-diagrams';

@Component({
imports: [
             DiagramModule
    ],
providers: [ ],
standalone: true,
    selector: "app-container",
    template: `
    <button (click)="bringLayerForward()">bringLayerForward</button>
    <button (click)="sendLayerBackward()">sendLayerBackward</button>
    <ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-nodes>
            <e-node id='node1' [width]=100 [height]=100 [offsetX]=100 [offsetY]=100 >
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node2' [width]=100 [height]=100 [offsetX]=130 [offsetY]=130>
                <e-node-annotations>
                    <e-node-annotation content="Layer 2 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node3' [width]=100 [height]=100 [offsetX]=160 [offsetY]=160>
                <e-node-annotations>
                    <e-node-annotation content="Layer 3 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram?: DiagramComponent;
    public layers: LayerModel[] =[];
    ngOnInit(): void {
        this.layers = [
            {
                id: 'layer1',
                objects: ['node1']
            },
            {
                id: 'layers2',
                objects:['node2']
            },
            {
                id: 'layers3',
                objects:['node3']
            }
        ]
    }

    /**
     * Move the layer forward
     * Parameter 1 -A string representing the id of the layer to be moved forward.
     */
    bringLayerForward() {
        (this.diagram as any).bringLayerForward('layer1');
    }

    /**
     * Move the layer Backward
     * Parameter 1 - A string representing the id of the layer to be  moved backward.
     */
    sendLayerBackward() {
        (this.diagram as any).sendLayerBackward('layer1');
    }
    
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Layer and objects rendering order

The rendering of diagram elements with layer properties involves grouping them within a diagram_diagramLayer for basic shape nodes and diagram_nativeLayer_svg for SVG-native elements. Even if different types of nodes are added within the same layer, the rendering at the DOM level occurs in separate layers. Therefore, when executing layering commands like bringLayerForward and sendLayerBackward, the native SVG elements will always render above the basic shape elements.

The order of rendering is as follows: HTML shapes -> SVG shapes -> Path data shapes & Basic shapes.

Clone Layer

Layers can be cloned along with their objects using the cloneLayer public method. This creates an identical copy of the layer and all its assigned elements.

Use case: Create template layers or duplicate complex layer configurations for reuse in different diagram sections.

The following code illustrates how to clone a layer:

import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { DiagramModule , LayerModel, DiagramComponent } from '@syncfusion/ej2-angular-diagrams'

@Component({
imports: [
             DiagramModule
],
providers: [ ],
standalone: true,
    selector: "app-container",
    template: `
    <button (click)="clonelayer()">clonelayer</button>
    <ejs-diagram #diagram id="diagram" width="100%" height="580px" [layers]="layers">
    <e-nodes>
            <e-node id='node1' [width]=100 [height]=100 [offsetX]=100 [offsetY]=100 >
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node2' [width]=100 [height]=100 [offsetX]=160 [offsetY]=360>
                <e-node-annotations>
                    <e-node-annotation content="Layer 2 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
            <e-node id='node3' [width]=100 [height]=100 [offsetX]=300 [offsetY]=100>
                <e-node-annotations>
                    <e-node-annotation content="Layer 1 Object">
                    </e-node-annotation>
                </e-node-annotations>
            </e-node>
    </e-nodes>
    </ejs-diagram>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild("diagram")
    public diagram?: DiagramComponent;
    public layers: LayerModel[] =[];
    ngOnInit(): void {
        this.layers = [
            {
                id: 'layer1',
                objects: ['node1', 'node3']
            },
            {
                id: 'layers2',
                objects:['node2']
            }
        ]
    
    }
    /**
     * To Clone the layer
     * Parameter 1 - A string representing the name of the  layer to be cloned.
     */
    clonelayer() {
        (this.diagram as any).cloneLayer('layer1');
    }
    
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Active Layer

The active layer represents the layer with the highest z-index in a diagram. When objects are added at runtime, they are automatically assigned to the active layer. If no layers are explicitly defined, a default layer is created and set as the active layer. When multiple layers exist, the layer with the highest z-index becomes the active layer.

Use case: Ensure new elements are added to the appropriate layer in multi-layer diagrams, particularly in interactive editing scenarios.

Get active layer

Retrieve the current active layer of the diagram using the getActiveLayer public method:

// Gets the currently active layer
this.diagram.getActiveLayer();

Set active layer

Set any layer as the active layer using the setActiveLayer public method:

// Set the specified layer as active
// @param layerName defines the name of the layer to be set as active
this.diagram.setActiveLayer('layer2');