5

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)?

5

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

  • it works!!! thx u very much!!! – Dima Railguner Dec 5 '13 at 8:30
  • This excellent sample and explanation really needs to go into the official docs somewhere. It is perfectly illustrates a frequent use case. The setFeatures() method was the key that was not obvious (to me) from the docs. – LazerSharks Dec 12 '16 at 18:17
  • Only thing is that I wish they had callback functions for infoWindow.hide() and infoWindow.clearFeatures(); Currrently it seems the waiting caused by the callback of map.centerAt() is the only thing that prevents .hide() and clearFeatures() from completing out of turn after setFeatures() and .show() executes, undoing the setting and showing of the new popup. – LazerSharks Dec 12 '16 at 18:43

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.