private void ZoomToGraphic() { if (activeGraphic != null && activeGraphic.Geometry != null) { var graphicExtent = activeGraphic.Geometry.Extent; var mapExtent = MyMap.Extent; double mapExtentWidth = mapExtent.XMax - mapExtent.XMin; double mapExtentHeight = mapExtent.YMax - mapExtent.YMin; if (MyMap.Rotation != 0) { mapExtentHeight = mapExtent.XMax - mapExtent.XMin; mapExtentWidth = mapExtent.YMax - mapExtent.YMin; } //Just Center the map to your graphic MyMap.PanTo(graphicExtent.GetCenter()); //Zoom using factor. double xRatio = mapExtentWidth / graphicExtent.Width; double yRatio = mapExtentHeight /graphicExtent.Height; MyMap.Zoom(xRatio > yRatio ? yRatio : xRatio); } }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.