//set a global fixed anchor for the infoWindow when the application loads (initEditing might be a good place) map.infoWindow.setFixedAnchor(esri.dijit.InfoWindow.ANCHOR_UPPERRIGHT); //afterwards wire up the event handling to make sure the map will pan if the entire infoWindow isn't going to fit on the screen dojo.connect(map.infoWindow, "onShow", function() { //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 - map.infoWindow.coords.x) - 435; var yDiff = Math.abs(maxPointScreen.y - map.infoWindow.coords.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); });
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.