Your code contains: map.infoWindow.resize(415,230);
map.infoWindow.show(evt.screenPoint, esri.dijit.InfoWindow.ANCHOR_UPPERRIGHT);
so it looks like you always want to show the infoWindow to the upper-right of the evt.screenPoint (the location the user clicks) and have it appear at this fixed size. You can use this logic to calculate whether the infoWindow will fit at a given point: function executeIdentifyTask(evt) {
map.graphics.clear();
//Set the infoWindow to open at the top right of the point at all times
map.infoWindow.setFixedAnchor(esri.dijit.InfoWindow.ANCHOR_UPPERRIGHT);
//Determine the upper right, and center, coordinates of the map
var maxPoint = new esri.geometry.Point(map.extent.xmax, map.extent.ymax)
var centerPoint = new esri.geometry.Point(map.extent.getCenter());
//Convert these to screen coordinates
var maxPointScreen = map.toScreen(maxPoint);
var centerPointScreen = map.toScreen(centerPoint);
//Subtract the size of the infoWindow, including a buffer.
//This will show whether the infoWindow would spill out of the current view.
var xDiff = Math.abs(maxPointScreen.x - evt.screenPoint.x) - 435;
var yDiff = Math.abs(maxPointScreen.y - evt.screenPoint.y) - 285;
//If required, recalculate a new centerpoint which accounts for the infoWindow
if (xDiff < 0) {centerPointScreen.x -= xDiff;}
if (yDiff < 0) {centerPointScreen.y += yDiff;}
//Pan the map to the new centerpoint (in Map coordinates)
centerPoint = map.toMap(centerPointScreen);
map.centerAt(centerPoint);
//Display the infoWindow at the original point clicked
map.infoWindow.show(evt.screenPoint, esri.dijit.InfoWindow.ANCHOR_UPPERRIGHT); Steve Just wanted to say thanks to Steve for this code, which works perfectly and saved me a ton of time. +100 Internets for you! I'm migrating my application from the Google Maps extension for the JSAPI to v2.7 of the ESRI Javascript API (no google maps). My infowindows contain a large amount of information and were previously designed with the assumption that the anchor would be fixed and the map would automatically pan so that the whole infowindow would be visible. This is the default behavior of an infowindow in the google API. When I migrated the app, I was finding that in certain situations, the infowindow would display partially outside the map bounds and the user would have to manually pan to see the whole thing. I was getting hung up on trying to programatically figure out the top corner of the infowindow and then do some math to figure out if it falls outside the map bounds, but Steve's solution avoids that whole issue by using the constants. Very nice! Just tweak the constants for your particular situation.
... View more