This document is archived and information here might be outdated.  Recommended version.


Zoom by Ratio and Recenter Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Zoom by Ratio and Recenter Snippet

Zoom in ActiveView using a ratio of the current extent and re-center based upon supplied x,y map coordinates.

[C#]
///<summary>Zoom in ActiveView using a ratio of the current extent and re-center based upon supplied x,y map coordinates.</summary>
///
///<param name="activeView">An IActiveView interface.</param>
///<param name="zoomRatio">A System.Double that is the ratio to zoom in. Less that 1 zooms in (Example: .75), greater than 1 zooms out (Example: 2).</param>
///<param name="xMap">A System.Double that is the x portion of a point in map units to re-center on.</param>
///<param name="yMap">A System.Double that is the y portion of a point in map units to re-center on.</param>
/// 
///<remarks>Both the width and height ratio of the zoomed area is preserved.</remarks>
public void ZoomByRatioAndRecenter(ESRI.ArcGIS.Carto.IActiveView activeView, System.Double zoomRatio, System.Double xMap, System.Double yMap)
{
  if(activeView == null || zoomRatio < 0)
  {
    return;
  }
  ESRI.ArcGIS.Geometry.IEnvelope envelope=activeView.Extent;
  ESRI.ArcGIS.Geometry.IPoint point=new ESRI.ArcGIS.Geometry.PointClass();
  point.X=xMap;
  point.Y=yMap;
  envelope.CenterAt(point);
  envelope.Expand(zoomRatio, zoomRatio, true);
  activeView.Extent=envelope;
  activeView.Refresh();
}
[Visual Basic .NET]
'''<summary>Zoom in ActiveView using a ratio of the current extent and re-center based upon supplied x,y map coordinates.</summary>
'''
'''<param name="activeView">An IActiveView interface.</param>
'''<param name="zoomRatio">A System.Double that is the ratio to zoom in. Less that 1 zooms in (Example: .75), greater than 1 zooms out (Example: 2).</param>
'''<param name="xMap">A System.Double that is the x portion of a point in map units to re-center on.</param>
'''<param name="yMap">A System.Double that is the y portion of a point in map units to re-center on.</param>
''' 
'''<remarks>Both the width and height ratio of the zoomed area is preserved.</remarks>
Public Sub ZoomByRatioAndRecenter(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal zoomRatio As System.Double, ByVal xMap As System.Double, ByVal yMap As System.Double)

  If activeView Is Nothing OrElse zoomRatio < 0 Then
    Return
  End If

  Dim envelope As ESRI.ArcGIS.Geometry.IEnvelope=activeView.Extent
  Dim point As ESRI.ArcGIS.Geometry.IPoint=New ESRI.ArcGIS.Geometry.PointClass
  point.X=xMap
  point.Y=yMap
  envelope.CenterAt(point)
  envelope.Expand(zoomRatio, zoomRatio, True)

  activeView.Extent=envelope
  activeView.Refresh()

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Geometry
  • ESRI.ArcGIS.System