LayerStructure class

The LayerStructure class reflects the structure of the operational layers in the current map. It is used to traverse and operate each layer and sublayer abstracted as a LayerNode in the LayerStructure.

AMD Module Require

require(["jimu/LayerStructure"], function(LayerStructure) { /* code goes here */ });

Constructor

There is a single instance of LayerStructure in the Web AppBuilder environment.

var layerStructureInstance = LayerStructure.getInstance();

Example:

Prints the tree structure of the operational layers in the current map in the console window.

var layerStructure = LayerStructure.getInstance();
        function printLayerTree() {
          layerStructure.traversal(function(layerNode) {
            var indent = "";
            for(var i = 0; i < layerNode.getNodeLevel(); i++) {indent += "  ";}
            console.log(indent, layerNode.title);
          });
        }

        printLayerTree();

        layerStructure.on(LayerStructure.EVENT_STRUCTURE_CHANGE, function(eventObject) {
          // reprint the layer tree if the layer structure has been changed;
          printLayerTree();
        });

Constants

STRUCTURE_CHANGE_ADD

Type of structure change event when layerNodes are added.

STRUCTURE_CHANGE_REMOVE

Type of structure change event when layerNodes are removed.

STRUCTURE_CHANGE_SUBNODE_ADD

Type of structure change event when subLayerNodes are added.

STRUCTURE_CHANGE_SUBNODE_REMOVE

Type of structure change event when subLayerNodes are removed.

STRUCTURE_CHANGE_NODE_UPDATE

Type of structure change event when layerNodes are updated.

STRUCTURE_CHANGE_REORDER

Type of structure change event when layerNodes are reordered.

EVENT_STRUCTURE_CHANGE

Event name for a structure change.

EVENT_TOGGLE_CHANGE

Event name for a toggle change.

EVENT_VISIBILITY_CHANGE

Event name for a visibility change.

EVENT_FILTER_CHANGE

Event name for a filter change.

EVENT_RENDERER_CHANGE

Event name for a renderer change.

EVENT_OPACITY_CHANGE

Event name for an opacity change.

Methods

addTable(table)

Adds a table to layerStructure.

Parameters:

table = {
      id: Optional parameters,
      title: title of new table,
      url: alternative with featureCollectionData,
      featureCollectionData: alternative with url,
      options: Optional parameters. See options list of FeatureLayer Constructor from
               ArcGIS JavaScript API reference.
  }

Return value: LayerNode

getBasemapLayerObjects()

Gets the layerObjects from the basemap.

Parameters: null

Return value: LayerObject[]

getLayerNodes()

Gets the operational layerNodes in the current map.

Parameters: null

Return value: LayerNode[]

getNodeById(nodeId)

Gets the layerNode or tableNode by ID.

Parameters: nodeId—layerNode or tableNode Id.

Return value: LayerNode

getTableNodes()

Gets the operational tableNodes in the current map.

Parameters: null

Return value: LayerNode[]

getWebmapLayerNodes()

Gets the operational layerNodes that are defined in the web map.

Parameters: null

Return value: LayerNode[]

getWebmapTableNodes()

Gets the operational tableNodes that are defined in the web map.

Parameters: null

Return value: LayerNode[]

removeTable(nodeId)

Removes a tableNode from layerStructure by the node ID.

Parameters: nodeId—The tableNode ID.

Return value: null

traversal: function(callback)

Traverses all nodes of the layerStructure with Depth-First-Search.

Parameters: callback: function(layerNode) {};

Callback parameters: layerNode

Callback return value: Boolean—Returns true when the traversal is interrupted; returns false when the traversal continues.

Return value: Boolean—Returns true when the traversal is interrupted; returns false when the traversal is complete.

traversalWithNodes: function(callback, nodes)

Traverses all nodes of nodes parameter with Depth-First-Search.

Parameters: callback: function(layerNode) {};

Callback parameters: layerNode

Callback return value: Boolean— Returns true when the traversal is interrupted; returns false when the traversal continues.

nodes—The layerNodes array

Return value: Boolean—Returns true when the traversal is interrupted; returns false when the traversal is complete.

Events

structure-change

Fires when the structure is changed.

Event object:

{
  type: String
  layerNodes: LayerNode[]
  rootLayerNodes: LayerNode[]
}

See also: EVENT_STRUCTURE_CHANGE in the Constants table.

toggle-change

Fires when the layerNodes toggle is changed.

Event object:

{
  layerNodes: LayerNode[]
}

See also: EVENT_TOGGLE_CHANGE in the Constants table

visibility-change

Fires when the visibility of layerNodes is changed.

Event object:

{
  layerNodes: LayerNode[]
}

See also: EVENT_TOGGLE_CHANGE in the Constants table.

filter-change

Fires when the layerNodes filter is changed.

Event object:

{
  layerNodes: LayerNode[]
}

See also: EVENT_FILTER_CHANGE in the Constants table.

renderer-change

Fires when the layerNodes renderer is changed.

Event object:

{
  layerNodes: LayerNode[]
}

See also: EVENT_RENDERER_CHANGE in the Constants table.

opacity-change

Fires when the layerNodes opacity is changed.

Event object:

{
  layerNodes: LayerNode[]
}

See also: EVENT_OPACITY_CHANGE in the Constants table.