map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
Thanks Alex, that actually saved me a lot of time. I adapted it to a function which measures how close a DOMElement is to the map extent boundaries:
getElementDistanceFromExtent: function(element) { if (!$ic.isNotNullObject(element)) return false; var posElementInfo = dojoDomGeometry.position(element); var maxPoint = new Point(this.map.extent.xmax, this.map.extent.ymax); var minPoint = new Point(this.map.extent.xmin, this.map.extent.ymin); var centerPoint = new Point(this.map.extent.getCenter()); var maxPointScreen = screenUtils.toScreenGeometry(this.map.extent, this.map.width, this.map.height, maxPoint); var minPointScreen = screenUtils.toScreenGeometry(this.map.extent, this.map.width, this.map.height, minPoint); var distXmax = maxPointScreen.x - (posElementInfo.x + posElementInfo.w); var distXmin = posElementInfo.x - minPointScreen.x; var distYmax = minPointScreen.y - (posElementInfo.y + posElementInfo.h); var distYmin = posElementInfo.y - maxPointScreen.y; return { distXmax: distXmax, distXmin: distXmin, distYmax: distYmax, distYmin: distYmin }; }
function showResults(idResults, evt) { for (var i = 0, il = idResults.length; i < il; i++) { var graphic = idResults; graphic.feature.setInfoTemplate(sustaintemplate); } map.infoWindow.setContent(updatePopup(graphic)); //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) - 470; var yDiff = Math.abs(maxPointScreen.y - evt.screenPoint.y) - 490; //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); }
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.