Select to view content in your preferred language

create programmatically map frame with basic properties of map grid

1930
5
Jump to solution
03-08-2023 04:55 AM
Ruben_DarioCalero_Clavijo
Occasional Contributor

Hello, Esri Team

I trying to create programmatically in ArcGIS Pro SDK C#, a Button that create a map frame with basic properties of the map grid in c# (Border width of MapFrame, Coordinate System of Grid, Line width of Ticks, Font Style of Labels, Visible Labels, Interval of gridlines).

I have been looking for examples of how to set this basic properties for the map grid on the internet (Esri Community, github Esri, Google, stackexchange, chatgpt) but i cant find it.

So I need some basic examples to set this basic properties of the mapgrid:

  • MapFrame>Display>Border>Symbol=(2 pt)
  • Grid>Coordinate System=(Any Example)
  • Grid>Ticks>Symbol>Appearance>Line width=(2 pt)
  • Grid>Labels>General>Appearance>Font Style=(Bold)
  • Grid>Components>labels>Visible=(North, South, East, West)
  • Grid>Components>gridlines>Interval=(x=50000,Y=5000)

I attach a screenshot of what i need (mapframe with mapgrid)

 

MapGrid_ArcGISPro.png

 

0 Kudos
1 Solution

Accepted Solutions
Ruben_DarioCalero_Clavijo
Occasional Contributor

I already develop the correct code. This is the code. thanks.

 

protected override async void OnClick()
        {
var mapView = MapView.Active;
            if (mapView != null)
            {
                var mapvieEx = mapView.Extent;//PRUEBA OPTIENE EXTEND

                Layout newLayout = await QueuedTask.Run<Layout>(() =>
                {
                    // Create a new CIM page
                    CIMPage newPage = new CIMPage();
                                                           
                    //ORIGINAL EN PULGADAS
                    newPage.Width = 27.94;
                    newPage.Height = 21.59;
                    // newPage.Units = LinearUnit.Inches;
                    newPage.Units = LinearUnit.Centimeters;
                    
                    // Add rulers-POSIBLE QUITAR
                    newPage.ShowRulers = true;
                    newPage.SmallestRulerDivision = 0.5;
                              
                    // Apply the CIM page to a new layout and set name
                    newLayout = LayoutFactory.Instance.CreateLayout(newPage);
                    newLayout.SetName("Layout Carta-Acueducto");
                
                    return newLayout;
                });

                var layoutPane = await ProApp.Panes.CreateLayoutPaneAsync(newLayout);



await QueuedTask.Run(() =>//en el ejemplo no tenia el wait
                {

                    //1. create a map frame
                    //aquire a map
                    var mapItem = Project.Current.GetItems<MapProjectItem>().First();
                    var map = mapItem.GetMap();

                    var ll = new Coordinate2D(0.4907, 2.4994);
                    var ur = new Coordinate2D(27.5, 21.0997);
                    var env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);


                    //create the map frame
                    var map_frame = ElementFactory.Instance.CreateMapFrameElement(newLayout, env, map);
                    // map_frame.SetWidth(2);//PRUEBA
                    //SE BUSCA GENERAR UN GRID DEL TIPO MEASURED GRID-IMPORTANTEE


                    
                    //INICIO PRUEBA PROPIEDADES MAPFRAME

                    //primero agregar las GridLines (lineas, ticks(linea del label), label) segun ejemplo addgrid.cs
                    var gridLinesEastWest = new CIMGridLine
                    {
                        Name = "GridLines",
                        ElementType = GridElementType.Line,
                        GridLineOrientation = GridLineOrientation.EastWest,
                        Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(),
                        Pattern = new CIMGridPattern
                        {
                            Interval = 5000, //CADA VEZ Q SE REPITE
                            Start = 0,
                            Stop = 1,
                            Gap = 0
                        }
                    };
                    var gridLinesNorthSouth = new CIMGridLine
                    {
                        Name = "GridLines",
                        ElementType = GridElementType.Line,
                        GridLineOrientation = GridLineOrientation.NorthSouth,
                        Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(),
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 }
                    }; var gridTicksNorthSouth = new CIMGridLine
                    {
                        Name = "Ticks",
                        ElementType = GridElementType.Tick,
                        GridLineOrientation = GridLineOrientation.NorthSouth,
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 },
                        //ORIGINAL FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                        FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                        ToTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                    };
                    var gridTicksEastWest = new CIMGridLine
                    {
                        Name = "Ticks",
                        ElementType = GridElementType.Tick,
                        GridLineOrientation = GridLineOrientation.EastWest,
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 },
                        //ORIGINAL FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                        FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                        ToTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                    };


                    var gridLabelsEastWest = new CIMGridLine
                    {
                        Name = "Labels",
                        ElementType = GridElementType.Label,
                        GridLineOrientation = GridLineOrientation.EastWest,
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 },
                        FromTick = new CIMExteriorTick
                        {
                            Length = 0.0694,
                            Offset = 0,
                            IsVisible = true,
                            GridEndpoint = new CIMGridEndpoint
                            {
                                GridLabelTemplate = new CIMSimpleGridLabelTemplate
                                {
                                   //ORIGINAL DynamicStringTemplate = "<dyn type=\"grid\" units=\"dms\" decimalPlaces=\"0\" showDirections=\"True\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>",
                                    DynamicStringTemplate = "<dyn type=\"grid\" units=\"\" decimalPlaces=\"0\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>",
                                    //TODO
                                    //ORIGINAL Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                    Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                },
                                Offset = 0.083,
                                Position = 2, // A QUE POSICION SE REFIERE
                                LineSelection = 7
                            }
                        },
                        ToTick = new CIMExteriorTick
                        {
                            Length = 0.0694,
                            Offset = 0,
                            IsVisible = true,
                            GridEndpoint = new CIMGridEndpoint
                            {
                                GridLabelTemplate = new CIMSimpleGridLabelTemplate
                                {
                                   // DynamicStringTemplate = "", //TODO                               
                                    DynamicStringTemplate = "<dyn type=\"grid\" units=\"\" decimalPlaces=\"0\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>",
                                    //ORIGINAL   Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Regular")).MakeSymbolReference()
                                    Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                },
                                Offset = 0.083,
                                Position = 2, //AQUE POSICION SE REFIERE
                                LineSelection = 7
                            }
                        }
                    };
                    var gridLabelsNorthSouth = new CIMGridLine
                    {
                        Name = "Labels",
                        ElementType = GridElementType.Label,
                        GridLineOrientation = GridLineOrientation.NorthSouth,
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 },
                        FromTick = new CIMExteriorTick
                        {
                            Length = 0.0694,
                            Offset = 0,
                            IsVisible = true,
                            GridEndpoint = new CIMGridEndpoint
                            {
                                GridLabelTemplate = new CIMSimpleGridLabelTemplate
                                {
                                   //ORIGINAL DynamicStringTemplate = "<dyn type=\"grid\" units=\"dms\" decimalPlaces=\"0\" showDirections=\"True\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", //TODO
                                    DynamicStringTemplate = "<dyn type=\"grid\" units=\"\" decimalPlaces=\"0\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", //TODO                                                                                                                                                              //
                                    Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                },
                                Offset = 0.083,
                                Position = 2, // A QUE POSICION SE REFIERE
                                LineSelection = 7
                            }
                        },
                        ToTick = new CIMExteriorTick
                        {
                            Length = 0.0694,
                            Offset = 0,
                            IsVisible = true,
                            GridEndpoint = new CIMGridEndpoint
                            {
                                GridLabelTemplate = new CIMSimpleGridLabelTemplate // se podria quitar para ver texto estandar
                                {
                                   //ORIGINAL DynamicStringTemplate = "", //TODO                               
                                    DynamicStringTemplate = "<dyn type=\"grid\" units=\"\" decimalPlaces=\"0\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", //Ejemplo de otras unidades units=\"{gridUnits}\"
                                    Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                },
                                Offset = 0.083,
                                Position = 2, // A QUE POSICION SE REFIER
                                LineSelection = 7
                            }
                        }
                    };




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

                    CIMMapGrid mapGrid = new CIMMeasuredGrid
                    {
                        
                        Name = "El_MapGrid",
                        GridLines = new CIMGridLine[] { gridLinesEastWest, gridLinesNorthSouth, gridTicksNorthSouth, gridTicksEastWest, gridLabelsEastWest, gridLabelsNorthSouth },
                        IsVisible = true,
                        NeatlineSymbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), //ES LA LINEA INTERIOR
                        ProjectedCoordinateSystem = projectedCoordinateSystem,//QUITAR LA COMA
                    };

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

                    //PRUEBA CAMBIO BORDER SIZE
                    cimMapFrame.GraphicFrame.BorderSymbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference();
                    
                    map_frame.SetDefinition(mapFrameDefinition);
                    //FIN PRUEBA PROPIEDADES MAPFRAME
                    //var mapvieEx = MapView.Active.Extent;
                    map_frame.SetCamera(mapvieEx);//OJO- SE OBTIENE TAMANO DE VENTANA
                });

                

                MessageBox.Show("Layout Creado con DataFrame.");
            }
            else
            {
                MessageBox.Show("Primero se debe Seleccionar la Ventana del Mapa (MapView).");
            }
        }

  

View solution in original post

0 Kudos
5 Replies
CharlesMacleod
Esri Regular Contributor

We are adding the capability to apply a grid style to a mapframe to the Layout api at 3.2.  The (target) frame must have a valid 2D map.

If u have the graticules/grid style item already defined in a style item that would be the most straightforward to apply (rather than trying to build it from scratch in code which is not practical given the v large number of properties that would need defaults). Applying a style to the map frame will involve using the CIM definition of the map frame. as currently I am in Palm Springs for the DEV Summit so i can take a look at this further next week when Im back (in the office).

Meanwhile, If u r not familiar with the CIM then u might want to review this session from the 2019 DEV Summit:

https://esri.github.io/arcgis-pro-sdk/techsessions/2019/PalmSprings/UnderstandingTheCIM.zip

This is the video: ArcGIS Pro SDK for .NET: Understanding the CIM, a Guide for Developers 

Examine the CIM of a map frame, specifically its "Grids" collection. https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic14379.html.. This is where u would add your grid style item - and is what the API will do for u - without needing to manipulate the CIM - at 3.2.

 

 

 

0 Kudos
Ruben_DarioCalero_Clavijo
Occasional Contributor

Ok, thanks a lot. I be waiting for further help when you return from Palm Springs from the DEV Summit.

0 Kudos
CharlesMacleod
Esri Regular Contributor

hi ruben, so i did get a chance to take a look at the grid style and turns out it is quite complicated. More complicated than I realized. I also ran into one snag that I could not work around - the dependence of the graticule on an internal class: namely property CIMGraticule.GeographicCoordinateSystem is of type ArcGIS.Core.Internal.CIM.GeographicCoordinateSystem

Anyway, I did promise an example so I did put an example together however it uses an internal namespace which is unsupported. 

anyway, you are welcome to fiddle with this code. It makes the following assumptions:

The style item is a CIMGraticule

The layout page units are in inches. If you have metric units for the page then there would be extra work in converting the graticule grid line length and offset measurements (which, by default, are in inches) to the units of the layout page.

Note: There is also a check for a 2D map associated with the map frame in the example. Graticules can only be applied to map frames with 2D maps. This check is _required_.

Finally, current plan is still for the capability to apply a grid style to a map frame be added to the layout public api at 3.2.

 

var stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
  .FirstOrDefault(item => item.Name == "ArcGIS 2D");

 var m_frame = LayoutView.Active?.Layout?.GetElementsAsFlattenedList()
     .OfType<MapFrame>()?.FirstOrDefault();
 if (m_frame == null)
   return;

 //valid 2D maps only
 if (m_frame.Map == null || 
     m_frame.Map.DefaultViewingMode != MapViewingMode.Map)
   return;

 QueuedTask.Run(() => {
   //experiment with a graticule
   var grid_si = stylePrjItm.SearchGrids(
     "Blue Vertical Label Graticule").FirstOrDefault();
   if (grid_si == null)
     return;
   var grid = grid_si.GetObject() as CIMGraticule;
   //Note: Grids can also be CIMMeasureGrid, CIMReferenceGrid, and
   //CIMCustomGrid

   //unsupported
   var xml = m_frame.Map.SpatialReference.Gcs.ToXml();
   var gcs = ArcGIS.Core.Internal.CIM.XmlUtil.DeserializeXML<
     ArcGIS.Core.Internal.CIM.GeographicCoordinateSystem>(xml);
   grid.GeographicCoordinateSystem = gcs;

   //assign grid to the frame
   var cmf = m_frame.GetDefinition() as CIMMapFrame;
   //note, if page units are _not_ inches then grid's gridline
   //lengths and offsets would need to be converted to the page units
   var mapGrids = new List<CIMMapGrid>();
   if (cmf.Grids != null)
     mapGrids.AddRange(cmf.Grids);
   mapGrids.Add(grid);

   cmf.Grids = mapGrids.ToArray();
   m_frame.SetDefinition(cmf);
 });

 

0 Kudos
Ruben_DarioCalero_Clavijo
Occasional Contributor

I already develop the correct code. This is the code. thanks.

 

protected override async void OnClick()
        {
var mapView = MapView.Active;
            if (mapView != null)
            {
                var mapvieEx = mapView.Extent;//PRUEBA OPTIENE EXTEND

                Layout newLayout = await QueuedTask.Run<Layout>(() =>
                {
                    // Create a new CIM page
                    CIMPage newPage = new CIMPage();
                                                           
                    //ORIGINAL EN PULGADAS
                    newPage.Width = 27.94;
                    newPage.Height = 21.59;
                    // newPage.Units = LinearUnit.Inches;
                    newPage.Units = LinearUnit.Centimeters;
                    
                    // Add rulers-POSIBLE QUITAR
                    newPage.ShowRulers = true;
                    newPage.SmallestRulerDivision = 0.5;
                              
                    // Apply the CIM page to a new layout and set name
                    newLayout = LayoutFactory.Instance.CreateLayout(newPage);
                    newLayout.SetName("Layout Carta-Acueducto");
                
                    return newLayout;
                });

                var layoutPane = await ProApp.Panes.CreateLayoutPaneAsync(newLayout);



await QueuedTask.Run(() =>//en el ejemplo no tenia el wait
                {

                    //1. create a map frame
                    //aquire a map
                    var mapItem = Project.Current.GetItems<MapProjectItem>().First();
                    var map = mapItem.GetMap();

                    var ll = new Coordinate2D(0.4907, 2.4994);
                    var ur = new Coordinate2D(27.5, 21.0997);
                    var env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);


                    //create the map frame
                    var map_frame = ElementFactory.Instance.CreateMapFrameElement(newLayout, env, map);
                    // map_frame.SetWidth(2);//PRUEBA
                    //SE BUSCA GENERAR UN GRID DEL TIPO MEASURED GRID-IMPORTANTEE


                    
                    //INICIO PRUEBA PROPIEDADES MAPFRAME

                    //primero agregar las GridLines (lineas, ticks(linea del label), label) segun ejemplo addgrid.cs
                    var gridLinesEastWest = new CIMGridLine
                    {
                        Name = "GridLines",
                        ElementType = GridElementType.Line,
                        GridLineOrientation = GridLineOrientation.EastWest,
                        Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(),
                        Pattern = new CIMGridPattern
                        {
                            Interval = 5000, //CADA VEZ Q SE REPITE
                            Start = 0,
                            Stop = 1,
                            Gap = 0
                        }
                    };
                    var gridLinesNorthSouth = new CIMGridLine
                    {
                        Name = "GridLines",
                        ElementType = GridElementType.Line,
                        GridLineOrientation = GridLineOrientation.NorthSouth,
                        Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(),
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 }
                    }; var gridTicksNorthSouth = new CIMGridLine
                    {
                        Name = "Ticks",
                        ElementType = GridElementType.Tick,
                        GridLineOrientation = GridLineOrientation.NorthSouth,
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 },
                        //ORIGINAL FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                        FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                        ToTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                    };
                    var gridTicksEastWest = new CIMGridLine
                    {
                        Name = "Ticks",
                        ElementType = GridElementType.Tick,
                        GridLineOrientation = GridLineOrientation.EastWest,
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 },
                        //ORIGINAL FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                        FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                        ToTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference(), },
                    };


                    var gridLabelsEastWest = new CIMGridLine
                    {
                        Name = "Labels",
                        ElementType = GridElementType.Label,
                        GridLineOrientation = GridLineOrientation.EastWest,
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 },
                        FromTick = new CIMExteriorTick
                        {
                            Length = 0.0694,
                            Offset = 0,
                            IsVisible = true,
                            GridEndpoint = new CIMGridEndpoint
                            {
                                GridLabelTemplate = new CIMSimpleGridLabelTemplate
                                {
                                   //ORIGINAL DynamicStringTemplate = "<dyn type=\"grid\" units=\"dms\" decimalPlaces=\"0\" showDirections=\"True\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>",
                                    DynamicStringTemplate = "<dyn type=\"grid\" units=\"\" decimalPlaces=\"0\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>",
                                    //TODO
                                    //ORIGINAL Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                    Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                },
                                Offset = 0.083,
                                Position = 2, // A QUE POSICION SE REFIERE
                                LineSelection = 7
                            }
                        },
                        ToTick = new CIMExteriorTick
                        {
                            Length = 0.0694,
                            Offset = 0,
                            IsVisible = true,
                            GridEndpoint = new CIMGridEndpoint
                            {
                                GridLabelTemplate = new CIMSimpleGridLabelTemplate
                                {
                                   // DynamicStringTemplate = "", //TODO                               
                                    DynamicStringTemplate = "<dyn type=\"grid\" units=\"\" decimalPlaces=\"0\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>",
                                    //ORIGINAL   Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Regular")).MakeSymbolReference()
                                    Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                },
                                Offset = 0.083,
                                Position = 2, //AQUE POSICION SE REFIERE
                                LineSelection = 7
                            }
                        }
                    };
                    var gridLabelsNorthSouth = new CIMGridLine
                    {
                        Name = "Labels",
                        ElementType = GridElementType.Label,
                        GridLineOrientation = GridLineOrientation.NorthSouth,
                        Pattern = new CIMGridPattern { Interval = 5000, Start = 0, Stop = 1, Gap = 0 },
                        FromTick = new CIMExteriorTick
                        {
                            Length = 0.0694,
                            Offset = 0,
                            IsVisible = true,
                            GridEndpoint = new CIMGridEndpoint
                            {
                                GridLabelTemplate = new CIMSimpleGridLabelTemplate
                                {
                                   //ORIGINAL DynamicStringTemplate = "<dyn type=\"grid\" units=\"dms\" decimalPlaces=\"0\" showDirections=\"True\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", //TODO
                                    DynamicStringTemplate = "<dyn type=\"grid\" units=\"\" decimalPlaces=\"0\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", //TODO                                                                                                                                                              //
                                    Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                },
                                Offset = 0.083,
                                Position = 2, // A QUE POSICION SE REFIERE
                                LineSelection = 7
                            }
                        },
                        ToTick = new CIMExteriorTick
                        {
                            Length = 0.0694,
                            Offset = 0,
                            IsVisible = true,
                            GridEndpoint = new CIMGridEndpoint
                            {
                                GridLabelTemplate = new CIMSimpleGridLabelTemplate // se podria quitar para ver texto estandar
                                {
                                   //ORIGINAL DynamicStringTemplate = "", //TODO                               
                                    DynamicStringTemplate = "<dyn type=\"grid\" units=\"\" decimalPlaces=\"0\" showDirections=\"False\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", //Ejemplo de otras unidades units=\"{gridUnits}\"
                                    Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Bold")).MakeSymbolReference()
                                },
                                Offset = 0.083,
                                Position = 2, // A QUE POSICION SE REFIER
                                LineSelection = 7
                            }
                        }
                    };




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

                    CIMMapGrid mapGrid = new CIMMeasuredGrid
                    {
                        
                        Name = "El_MapGrid",
                        GridLines = new CIMGridLine[] { gridLinesEastWest, gridLinesNorthSouth, gridTicksNorthSouth, gridTicksEastWest, gridLabelsEastWest, gridLabelsNorthSouth },
                        IsVisible = true,
                        NeatlineSymbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), //ES LA LINEA INTERIOR
                        ProjectedCoordinateSystem = projectedCoordinateSystem,//QUITAR LA COMA
                    };

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

                    //PRUEBA CAMBIO BORDER SIZE
                    cimMapFrame.GraphicFrame.BorderSymbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)).MakeSymbolReference();
                    
                    map_frame.SetDefinition(mapFrameDefinition);
                    //FIN PRUEBA PROPIEDADES MAPFRAME
                    //var mapvieEx = MapView.Active.Extent;
                    map_frame.SetCamera(mapvieEx);//OJO- SE OBTIENE TAMANO DE VENTANA
                });

                

                MessageBox.Show("Layout Creado con DataFrame.");
            }
            else
            {
                MessageBox.Show("Primero se debe Seleccionar la Ventana del Mapa (MapView).");
            }
        }

  

0 Kudos
RichardDaniels
Frequent Contributor

Have you considered using a Map Layout Template (.pagx file extension) that would contain the custom definitions you need? The legend, labels, symbols, etc. can be given unique tags/names so they can be updated in code. In our case we have a user select from a list of templates in a form and then enter titles (on the form). When they click Apply the selected template is loaded with the current ActiveMap in the frame and the maps titles (defined in the template) are automatically updated. 

 

*Layout files (.pagx file extension) are saved layouts that can be shared across projects. They can be used as a template for new projects and can create consistency across a set of layouts or throughout an organization.

0 Kudos