How to access to the related layer with triggered action

747
2
Jump to solution
09-01-2021 12:07 PM
Amadeus111
Occasional Contributor II

I am trying to implement an action that zooms to layer's full entent. Is there a way to access the related layer?

I found some info: https://totalapis.github.io/api-reference/esri-widgets-LayerList-ListItem.html

but could not implement it. 

For instance, I am trying to access the layer shown with the arrow mark when actions (3 dots) triggered

OguzSariyildiz_0-1630524181350.png

 

 

 

 

let layerList = new LayerList({
            view: view,
            container:"sideDiv",
            listItemCreatedFunction: defineActions    
        });
        var item = event.item;
          
          item.actionsSections = [
            [
              {
                title: "Go to full extent",
                className: "esri-icon-zoom-out-fixed",
                id: "full-extent"
              },
            ],
          ];

view.when(function() {  

            layerList.on("trigger-action", function(event) {
            // The layer visible in the view at the time of the trigger.
            
            // Capture the action id.
            var id = event.action.id;
            activeLayer = layerList.layer //this does not work

            
            if (id === "full-extent") {
              // If the full-extent action is triggered then navigate
              // to the full extent of the visible layer.
              view.goTo(activeLayer.fullExtent); //this either
            } 
            });

 

 

 

Thanks

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

The LayerList doesn't have a layer property. You'll have to get the layer information from the event.

view.goTo(event.item.layer.fullExtent);

However, this will only work with single feature layers, not Group Layers, as in this sample

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

The LayerList doesn't have a layer property. You'll have to get the layer information from the event.

view.goTo(event.item.layer.fullExtent);

However, this will only work with single feature layers, not Group Layers, as in this sample

Amadeus111
Occasional Contributor II

Hi @KenBuja 

is it possible to access to attribute table with the event? Where can I get the properties of an event? I could not find any resource. 

I would like to implement an action that opening attribute table but can not do it 

alert(event.item.layer.isTable)

returns false

0 Kudos