{
var usaStatesLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>()
.FirstOrDefault(fl => fl.Name == "USA States");
if (usaStatesLayer == null) return;
//Note: Run within a QueuedTask
//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);
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)