How to tell if a particular widget is active?

2075
4
Jump to solution
09-21-2016 04:28 PM
StephenLead
Regular Contributor III

Is it possible to determine, from one widget, whether another widget is active?

For example, in my new widget's startup function, can I tell whether the Scalebar widget is active?

Inactive:

inactive

Active:

active

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Stephen,

You check for the "visible": false (inactive) property when looping through the appConfig.

var isActive = false;
array.some(this.appConfig.widgetOnScreen.widgets, function(wc){
    if(wc.name === 'Scalebar'){
        if(wc.visible){
            isActive = true;
        } 
        return true;
    }
});

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Stephen,

You check for the "visible": false (inactive) property when looping through the appConfig.

var isActive = false;
array.some(this.appConfig.widgetOnScreen.widgets, function(wc){
    if(wc.name === 'Scalebar'){
        if(wc.visible){
            isActive = true;
        } 
        return true;
    }
});
LefterisKoumis
Occasional Contributor III

Robert I am trying to use this script to check if a widget is open and it is then to close it. But I run into problems. The error is:

Uncaught TypeError: Cannot read property 'style' of null

I don't know why I get this since I trying to close the widget only if it is open. AM I missing something?

Also, the script check if it is visible. Is that means just visible on the screen or open?

Thank you.

 var isActive = false;
                array.some(this.appConfig.widgetOnScreen.widgets, function(wc){
                if(wc.name === 'BufferSelection'){
                if(wc.visible){
                    isActive = true;
                     WidgetManager.getInstance().closeWidget([0])
                    } 
                    return true;
                    }
                });‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  The issue I see in your code is this:

WidgetManager.getInstance().closeWidget([0])

It should be:

WidgetManager.getInstance().closeWidget(wc.id);
0 Kudos
LefterisKoumis
Occasional Contributor III

Thank you. Sometimes the answer is staring at you...

I got a bizarre behavior. Instead of closing the widget, it empties the content of all UI components!! ???

0 Kudos