map.infowindow.getselectedfeature() returning undefined and How to get the currently selected feature ?

855
2
Jump to solution
05-18-2017 07:17 AM
esriuser2
New Contributor II

When I select a geometry on map, the method map.infoWindow.getSelectedFeature() always returns "undefined". This behaviour is not working code below:

map = new Map("mapDiv", {});

map.infoWindow.on("selection-change", function ()

{ var graphic = map.infoWindow.getSelectedFeature(); // graphics is always "undefined" }

How to get the currently selected feature ?

Thank you!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

esri user,

  Because you are creating a new map and not trying to use the existing map you will never get a selection. You need to use the existing map object:

this.map.infoWindow.on("selection-change", function (){
    var graphic = this.map.infoWindow.getSelectedFeature(); // graphics is always "undefined"
}

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

esri user,

  Because you are creating a new map and not trying to use the existing map you will never get a selection. You need to use the existing map object:

this.map.infoWindow.on("selection-change", function (){
    var graphic = this.map.infoWindow.getSelectedFeature(); // graphics is always "undefined"
}
0 Kudos
KenBuja
MVP Esteemed Contributor

Do you need to use lang.hitch here?

this.map.infoWindow.on("selection-change", lang.hitch(this, function (){
    var graphic = this.map.infoWindow.getSelectedFeature(); // graphics is always "undefined"
}));
0 Kudos