Whats the recommended way to communicate with built-in widgets e.g., Geocoder?

3445
7
Jump to solution
06-08-2015 06:12 AM
AnandAkmanchi
Occasional Contributor

We are trying to build a widget that needs an address location to start with and then it performs actions like display nearby features and do other business. We thought of adding an address search box to the widget, but feel this is unnecessary as AppBuilder already provides a Geocoder widget.

We see that the AppBuilder framework already provides a recommended way of communicating between widgets by publishing and subscribing to data. However, we see that the Geocoder widget does not broadcast or publish any data that other widgets can listen to, for e.g., messages like ‘no results found’, ‘list of results’, ‘selected candidate’ etc.

We are looking at other ways of tapping into the Geocoder widget's actions. One of the approach we are trying, is to use dojo's 'aspect.after' method which waits until specified function of target widget completes the execution(here target is Geocoder widget) and then executes the advisingFunction (in the custom widget).

For this to work, we need the instance of Geocoder widget, which we can get by

  • using 'this.widgetManager.getWidgetsByName("Geocoder")’ method, where ‘Geocoder’ is the widget's name
  • From the list of loaded widgets array, using the 'Geocoder' label

First question is, which is the correct way of accessing another widget?

Here is some pseudocode for what we are trying to do,

// get the instance of Geocoder widget in your custom widget
var geocoderWidget = this.widgetManager.getWidgetsByName("Geocoder"); 

// wait for Geocoder widget's 'showResults' method which is called when user selects an address from list of results to plot on map
aspect.after(geocoderWidget[0], "showResults", function (param) {
//write code here to read the location of user selected address and use it further for your business
}, true);

Our second question is that, is this a recommended way of hooking into another widget's actions and perform other stuff in your custom widget?

Any pointers from the community will be very helpful.

Thanks

Anand

1 Solution

Accepted Solutions
JunshanLiu
Occasional Contributor III

aspect.after is a good way if widget doesn't publish the data that your widget wants.

For your custom widget, I recommend to use this way:Communication between widgets—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers

And, we have a plan to review all released widgets and make all widgets publish necessary data. Any suggestion is very appreciated!

In future release, we plan to support another communication mode: workflow, this means we can put widgets together to complete one task, one widget's output will be passed into another widget as it's input depends on the workflow configuration. Also, any design suggestion is very welcomed!

View solution in original post

7 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Anand,

   Your code is the way I get references to widgets all the time. Your use of aspect after is the perfect solution to your issue. So I would say you are on the right track.

TimWitt2
MVP Regular Contributor

This is a great discussion, I was thinking about doing a similar thing, but had no idea on how to get started.

LarryStout
Occasional Contributor III

Anand,

Robert is absolutely correct.  I use this technique to modify the appearance/behavior of half a dozen of Esri's widgets without modifying their code.  I have also found that when Esri updates a widget, this technique is pretty easy to troubleshoot if the functionality ceases to work.

Larry

KisakyeM
New Contributor III

@LarryStout do you mind sharing some code on how you modify esri's widgets (inside a custom widget) without modifying their code?

0 Kudos
JunshanLiu
Occasional Contributor III

aspect.after is a good way if widget doesn't publish the data that your widget wants.

For your custom widget, I recommend to use this way:Communication between widgets—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers

And, we have a plan to review all released widgets and make all widgets publish necessary data. Any suggestion is very appreciated!

In future release, we plan to support another communication mode: workflow, this means we can put widgets together to complete one task, one widget's output will be passed into another widget as it's input depends on the workflow configuration. Also, any design suggestion is very welcomed!

KisakyeM
New Contributor III

@AnandAkmanchi  how did you locate the "showResults" method of the geocoder widget? I am attempting to do something similar to what you did but for the Filter widget. I cannot find anywhere that lists the methods of this widget. I am looking to extract the user selected value form the dropdown list and use it in a custom widget.

0 Kudos
Dr_Anand_Akmanchi
New Contributor

@KisakyeM sorry, I am unable to recollect as this was a few years ago.

0 Kudos