[GIS] Redraw info window after centering map on click (ESRI Javascript API)

arcgis-javascript-api

When I click on one of the features on my map the map gets re-centered using the following event handler:

var pointClick = projects.on("click", function(e){
    // Center map on selected feature
    map.centerAt(e.mapPoint);

    // A bunch of other stuff
});

Unfortunately the info window describing that point does not move to the new location unless the map gets redrawn (by moving to another zoom level, for example).

Is there a method to force the info window to refresh? The information in the info window reflects the point that was most recently clicked on, but the location of the info window does not change.

Screencast:
http://www.screencast.com/t/fo1Nec0CBzk6

I can provide the code if necessary.

Best Answer

The easiest solution is to use an infoTemplate with your graphics or feature layer.

When a graphic or feature layer has an info template, and it is clicked, the map's info window is opened with info from that point or feature. If you move to this approach, there's no need to manually call map.infoWindow.show() (which I'm guessing you're doing based on the screen cast).

If it is not possible to use an info template, you can manage the state and position of the popup manually. In your click handler, use:

map.infoWindow.hide();
map.infoWindow.setFeatures([<graphic that was clicked>]);
map.infoWindow.show(e.mapPoint);