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).");
}
}