0

When I select a geometry on map, the method map.infoWindow.getSelectedFeature() always returns "undefined". It looks like it is not working. This behavior is with InfoWindow and also with Popup. Also not working event map.infoWindow.on("selection-change",....

Code:

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

How to read currently selected feature?

1 Answer 1

0

The Popup is different than the infoWindow in its implementation.

The Popup class is an implementation of InfoWindow that inherits from InfoWindowBase to provide additional capabilities.

and

Popups provide the following additional capabilities:

  •Provides a user interface to navigate through multiple selections.
  •Zoom and highlight selected feature.
  •Maximize the info window.

The popup has events and methods that the infoWindow doesn't have, such as the "selection-change" and "getSelectedFeature". For example, in this sample, this code insertion returns the selected feature.

map.on("load", mapReady);

//new code
popup.on("selection-change", function(){
  var graphic = popup.getSelectedFeature();
  console.log(graphic);
});
//end of code

var parcelsURL = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer";

If you want to get the selected feature, why not listen to the map's click event or, if you're using a FeatureLayer, utilize its "selection-complete" event, which returns an array of graphics.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.