ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapView Class / ZoomTo Method / ZoomTo(Geometry,Nullable<TimeSpan>,Boolean) Method
The geometry defining the extent in which to zoom.
The amount of time to navigate the view to the new camera position. If null it uses the default navigation duration.
Indicates if the Pitch and Heading should remain the same after the navigation is completed. If false the Heading will be set to 15.0 and the Pitch will be set to -60.0. This parameter only effects 3D views.
Example

In This Topic
    ZoomTo(Geometry,Nullable<TimeSpan>,Boolean) Method
    In This Topic
    Zoom the view to the extent defined by a geometry. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Function ZoomTo( _
       ByVal geometry As Geometry, _
       Optional ByVal duration As Nullable(Of TimeSpan), _
       Optional ByVal maintainViewDirection As Boolean _
    ) As Boolean

    Parameters

    geometry
    The geometry defining the extent in which to zoom.
    duration
    The amount of time to navigate the view to the new camera position. If null it uses the default navigation duration.
    maintainViewDirection
    Indicates if the Pitch and Heading should remain the same after the navigation is completed. If false the Heading will be set to 15.0 and the Pitch will be set to -60.0. This parameter only effects 3D views.

    Return Value

    True if the navigation is completed, false if it was interrupted by another view navigation.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    This is equivalent to setting the extent of the view. Use this method in combination with the Extent property to get and then modify the view's extent. If the geometry's spatial reference is in a different spatial reference than the map this method projects the geometry into the spatial reference of the map.
    Example
    Zoom to a specified point
    //Create a point
    var pt = MapPointBuilderEx.CreateMapPoint(x, y, 
                   SpatialReferenceBuilder.CreateSpatialReference(4326));
    //Buffer it - for purpose of zoom
    var poly = GeometryEngine.Instance.Buffer(pt, buffer_size);
    
    //do we need to project the buffer polygon?
    if (!MapView.Active.Map.SpatialReference.IsEqual(poly.SpatialReference))
    {
      //project the polygon
      poly = GeometryEngine.Instance.Project(poly, MapView.Active.Map.SpatialReference);
    }
    
    // Must run on MCT.
    QueuedTask.Run(() =>
    {
      //Zoom - add in a delay for animation effect
      MapView.Active.ZoomTo(poly, new TimeSpan(0, 0, 0, 3));
    });
    
    Zoom To a Point
    public Task<bool> ZoomToPoint(double x, double y, ArcGIS.Core.Geometry.SpatialReference spatialReference)
    {
      //Get the active map view.
      var mapView = MapView.Active;
      if (mapView == null)
        return Task.FromResult(false);
    
      return QueuedTask.Run(() =>
      {
        //Note: Run within QueuedTask
        //Create a point
        var pt = MapPointBuilderEx.CreateMapPoint(x, y, spatialReference);
        //Buffer it - for purpose of zoom
        var poly = GeometryEngine.Instance.Buffer(pt, buffer_size);
    
        //do we need to project the buffer polygon?
        if (!MapView.Active.Map.SpatialReference.IsEqual(poly.SpatialReference))
        {
          //project the polygon
          poly = GeometryEngine.Instance.Project(poly, MapView.Active.Map.SpatialReference);
        }
    
        //Zoom - add in a delay for animation effect
        return mapView.ZoomTo(poly, new TimeSpan(0, 0, 0, 3));
      });
    }
    
    Expand Extent
    public Task<bool> ExpandExtentAsync(double dx, double dy)
    {
      return QueuedTask.Run(() =>
      {
        //Get the active map view.
        var mapView = MapView.Active;
        if (mapView == null)
          return false;
    
        //Expand the current extent by the given ratio.
        var extent = mapView.Extent;
        var newExtent = ArcGIS.Core.Geometry.GeometryEngine.Instance.Expand(extent, dx, dy, true);
        return mapView.ZoomTo(newExtent);
      });
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also