Close widget panel on selection changed

281
8
Jump to solution
03-08-2018 08:58 AM
CharlesBailey3
Occasional Contributor

I am working with WAB 2.6 and want to close a widget panel when the selection in the map is changed. I can see the map.on("selection-change") code in some other question samples but don't see anything about it in the API 3.23 reference under map events. Can someone tell me the syntax for this function, where it goes and what needs to be defined in order to use the event handler? Thanks, cob

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Cob,

   Your code should be:

this.map.infoWindow.on("selection-change", lang.hitch(this, function() {
  PanelManager.getInstance().closePanel(this.id + '_panel');
}));‍‍‍

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Cob,

   What widget panel are you wanting to close? There is no selection-change on the map class. A FeatureLayer does have a selection-complete event though. So you have to attach to a specific layers selection-complete or selection-clear event.

0 Kudos
CharlesBailey3
Occasional Contributor

It's a custom in panel that displays the area and perimeter of the selected feature via a feature action. I want it to close whenever any other feature is selected in the map - and it also needs to work on layers added to the map from local sources - can I use lang.hitch(this or something to make it apply to any layer in the map? Thanks Robert - cob

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Cob,


  Is it the selection widget that is used to select the feature or are you just talking about selected it using a pop Up?

0 Kudos
CharlesBailey3
Occasional Contributor

Just the popup by clicking the feature on the map - are you thinking about the selection change on the popup class? Could something like this work?

map.infoWindow.on("selection-change", function() {Close the Panel}
0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Cob,


  Absolutely that is where I am going.

0 Kudos
CharlesBailey3
Occasional Contributor

OK I tried it in a test setting but it doesn't seem to recognize the event. This code is in the widget.js file (which may not be the right place) for the test widget infographic :I defined 'esri/dijit/Popup' and function Popup, and here is the code in the PostCreate function: 

this.inherited(arguments);
map.infoWindow.on("selection-change", function() {           console.log('foo');          PanelManager.getInstance().closePanel(this.id + '_panel');          });

It fails with no error, and is not firing the selection event at all (i.e. no 'foo' printed). I know the close panel routine works because I
had a click event in there before with the same code. I also tried this.map.infoWindow.on(...with the same results. Thoughts?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Cob,

   Your code should be:

this.map.infoWindow.on("selection-change", lang.hitch(this, function() {
  PanelManager.getInstance().closePanel(this.id + '_panel');
}));‍‍‍

View solution in original post

CharlesBailey3
Occasional Contributor

Outstanding as usual Robert, thanks!

0 Kudos