[GIS] How to open InfoTemplate programmatically

arcgis-javascript-apiarcgis-server

Could somebody help me?
How to open InfoTemplate programmatically???
Using of FeatureLayer.selectFeatures(…) not helps.
Here is example:
http://jsfiddle.net/gfV2K/
When I click on the map then single feature selected and InfoTemplate is opened.
But when I click some feature in the grid then single feature selected and InfoTemplate isn't opened!
So how to open InfoTemplate in this case? May be there is a way to simulate this behavior (for example by calling map.click() event)?

Best Answer

You can do this using setFeatures() and show() on the map's infoWindow (which by default is an instance of esri/dijit/Popup). You'll want to call clearFeatures() and hide() before calling setFeatures and show. I also recommend waiting until the map finishes navigating to the new center before calling setFeatures and show. This is easy since centerAt() returns a deferred so you can use its then() method to ensure the map is centered before you open the popup.

Here's how you would update the selectState function to do this:

// fires when a row in the dgrid is clicked
function selectState(e) {
  // select the feature
  var fl = map.getLayer("states");
  var query = new Query();
  query.objectIds = [parseInt(e.target.innerHTML)];
  fl.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result) {
    if ( result.length ) {
      var center = result[0].geometry.getExtent().getCenter();
      // close the map's popup and clear features
      window.map.infoWindow.hide();
      window.map.infoWindow.clearFeatures();

      // re-center the map to the selected feature
      // once that completes, show the popup anchored to the center of the new feature
      window.map.centerAt(center).then(function() {
        window.map.infoWindow.setFeatures([result[0]]);
        window.map.infoWindow.show(center);
      });
    } else {
      console.log("Feature Layer query returned no features... ", result);
    }
  });
}

Full working example: http://jsbin.com/UXaYidi/1/edit