Extending LayerList widget

372
1
Jump to solution
10-09-2019 08:16 AM
LizEidsness
New Contributor III

Hi,

I'm trying to extent the LayerList widget as a means to reuse preferred settings/code between projects.  The trouble I'm having is in implementing the trigger-action handler.  I have ported the code from the sample.  It worked fine outside of my widget extension, so It's likely a matter of scope, but I can't figure out how to change it.

I'm writing my widget in TypeScript. 

In postInitialize, I'm setting up the list item actions, and they seem to work.  But on click, the event coming through to _triggerAction doesn't have event.item.  I noticed it is of type "click".  Might be a clue as to what is going on??

relevant bits:

postInitialize() {

    var defineActions = this._defineActions.bind(this);
    this.listItemCreatedFunction = defineActions;

    var triggerAction = this._triggerAction.bind(this)
    this.on("trigger-action", triggerAction);
}

private _triggerAction(event) {
    var layer = event.item.layer;
    var id = event.action.id;

    if (layer) {
        switch (id) {
            case "full-extent":
                this.view.goTo(layer.fullExtent);
                break;
            case "information":
                window.open(layer.url);
                break;
            case "increase-opacity":
                if (layer.opacity < 1) {
                    layer.opacity += 0.25;
                }
                break;
            case "decrease-opacity":
                if (layer.opacity > 0) {
                    layer.opacity -= 0.25;
                }
        }
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I'm using JS API 4.11.

Ideas?

Liz

0 Kudos
1 Solution

Accepted Solutions
LizEidsness
New Contributor III

I went looking in the LayerList widget's source code for clues, and figured it out.  I was using the same name for my trigger function as the method for raising the trigger.  

So changing _triggerAction to _myTriggerAction resolved the issue.

Leaving it here for anyone else.

View solution in original post

0 Kudos
1 Reply
LizEidsness
New Contributor III

I went looking in the LayerList widget's source code for clues, and figured it out.  I was using the same name for my trigger function as the method for raising the trigger.  

So changing _triggerAction to _myTriggerAction resolved the issue.

Leaving it here for anyone else.

0 Kudos