ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / MapFrame Class / SetCamera Method / SetCamera(Envelope) Method

In This Topic
    SetCamera(Envelope) Method
    In This Topic
    Sets the map frame extent using an envelope. This method must be called on the MCT. Use QueuedTask.Run.
    public void SetCamera( 
       Envelope extent
    Public Overloads Sub SetCamera( _
       ByVal extent As Envelope _


    This method or property must be called within the lambda passed to QueuedTask.Run.
    SetCamera will have no effect a map frame's extent being driven by a map series.
    //Set the extent of a map frame to the envelope of a feature.
    //Perform on the worker thread
    await QueuedTask.Run(() =>
      //Reference MapFrame
      MapFrame mf_env = layout.FindElement("Map Frame") as MapFrame;
      //Get map and a layer of interest
      Map m = mf_env.Map;
      //Get the specific layer you want from the map and its extent
      FeatureLayer lyr = m.FindLayers("GreatLakes").First() as FeatureLayer;
      Envelope lyrEnv = lyr.QueryExtent();
      //Set the map frame extent to the feature layer's extent / envelope
      mf_env.SetCamera(lyrEnv);  //Note - you could have also used the lyr as an overload option
    Change map frame extent to single feature with 15 percent buffer
    //Change map frame extent to single feature with 10 percent buffer
    //Process on the worker thread
    await QueuedTask.Run(() =>
      //Reference the mapframe and its associated map
      MapFrame mf = layout.FindElement("Map Frame") as MapFrame;
      Map m = mf.Map;
      //Reference a feature layer and build a query (to return a single feature)
      FeatureLayer fl = m.FindLayers("GreatLakes").First() as FeatureLayer;
      QueryFilter qf = new QueryFilter();
      string whereClause = "NAME = 'Lake Erie'";
      qf.WhereClause = whereClause;
      //Zoom to the feature
      using (ArcGIS.Core.Data.RowCursor rowCursor = fl.Search(qf))
        while (rowCursor.MoveNext())
          //Get the shape from the row and set extent
          using (var feature = rowCursor.Current as ArcGIS.Core.Data.Feature)
            Polygon polygon = feature.GetShape() as Polygon;
            Envelope env = polygon.Extent as Envelope;
            //Zoom out 15 percent
            Camera cam = mf.Camera;
            cam.Scale = cam.Scale * 1.15;

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also