Layers in the map are organized in a tree data structure. The root of this tree is the map’s layer tree. You can add either layers or layer groups to the layer tree.

A layer group (view/LayerGroup) can hold a collection of layers or other layer groups. In this way, it is possible to group layers in multiple levels.

Program: Organizing layers in a new LayerGroup and adding it to the map. (from samples/layercontrol/main.js)
var backgroundGroup = new LayerGroup({
  label: "Background"
var world = LayerConfigUtil.createWorldLayer();
backgroundGroup.addChild(world, "top");

LayerConfigUtil.createFusionBackgroundLayer().then(function(earth) {
  backgroundGroup.addChild(earth, "below", world);

map.layerTree.addChild(backgroundGroup, "bottom");

To inspect the structure of the tree, use the methods and properties of view/LayerTreeNode, which are implemented by all layers and layer groups. The children property returns a list of children of the node. The accept method allows you to traverse the tree using a view/LayerTreeVisitor.

Figure 1. Layers organized in multiple levels.