Build a map layout
This tutorial demonstrates how to create a custom map layout using the ArcGIS Pro SDK for .NET.
With the ArcGIS Pro SDK for .NET, you can extend ArcGIS Pro with your own unique tools and workflows. Using Microsoft Visual Studio and the Pro SDK, developers can build Pro add-ins and solution configurations that provide users with custom functionality specific to their organization or industry.
The ArcGIS Pro SDK for .NET includes a Map Layout API, which provides classes and members to support managing layouts, layout elements, and working with layout views. You can create new layouts and layout elements, modify existing elements, and manage selections, layout view control, and navigation.
In this tutorial, you will create a new map layout, add layout elements including a map frame and text elements, and then open the layout in a new layout view.
Prerequisites
- Microsoft Visual Studio is required. See the ArcGIS Pro system requirements for latest version and compatibility.
- Install ArcGIS Pro version 3.0 or higher.
- Install the ArcGIS Pro SDK for .NET. See the Installation ProGuide for more information.
- This tutorial uses Pro SDK Community sample data.
Steps
Create a new ArcGIS Pro Add-In Visual Studio Project
Start Visual Studio.
Choose File > New > Project and then from the ArcGIS templates group, select ArcGIS Pro Module Add-in. Name the add-in project "MapLayout".
By default, the
Config.daml
file opens in Visual Studio. TheModule1.cs
file contains add-in module code.Note also in the
Config.daml
file that theid
attribute of theinsert
tag matches the ID within theModule Module1.cs
file and that theclass
attribute also matches the class name of the module.Name To find the ArcGIS templates group, see Templates > Visual C# > ArcGIS. Also confirm that the latest .NET Framework is selected.
Create a new Pro button and edit DAML
Right-click the project and choose Add > New Item. From the ArcGIS Pro Add-ins group > list of templates, select ArcGIS Pro Button.
Name the new class file "BuildNewLayout.cs" and press Add to close the dialog box.
Once added, the
Build
file should open by default. The Button template also provides the contents of the class file, as well as corresponding code in theN e w Layout.cs Config.daml
file for the Pro UI, so the tool can be activated. TheConfig.daml
is updated first.Open the
Config.daml
file and modify the button item as follows:When you update the
Config.daml
, you change how the tool displays in the Create Features pane UI, providing helpful information to the user about the tool's name and purpose.Change
caption
toBuild New Layout
.Change the
tooltip heading
to"Build New Map Layout"
and the ToolTip text to"Create a new map layout with layout elements."
Change the group
caption
to“Layout Tools”
.
Use dark colors for code blocks Copy
Create and set up a new layout page
Open the
Build
file and add the following using directives:N e w Layout.cs Use dark colors for code blocks Copy In the
Build
file, update the code to match the following for theN e w Layout.cs O
method. This creates a new layout and CIM page and applies it to the layout:n Click Creating a new layout generates a new layout project item in the Layouts folder on the Contents pane. The next logical steps are to create new layout elements. See the ElementFactory for adding new elements to the layout. A new layout project item is not automatically opened in a layout view pane. Use methods from the LayoutFrameworkExtender to open a layout project item in a pane. See also LayoutFactory class.
Use dark colors for code blocks Copy
Create a map and map elements and add to the layout
You will continue adding code to the O
method.
In this step you create a map and add a layer through code, and then set the Map
and then the camera. The MapFrame class primarily manages the placement of maps and scenes on a page layout. You can use Map and SetMap members to get and set the Map associated with a Map
. To change the geographic extent within a map frame, use the Camera
and Set
members to get and set the Camera associated with a Map
.
Next you will add code to create a map with census data, add it to the layout, and set the camera. Update the code to match the following:
Use dark colors for code blocks Copy Continue adding code to the
O
method. This code creates a title and North arrow:n Click Use dark colors for code blocks Copy
Finalize code and test
In this step, you continue to use the ElementFactory to create and add new map elements to your layout.
Finalize the
O
method with additional code creating a map legend and then opening the layout pane.n Click After creating a legend, return the layout, close the
Queued
, and then open the layout withTask Create
.Layout Pane Async Use dark colors for code blocks Copy Once your code is completed, build your project and debug any issues. Start the project, which will launch ArcGIS Pro.
Create a new project when the ArcGIS Pro start page appears. From the Add-in tab and find your new button.
Press your new button to run the code and open the new layout.
What's Next?
Learn how to use additional ArcGIS Pro SDK for .NET features in these tutorials: