Select to view content in your preferred language

Open a widget from another widget

2217
6
01-23-2011 07:37 AM
JohnGarvey
Deactivated User
I am trying to use widget containers and widgets for a dynamic legend. I have a data selection widget that allows the user to select data and I have a legend that catches the selection, queries the server, classifies the return information, and renders the graphics on the map.

I would like to piggyback on the widget and container functionality with the legend. Is there a way to send an open widget event from the selection widget?

-hope this is clear....
Tags (2)
0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus
John

   All you need to do is call a line like this:

ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, id));

Where "id" is the sequential numerical id number that is given to your widget when it is loaded. You can guess (trial and error) to find this number or you can add the code below to the ViewerContainer.mxml to find the id for you from the widgets label string.

                        //add this public var
   public var _configData:ConfigData;

                        //Add this line to the postConfigHandler function
    _configData = event.data as ConfigData;

                        //Add this new function
   public function getWidgetId(widgetLabel:String):Number
   {
    var id:Number;
    for (var i:Number = 0; i < _configData.widgets.length; i++)
    {
     if (_configData.widgets.label == widgetLabel)
      id = _configData.widgets.id;
    }
    return id;
   

If you choose to add this code then you would use this line instead to open your widget:

ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, ViewerContainer.getWidgetId("TheLabelOfYourWidget")));
0 Kudos
JohnGarvey
Deactivated User
Thanks for the response and code, I am glad to see other people working on Sunday.

Do you have any leads on passing data with that event. I am looking at the method that catches the event in the widget manager, but is seems I would have to edit the config data of the widget and then throwing the WIDGET_OPEN event.  

I appreciate any suggestions.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
John,

   Best advice I can give is don't be afraid to add your own custom AppEvent. Just make sure you comment you changes so that you can migrate them to the next version of the viewer (which 2.3 is right around the corner).
0 Kudos
MattiasEkström
Frequent Contributor
Hi,
I'm trying to use this code to open a widget from another, I've added the code to my ViewerContainer, but when I'm trying to access the ViewerContainer.getWidgetId function from another widget I get an error.
1061: Call to a possibly undefined method getWidgetId through a reference with static type Class.

What could I be doing wrong here, it is a public function and I have an import for com.esri.viewer.ViewerContainer in my widget but still I can't get to that function.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Mattias,

   Make sure you use getInstance on the ViewerContainer.

ViewerContainer.getInstance().getWidgetId("Enhanced Search");
0 Kudos
MattiasEkström
Frequent Contributor
Thanks Robert! That was it, I didn't see that part in any code in previous posts.
0 Kudos