ArcGIS Pro 设置要素图层样式
This tutorial demonstrates how to build an add-in that can assign a renderer to your feature layer to change feature symbology.
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, such as the ability to interact with feature layers and their symbology, specific to their organization or industry. You can update layer symbology based upon an existing system style or a custom style that is loaded within your project.
In this tutorial you will create an add-in with two buttons that update the symbology of a point feature layer with either a new symbol or graduated colors.
Tip
For more information, see the ArcGIS Pro wiki map authoring or see the ArcGIS Pro SDK API reference. You can also review the ArcGIS Pro user community's map authoring samples.
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 solution
-
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 "LayerSymbology". Click OK to proceed.
Create new Pro buttons and update DAML
-
Right-click the project and choose Add > New Item and then from the ArcGIS Pro Add-ins group select ArcGIS Pro Button from the list of item templates.
-
When prompted, name the new class file
SingleSymbol.cs
and click Add to close the dialog box. -
Repeat these steps to add a second button, naming this class
GraduatedColor.cs
. -
Add the following code to the
OnClick
method ofSingleSymbol.cs
: -
Add the following code to the
OnClick
method ofGraduatedColor.cs
: -
Update the
Config.daml
fileAddInInfo
section so that the DAML appears as follows. This updates the captions for each of the buttons, and the caption of the control group, which will appear on the Add-In tab.
Create a new method in the module file
-
Copy the following code to create a new
ApplySymbol
method, and paste it into the Module1.cs file below theOverrides
region.
Update the dataset and test the add-in
To update layer symbology to graduated colors requires a numeric attribute named Symbol
on which to apply an equal interval classification. One method is to add a new field to the previously downloaded ArcGIS Pro SDK community sample dataset, FeatureTest, which is typically located in C:\Data\FeatureTest\
.
The following steps assume that you are using this dataset for testing.
-
Build your project and resolve any issues.
-
Click Start Debugging to run your project, which will launch ArcGIS Pro. Open the FeatureTest.aprx project.
-
In the map view, find the layer named TestPoints. Add a new integer attribute named Symbol to this layer and then calculate its values to match the values in the
ObjectID
attribute.You can use the following Geoprocessing tools to add a new field and calculate values:
<https://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-field.htm>
<https://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field.htm>
-
Once the new Symbol attribute is available and populated, from the Add-In tab find your new control group with your two new buttons. Test both of your buttons with the TestPoints point feature layer to see it rendered with either a new single symbol or graduated colors.
What's Next?
Learn how to use additional ArcGIS Pro SDK for .NET features in these tutorials: