How to programmatically rotate map in a map frame on layout?

533
2
Jump to solution
06-21-2022 07:13 AM
GISTaldor
New Contributor II

Hi.

I'm trying to make a rotated map ona layout - i.e. not rotate the map frame itself, but rather the map inside it (since I want it to be on a "landscape" page and some of my data extents are "thin" and long).

I figured out how this can be achieved manually (either by choosing Properties of this map in "Contents" view):

 

GISTaldor_0-1655820255986.png

or Map Frame properties on the layout:

 

GISTaldor_1-1655820358804.png

Both settings are actually the same one (at least it seems so) and when one is changed, another is also updated automatically.

Here's an example of a map rotated 90 degrees, so that its corresponding north arrow points to the left edge of the layout.

GISTaldor_2-1655820751775.png

 

 

Now, my question is: how can I do this programmatically. I couldn't find any property/method for that.

If I use this - the map frame itself (i.e. the layout element) is rotated, which isn't what I want.

And I need the map frame to remain as it is and the map inside it to rotate.

 

Thanks.

 

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

This will get a lot easier at 3.0 (which will be released on Thurs). Display constraints, at 3.0 can be set using a "GetAutoCamera()/SetAutoCamera(autoCamera)" method pair. Display constraints will be explained here: https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Layouts#map-frame-display-constraints 

This link will be broken until Thursday because it has not been released yet.

In the interim, u can use this code. Be advised that not all map frames can be rotated, especially if the map frame is linked or is a map series frame. Generally speaking, if the current display constraint is any of these then it should be fine. I did add a some defensive code to check for the most obvious conditions (such as 3D).

 

display_constraint.png

internal class RotateTheMap : Button {

  private static double _angle = 0;

  protected override void OnClick() {

   if (LayoutView.Active == null)
    return;

   var layout = LayoutView.Active.Layout;
   var mapFrame = layout.Elements.OfType<MapFrame>().FirstOrDefault();
   if (mapFrame == null)
    return;

   QueuedTask.Run(() => {

    var def = mapFrame.GetDefinition() as CIMMapFrame;
    if (def.View.ViewingMode != MapViewingMode.Map)
     return; //2D only

    _angle -= 15;//Counter-clockwise
    if (_angle < -345) _angle = 0;

    var autoCamera = def.AutoCamera;
    if (autoCamera == null)
    {
     //unusual
     def.AutoCamera = new CIMAutoCamera()
     {
      Camera = new CIMViewCamera(),
      AutoCameraType = AutoCameraType.Extent
     };
    }
    else if (autoCamera.Source != AutoCameraSource.None &&
        autoCamera.Source != AutoCameraSource.Fixed)
    {
     return;
    }

    def.View.Camera.Heading = _angle;
    mapFrame.SetDefinition(def);
   });
  }
 }

 

 

View solution in original post

0 Kudos
2 Replies
CharlesMacleod
Esri Regular Contributor

This will get a lot easier at 3.0 (which will be released on Thurs). Display constraints, at 3.0 can be set using a "GetAutoCamera()/SetAutoCamera(autoCamera)" method pair. Display constraints will be explained here: https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Layouts#map-frame-display-constraints 

This link will be broken until Thursday because it has not been released yet.

In the interim, u can use this code. Be advised that not all map frames can be rotated, especially if the map frame is linked or is a map series frame. Generally speaking, if the current display constraint is any of these then it should be fine. I did add a some defensive code to check for the most obvious conditions (such as 3D).

 

display_constraint.png

internal class RotateTheMap : Button {

  private static double _angle = 0;

  protected override void OnClick() {

   if (LayoutView.Active == null)
    return;

   var layout = LayoutView.Active.Layout;
   var mapFrame = layout.Elements.OfType<MapFrame>().FirstOrDefault();
   if (mapFrame == null)
    return;

   QueuedTask.Run(() => {

    var def = mapFrame.GetDefinition() as CIMMapFrame;
    if (def.View.ViewingMode != MapViewingMode.Map)
     return; //2D only

    _angle -= 15;//Counter-clockwise
    if (_angle < -345) _angle = 0;

    var autoCamera = def.AutoCamera;
    if (autoCamera == null)
    {
     //unusual
     def.AutoCamera = new CIMAutoCamera()
     {
      Camera = new CIMViewCamera(),
      AutoCameraType = AutoCameraType.Extent
     };
    }
    else if (autoCamera.Source != AutoCameraSource.None &&
        autoCamera.Source != AutoCameraSource.Fixed)
    {
     return;
    }

    def.View.Camera.Heading = _angle;
    mapFrame.SetDefinition(def);
   });
  }
 }

 

 

0 Kudos
GISTaldor
New Contributor II

Hi.

Thanks for the code sample, it really helped.

0 Kudos