public CIMColorRamp ColorRamp {get; set;}
Public Property ColorRamp As CIMColorRamp
public CIMColorRamp ColorRamp {get; set;}
Public Property ColorRamp As CIMColorRamp
{
var usaStatesLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>()
.FirstOrDefault(fl => fl.Name == "USA States");
if (usaStatesLayer == null)
{
return;
}
await QueuedTask.Run(() =>
{
//Create a color ramp from red to blue
var colorRampForPopulation = ColorFactory.Instance.ConstructColorRamp(
ColorRampAlgorithm.LinearContinuous,
ColorFactory.Instance.RedRGB, ColorFactory.Instance.BlueRGB);
//This Arcade expression categorizes the POP2000 field in the usaStates layer
//into Low, Medium, and High values
var arcade = @"if ($feature.POP2000 < 1000000)
{return ""Low"";}" +
@"else if ($feature.POP2000 >= 100000 && $feature.POP2000 < 5000000)
{return ""Medium""; }" +
@"else if ($feature.POP2000 >= 5000000)
{return ""High"";}" +
@"else{return ""NA"";}";
//Create the Arcade expression info
CIMExpressionInfo arcadeExp = new CIMExpressionInfo();
arcadeExp.Expression = arcade;
arcadeExp.ReturnType = ExpressionReturnType.Default;
arcadeExp.Title = "State Population Categorized";
arcadeExp.Name = "USA States Population 2000";
//Each population category is assigned a color from the color ramp and symbolized on the map
// using a unique value renderer
var uvr_desc = new UniqueValueRendererDefinition()
{
//ValueFields = new List<string> { "STATION" },
ColorRamp = colorRampForPopulation,
UseDefaultSymbol = true,
ValuesLimit = 100,
ArcadeExpression = arcadeExp.Expression
};
//Create the renderer and assign it to the layer
var renderer = usaStatesLayer.CreateRenderer(uvr_desc);
usaStatesLayer.SetRenderer(renderer);
});
}
/// <summary> /// Renders a feature layer using unique values from one or multiple fields ///  /// </summary> { //Check feature layer name //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data var featureLayer = activeMap.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.Name == "USDemographics"); if (featureLayer == null) { MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing"); } //construct unique value renderer definition UniqueValueRendererDefinition uvr = new UniqueValueRendererDefinition() { //Refer to the function below to get a display field of the feature layer ValueFields = new List<string> { await GetDisplayFieldAsync(featureLayer) }, //multiple fields in the array if needed. ColorRamp = colorRamp, //Specify color ramp }; //Creates a "Renderer" await QueuedTask.Run(() => { var cimRenderer = featureLayer.CreateRenderer(uvr); //Sets the renderer to the feature layer featureLayer.SetRenderer(cimRenderer); }); //Function to get the display field of a feature layer static Task<string> GetDisplayFieldAsync(FeatureLayer featureLayer) { return QueuedTask.Run(() => { // get the CIM definition from the layer var cimFeatureDefinition = featureLayer.GetDefinition() as ArcGIS.Core.CIM.CIMBasicFeatureLayer; // get the view of the source table underlying the layer var cimDisplayTable = cimFeatureDefinition.FeatureTable; // this field is used as the 'label' to represent the row return cimDisplayTable.DisplayField; }); } }
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)