MapGrid labels (coordinates) for layout on the right side of the map

350
1
08-17-2021 03:10 AM
FredB
by
New Contributor II

Hello,

I'm trying to display the grid label (coordinates) of a MapFrame on the right side of the map, but can't figure out how to do this. At the moment they are on the left side. I'ld like to do this in my code...

I've found the indices for position on the element:

Grid position indexes. Coordinates on the left side (I want them on the right side)Grid position indexes. Coordinates on the left side (I want them on the right side)

And my code:

 

var gridLabelsNorthSouth = new CIMGridLine
{
	Name = "Labels",
	ElementType = GridElementType.Label,
	GridLineOrientation = GridLineOrientation.NorthSouth,
	Pattern = new CIMGridPattern { Interval = this.printOptions.KoordinatenGitter, Start = 1, Stop = 0, Gap = 0 },
	VisibleIndices = new int[] { 3, 4 }, // <-- This is not working
	FromTick = new CIMExteriorTick
	{
		Length = 0.0694,
		Offset = 0,
		IsVisible = true,
		EdgeAffinity = new int[] { 3, 4 }, // <-- This is not working
		GridEndpoint = new CIMGridEndpoint
		{
			GridLabelTemplate = new CIMSimpleGridLabelTemplate
			{
				// DynamicStringTemplate = $"<dyn type=\"grid\" units=\"{gridUnits}\" decimalPlaces=\"0\" separator=\"True\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", 
				DynamicStringTemplate = $"<dyn type=\"grid\" decimalPlaces=\"0\" separator=\"True\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>",
				Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8, "Arial", "Regular")).MakeSymbolReference()
			},
			Offset = 0.083,
			Position = 4,  // <-- This is not working
			LineSelection = 7
		}
	},
	ToTick = new CIMExteriorTick
	{
		Length = 0.0694,
		Offset = 0,
		IsVisible = true,
		EdgeAffinity = new int[] { 3, 4 }, // <-- This is not working
		GridEndpoint = new CIMGridEndpoint
		{
			GridLabelTemplate = new CIMSimpleGridLabelTemplate
			{
				DynamicStringTemplate = "", //TODO                               
				Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 0.5, "Arial", "Regular")).MakeSymbolReference()
			},
			Offset = 0.083,
			Position = 4,  // <-- This is not working
			LineSelection = 7
		}
	}
};

var projectedCoordinateSystem = mapframe.Map.SpatialReference.ToCIMSpatialReference() as ProjectedCoordinateSystem;

CIMMapGrid mapGrid = new CIMMeasuredGrid
{
	Name = "GEODAT-Tools_MapGrid",
	GridLines = new CIMGridLine[] { gridLinesEastWest, gridLinesNorthSouth, gridLabelsEastWest, gridLabelsNorthSouth },
	IsVisible = true,
	ProjectedCoordinateSystem = projectedCoordinateSystem,
};

var mapFrameDefinition = mapframe.GetDefinition();
CIMMapFrame cimMapFrame = mapFrameDefinition as CIMMapFrame;
cimMapFrame.Grids = new CIMMapGrid[] { mapGrid };
mapframe.SetDefinition(mapFrameDefinition);

 

 

Any advice ?

Thanks !

Tags (3)
0 Kudos
1 Reply
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I use the following steps to solve these types of CIM related configuration problems: 

First I use the Pro UI to create a Grid in my Layout's MapFrame to fulfill my requirements.  I then create a test add-in with one button and insert the following code snippet into the button's code-behind:

 

protected override void OnClick()
	{
	  LayoutView activeLayoutView = LayoutView.Active;
	  if (activeLayoutView == null)
	  {
		MessageBox.Show("No active Layout");
		return;
	  }
	  var mapframe = activeLayoutView.ActiveMapFrame;
	  if (mapframe == null)
	  {
		MessageBox.Show("No active MapFrame");
		return;
	  }
	  QueuedTask.Run(() =>
	  {
		var mapFrameDefinition = mapframe.GetDefinition();
		CIMMapFrame cimMapFrame = mapFrameDefinition as CIMMapFrame;
		System.IO.File.WriteAllText(@"c:\temp\mapgrid.xml", cimMapFrame.ToXml());
	  });
	}

 

When running the test add-in I select my layout and make my MapFrame the active map frame.  After I used my test button I can then open the output file: c:\temp\mapgrid.xml in Visual Studio.  Using the output 'CIMMapFrame' structure I use the XML to find and examine the GridLines that were defined by ArcGIS Pro:

Wolf_0-1629307519720.png

 

0 Kudos