Web AppBuilder for ArcGIS (Developer Edition)

LayerInfo class

The LayerInfo class uses the unified interface to access layers in the web map.

Caution:

The LayerInfo class is deprecated. Use the LayerNode class instead.

AMD Module Require

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

Properties

<String> id

The layer ID defined in the web map.

<esri/map> map

The current web map object.

<LayerInfo> parentLayerInfo

The parent LayerInfo of the current LayerInfo. The value is null if there is no parent LayerInfo.

<String> title

The title of the layer.

Methods

findLayerInfoById(layerId)

Recursively finds the LayerInfo in the subLayerInfos. Returns null if the LayerInfo cannot be found.

Return type: <LayerInfo>

Parameters:

<String> url—Required. The REST service URL.

<String> layerId—Required. The layer ID.

getExtent()

Gets the current extent of the layer in the map.

Return type: <Extent>

getLayerObject()

Gets the layer object defined in the map.

Return type: <Deferred>

getLayerType()

Gets the layer type.

Return type: <Deferred>

getOpacity()

Gets the opacity or transparency of the layer in the map.

Return type: <Number>

getSubLayers()

Gets an array including all subLayerInfos of the current layer. Returns [] if the layer has no sublayers.

Return type: Object[<LayerInfo> layerInfo, …]

getUrl()

Gets the layer URL. Returns null if the layer has no URL.

Return type: <String>

isLeaf()

Returns true if the layer is a leaf layer. Otherwise, returns false.

Return type: <Boolean>

isRootLayer()

Returns true if the layer is a root layer. Otherwise, returns false.

Return type: <Boolean>

setOpacity(opacity)

Sets layer opacity or transparency in the map.

Return type: <Number>

Parameters:

<Number> opacity—The value can be from 0 to 1, where 0 is 100 percent transparent and 1 has no transparency.

traversal(callback)

Traverses all the sublayers with Depth-First-Search.

Parameters:

<Function> callback (layerInfo)—Required. Called by each layer and sends LayerInfo as a parameter. The layer can be handled in the callback.

Callback parameters: <LayerInfo>

Callback return type: <Boolean>

Callback return value:

  • If true, it is interrupt traversal.
  • If false, it is continue traversal.

Example:

layerInfosObject.traversal(function(layerInfo) {
   console.log(layerInfo.title, layerInfo.id);
})