Hello,
I can not seem to figure out how to add a background color to an ArcGIS Pro map frame using C# in ArcGIS Pro SDK. For example, I can programmatically add a new map frame to a layout, but I would then like to set a blue background color for the map frame. I cannot seem to find any documentation on this. Any help would be much appreciated.
Thank you!
If the API doesn't expose a method or property for your needs you can usually try the underlying 'Cartographic Information Model' (CIM) for that class. So specifically for the Map class you can find a BackgroundColor property in the corresponding CIMMap class. This code snippet will work for you:
if (MapView.Active?.Map == null) return;
QueuedTask.Run(() =>
{
var cimMap = MapView.Active.Map.GetDefinition();
cimMap.BackgroundColor = CIMColor.CreateRGBColor(0, 0, 255, 138);
MapView.Active.Map.SetDefinition(cimMap);
});
Hope this helps.
Thank you. The solution above, added a blue background to the active map within my map frame, but did not add a blue background to the map frame (within the layout view) itself. I am trying to change the background symbol (located in the format map frame pane) to blue (see image).
Thank you!
I'm wondering if anyone has any knowledge on using ArcGIS Pro SDK to add a background color to the map frame itself. Here is a graphic that displays the background feature that I am trying to change to blue.
Thank you!
Hi Joshua
Here is a code snippet that can change the map frame's background.
Thanks!
Uma
protected override void OnClick()
{
QueuedTask.Run(() =>
{
//Get the layout
var layout = Project.Current.GetItems<LayoutProjectItem>()?.First().GetLayout();
if (layout == null) return;
//Get the map frame in the layout
MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame;
if (mapFrame == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
return;
}
//Get the map frame's definition in order to modify the background.
var mapFrameDefn = mapFrame.GetDefinition() as CIMMapFrame;
//Construct the polygon symbol to use to create a background
var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlueRGB, SimpleFillStyle.Solid);
//Set the background
mapFrameDefn.GraphicFrame.BackgroundSymbol = polySymbol.MakeSymbolReference();
//Set the map frame defintion
mapFrame.SetDefinition(mapFrameDefn);
});
}
Perfect, this worked great.
Much appreciated.
Thanks!
@UmaHarano, is there a fix for doing this in ArcGIS Pro? I have the background color set on my Map tab, and that's showing up properly, but when viewing my map frames in Layout, their backgrounds revert to white unless I hide everything from my TOC.
Hi,
The Pro development team will soon allow the background set in the Map View to automatically display in the Layout's map frame also. Unfortunately at this time, you have to set the MapFrame's background even if your Map view has the background set already set.
I understand that; my question was how to actually change the background of the map within the frame. Changing the data frame background color only seems to change the color if you happen to add a gap...