ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / MapFrame Class / GetMapView Method
Example

GetMapView Method
Gets the map Frame's viewer on the specified layout pane.
Syntax
public MapView GetMapView( 
   LayoutView layoutView
)

Parameters

layoutView

Return Value

Returns a MapView.
Remarks
Note: the layout pane containing the viewer must be open. To navigate the map frame without an open layout pane, use the map frame's camera instead.
Example
Export the map view associated with a map frame to BMP
//Export the map view associated with a map frame to BMP.

//Create BMP format with appropriate settings
//EMF, EPS, GIF, JPEG, PDF, PNG, SVG, TGA, and TFF formats are also available for export
BMPFormat BMP = new BMPFormat()
{
  Resolution = 300,
  Height = 500,
  Width = 800,
  HasWorldFile = true,
  OutputFileName = filePath
};

//Reference the active layout view
LayoutView lytView = LayoutView.Active;

//Reference the map frame and its map view
MapFrame mf_bmp = layout.FindElement("Map Frame") as MapFrame;
MapView mv_bmp = mf_bmp.GetMapView(lytView);

if (mv_bmp != null)
{
  //Export on the worker thread
  await QueuedTask.Run(() =>
  {

    //Check to see if the path is valid and export
    if (BMP.ValidateOutputFilePath())
    {
      mv_bmp.Export(BMP);  //Export to BMP
    }
  });
}
SetAutoCameraFixedCenter
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.Center;

var camera = mf.GetMapView(LayoutView.Active).Camera;
var center = mf.GetViewCenter();

//var extent = EnvelopeBuilderEx.CreateEnvelope(
//    400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
//autoCamera.Extent = extent;

var camera2 = new CIMViewCamera()
{
  Heading = 0,
  Pitch = -90,
  Roll = 0,
  Scale = 21169571,
  X = 855708,
  Y = 1112409,
  Z = double.NaN
};
autoCamera.Camera = camera2;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraFixedCenterAndScale
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.CenterAndScale;

var camera = mf.GetMapView(LayoutView.Active).Camera;
var center = mf.GetViewCenter();

//var extent = EnvelopeBuilderEx.CreateEnvelope(
//    400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
//autoCamera.Extent = extent;

var camera2 = new CIMViewCamera()
{
  Heading = 0,
  Pitch = -90,
  Roll = 0,
  Scale = 21169571,
  X = 1310669.0 + ((400748.5 - 1310669.0) / 2.0),
  Y = 800296.4 + ((1424520.74 - 800296.4) / 2.0),
  Z = double.NaN
};
autoCamera.Camera = camera2;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
//autoCamera.IntersectLayerPath = states.URI;


if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraFixedScale
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.Scale;

var camera = mf.GetMapView(LayoutView.Active).Camera;
var center = mf.GetViewCenter();

//var extent = EnvelopeBuilderEx.CreateEnvelope(
//    400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
//autoCamera.Extent = extent;

var camera2 = new CIMViewCamera()
{
  Heading = 0,
  Pitch = -90,
  Roll = 0,
  Scale = 20000571,
  X = 1310669.0 + ((400748.5 - 1310669.0) / 2.0),
  Y = 800296.4 + ((1424520.74 - 800296.4) / 2.0),
  Z = double.NaN
};
autoCamera.Camera = camera2;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
//autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
Requirements

Target Platforms: Windows 11, Windows 10, Windows 8.1

ArcGIS Pro version: 2.3 or higher.
See Also