AnsweredAssumed Answered

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

Question asked by akmanchianand on Jun 8, 2015
Latest reply on Jun 10, 2015 by junshan_liu-esristaff

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

 

 

Outcomes