Canvas layer and root element

Hi,
I’m trying to use a specific layer to draw shapes by specifying a layer object when creating my root element :

const layerName = "my-layer";
var layer = this._canvas.getLayer(layerName) || this._canvas.createLayer(layerName);

var attrs = {
    type: 'root',
    layer: layerName
  };
  
var rootElement = this._elementFactory.createRoot(attrs);
this._canvas.setRootElement(rootElement);

The layer is created but the root element still uses a ‘root-3’ layer.
What is this ‘root-3’ layer ? Why does the root element not use the ‘base’ layer ? And how to set a specific layer for a root element ?
Thanks a lot :wink:

Creating a layer adds an SVG <g> element to the SVG. Setting the root element doesn’t care about layers but about planes which is a different concept.

Example

  • 1 collapsed sub-process (layer-base and layer-root-2 represent the 2 planes)
  • all other layers aren’t associated with planes (your my-layer will be one of those layers)

Planes are controlled indirectly by adding new root elements.

A plane will be associated with an automatically created layer.

Canvas#setRootElement will set the active root element by finding an existing one (and its associated plane and layer) or creating a new one (and its plane and layer).

Your my-layer will not be chosen as the layer for the new root element.

After Canvas#setRootElement you can use Canvas#getActiveLayer to get the layer that was created for your new root element.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.