LayerListViewModel

AMD: require(["esri/widgets/LayerList/LayerListViewModel"], (LayerListVM) => { /* code goes here */ });
ESM: import LayerListViewModel from "@arcgis/core/widgets/LayerList/LayerListViewModel";
Class: esri/widgets/LayerList/LayerListViewModel
Inheritance: LayerListViewModel Accessor
Since: ArcGIS API for JavaScript 4.2

Provides the logic for the LayerList widget. To hide layers in the map from the LayerList widget, set the listMode property on the layer(s) to hide.

See also:

Constructors

new LayerListViewModel(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class
Stringmore details

The name of the class.

more detailsAccessor
ListItemCreatedHandlermore details

Specifies a function that accesses each ListItem.

more detailsLayerListViewModel
Collection<ListItem>more details

A collection of ListItems representing operational layers.

more detailsLayerListViewModel
Stringmore details

The view model's state.

more detailsLayerListViewModel
MapView|SceneViewmore details

The view from which the widget will operate.

more detailsLayerListViewModel

Property Details

declaredClass Stringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

listItemCreatedFunction ListItemCreatedHandler
Since: ArcGIS API for JavaScript 4.4

Specifies a function that accesses each ListItem. Each list item can be modified according to its modifiable propeties. Actions can be added to list items using the actionsSections property of the ListItem.

Example:
layerListViewModel.listItemCreatedFunction = function (event) {

   // The event object contains properties of the
   // layer in the LayerList widget.

   let item = event.item;

   if (item.title === "US Demographics") {
     // open the list item in the LayerList
     item.open = true;
     // change the title to something more descriptive
     item.title = "Population by county";
     // set an action for zooming to the full extent of the layer
     item.actionsSections = [[{
       title: "Go to full extent",
       className: "esri-icon-zoom-out-fixed",
       id: "full-extent"
     }]];
   }
});
operationalItems Collection<ListItem>readonly

A collection of ListItems representing operational layers. To hide layers from the LayerList widget, set the listMode property on the layer(s) to hide.

See also:
state Stringreadonly

The view model's state.

Possible Values:"loading"|"ready"|"disabled"

Default Value:disabled

The view from which the widget will operate.

Method Overview

Name Return Type Summary Class
more details

Moves a list item from one position to another in the LayerList widget.

more detailsLayerListViewModel
more details

Triggers the trigger-action event and executes the given action or action toggle.

more detailsLayerListViewModel

Method Details

moveListItem(targetItem, fromParentItem, toParentItem, newIndex)
Since: ArcGIS API for JavaScript 4.16

Moves a list item from one position to another in the LayerList widget. This allows the user to reorder the operational layers in a map or even reorganize sublayers of GroupLayers. You cannot move a GroupLayer as a sublayer to another GroupLayer. You also cannot move MapImageLayer sublayers outside of a MapImageLayer.

For the purposes of the documentation below, an item (or list item) refers to a layer in a map. A parent item refers to a GroupLayer or MapImageLayer, and a child item refers to a sublayer of a GroupLayer or MapImageLayer.

Parameters:
targetItem ListItem

The list item (or layer) to move.

fromParentItem ListItem

If the targetItem is a child of a parent list item and you want to move it out of the parentItem, then use this parameter to indicate the parent item to move from.

toParentItem ListItem

The parent list item to move the targetItem to if moving it as a child to another parent item.

newIndex Number

The new index to move the targetItem to. If moving the item as a child to a parent item, then specify the index of the item within that parent.

Examples:
// Moves the first layer to the final position in the map
const viewModel = layerList.viewModel;
const item = layerList.operationalItems.getItemAt(0);
const lastIndex = layerList.operationalItems.length - 1;

viewModel.moveListItem(item, null, null, lastIndex);
// Moves the first sublayer in the first group layer
// to the first position in the second group layer
const viewModel = layerList.viewModel;
const parentItem1 = layerList.operationalItems.getItemAt(0);
const subItem1 = parentItem1.children.getItemAt(0);
const parentItem2 = layerList.operationalItems.getItemAt(1);

viewModel.moveListItem(subItem1, parentItem1, parentItem2, 0);
triggerAction(action, item)

Triggers the trigger-action event and executes the given action or action toggle.

Parameters:

The action to execute.

item ListItem

An item associated with the action.

Event Overview

Name Type Summary Class
{action: ActionButton,ActionToggle,item: ListItem}
more details

Fires after the user clicks on an action or action toggle inside the LayerList widget.

more details LayerListViewModel

Event Details

trigger-action

Fires after the user clicks on an action or action toggle inside the LayerList widget. This event may be used to define a custom function to execute when particular actions are clicked.

Properties:

The action clicked by the user.

item ListItem

An item associated with the action.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.