Public Overloads Sub SetRenderer( _ ByVal renderer As CIMRenderer _ )
public void SetRenderer( CIMRenderer renderer )
Parameters
- renderer
- Your custom renderer that will be used to draw features of the feature layer.
Public Overloads Sub SetRenderer( _ ByVal renderer As CIMRenderer _ )
public void SetRenderer( CIMRenderer renderer )
| Exception | Description |
|---|---|
| ArcGIS.Core.CalledOnWrongThreadException | This method or property must be called within the lambda passed to QueuedTask.Run. |
| System.ArgumentException | Cannot set renderer for layer. |
{
// Note: the following should be embedded in a QueuedTask.Run() statement
{
// GetRenderer from Layer (assumes it is a unique value renderer)
if (featureLayer.GetRenderer() is not CIMUniqueValueRenderer uvRenderer)
{
// not a unique value renderer, leave
return;
}
//layer has STATE_NAME field if using the community sample Data\Admin\AdminSample.aprx
string expression = "if ($view.scale > 21000000) { return $feature.STATE_NAME } else { return 'All' }";
CIMExpressionInfo updatedExpressionInfo = new()
{
Expression = expression,
Title = "Custom" // can be any string used for UI purpose.
};
//set the renderer's expression
uvRenderer.ValueExpressionInfo = updatedExpressionInfo;
//SetRenderer on Layer
featureLayer.SetRenderer(uvRenderer);
}
}
{
//Note: Needs QueuedTask to run
//Get simple renderer from the feature layer
CIMSimpleRenderer currentRenderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
if (currentRenderer == null)
return;
//Set symbol's real world setting to be the same as that of the feature layer
symbol.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes);
//Update the symbol of the current simple renderer
currentRenderer.Symbol = symbol.MakeSymbolReference();
//Update the feature layer renderer
featureLayer.SetRenderer(currentRenderer);
}
{
//Note: Needs QueuedTask to run
//Get simple renderer from the feature layer
CIMSimpleRenderer currentRenderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
if (currentRenderer == null)
return;
//Get symbol from the SymbolStyleItem
CIMSymbol symbolToApply = symbolStyleItem.Symbol;
//Set symbol's real world setting to be the same as that of the feature layer
symbolToApply.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes);
//Update the symbol of the current simple renderer
currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
//Update the feature layer renderer
featureLayer.SetRenderer(currentRenderer);
}
{
//Get the ArcGIS 2D System style from the Project
var arcGIS2DStyle =
Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
//Note: Needs QueuedTask to run
//Search for the symbolName style items within the ArcGIS 2D style project item.
var items = arcGIS2DStyle.SearchSymbols(StyleItemType.PointSymbol, "Circle 1");
//Gets the CIMSymbol
CIMSymbol symbolToUse = items.FirstOrDefault().Symbol;
//Get the renderer of the point feature layer
CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
//Set symbol's real world setting to be the same as that of the feature layer
symbolToUse.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes);
//Apply the symbol to the feature layer's current renderer
renderer.Symbol = symbolToUse.MakeSymbolReference();
//Apply the renderer to the feature layer
featureLayer.SetRenderer(renderer);
}
{
List<string> fields = new List<string>() { "Field1" };
//Note: Needs QueuedTask to run
StyleProjectItem styleToUse =
Project.Current.GetItems<StyleProjectItem>()
.FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
if (style == null) return;
//Note: Needs QueuedTask to run
var colorRampListFound = styleToUse.SearchColorRamps("Red-Gray (10 Classes)");
if (colorRampListFound == null || colorRampListFound.Count == 0) return;
CIMColorRamp cimColorRamp = null;
CIMRenderer renderer = null;
cimColorRamp = colorRampListFound[0].ColorRamp;
var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp);
renderer = featureLayer?.CreateRenderer(rendererDef);
featureLayer?.SetRenderer(renderer);
}
{
IEnumerable<FeatureLayer> featureLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>()
.Where(l => l.ShapeType == esriGeometryType.esriGeometryPoint);
var layerFile = @"C:\Data\SDK\UniqueValuePointLayer.lyrx";
foreach (var featureLayerToSymbolize in featureLayers)
{
//Get the Layer Document from the lyrx file
var lyrDocFromLyrxFile = new LayerDocument(layerFile);
var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
//Get the renderer from the layer file
var rendererFromLayerFile = ((CIMFeatureLayer)cimLyrDoc.LayerDefinitions[0]).Renderer as CIMUniqueValueRenderer;
//Apply the renderer to the feature layer
//Note: If working with a raster layer, use the SetColorizer method.
featureLayerToSymbolize?.SetRenderer(rendererFromLayerFile);
}
}
{
//field to be used to retrieve unique values
//Note: Run within a QueuedTask
var fields = new List<string> { "Type" };
//constructing a point symbol as a template symbol
CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(
ColorFactory.Instance.GreenRGB, 16.0, SimpleMarkerStyle.Pushpin);
CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
//constructing renderer definition for unique value renderer
UniqueValueRendererDefinition uniqueValueRendererDef =
new UniqueValueRendererDefinition(fields, symbolPointTemplate);
//creating a unique value renderer
CIMUniqueValueRenderer uniqueValueRenderer = featureLayer.CreateRenderer(uniqueValueRendererDef) as CIMUniqueValueRenderer;
//setting the renderer to the feature layer
featureLayer.SetRenderer(uniqueValueRenderer);
}
{
//The goal is to construct the CIMUniqueValueRenderer which will be applied to the feature layer.
// To do this, the following are the objects we need to set the renderer up with the fields and symbols.
// As a reference, this is the USCities dataset. Snippet will create a unique value renderer that applies
// specific symbols to all the cities in California and Alabama. The rest of the cities will use a default symbol.
// First create a "CIMUniqueValueClass" for the cities in Alabama.
List<CIMUniqueValue> listUniqueValuesAlabama = new List<CIMUniqueValue> { new CIMUniqueValue { FieldValues = new string[] { "Alabama" } } };
CIMUniqueValueClass alabamaUniqueValueClass = new CIMUniqueValueClass
{
Editable = true,
Label = "Alabama",
Patch = PatchShape.Default,
Symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB).MakeSymbolReference(),
Visible = true,
Values = listUniqueValuesAlabama.ToArray()
};
// Create a "CIMUniqueValueClass" for the cities in California.
List<CIMUniqueValue> listUniqueValuescalifornia = new List<CIMUniqueValue> { new CIMUniqueValue { FieldValues = new string[] { "California" } } };
CIMUniqueValueClass californiaUniqueValueClass = new CIMUniqueValueClass
{
Editable = true,
Label = "California",
Patch = PatchShape.Default,
Symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlueRGB).MakeSymbolReference(),
Visible = true,
Values = listUniqueValuescalifornia.ToArray()
};
//Create a list of the above two CIMUniqueValueClasses
List<CIMUniqueValueClass> listUniqueValueClasses = new List<CIMUniqueValueClass>
{
alabamaUniqueValueClass, californiaUniqueValueClass
};
//Create a list of CIMUniqueValueGroup
CIMUniqueValueGroup uvg = new CIMUniqueValueGroup
{
Classes = listUniqueValueClasses.ToArray(),
};
List<CIMUniqueValueGroup> listUniqueValueGroups = new List<CIMUniqueValueGroup> { uvg };
//Create the CIMUniqueValueRenderer
CIMUniqueValueRenderer uvr = new CIMUniqueValueRenderer
{
UseDefaultSymbol = true,
DefaultLabel = "all other values",
DefaultSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreyRGB).MakeSymbolReference(),
Groups = listUniqueValueGroups.ToArray(),
Fields = new string[] { "STATE_NAME" }
};
//Set the feature layer's renderer.
//Note: Run within a QueuedTask
featureLayer.SetRenderer(uvr);
}
{
string colorBrewerSchemesName = "ArcGIS Colors";
//Get the style project item that contains the color ramps
//Refer to the Initialize region for an example of how to get a style item
//and the color ramp from it.
//Note: Run within a QueuedTask
//defining a heatmap renderer that uses values from Population field as the weights
HeatMapRendererDefinition heatMapDef = new HeatMapRendererDefinition()
{
Radius = 20,
WeightField = "Population",
ColorRamp = colorRamp,
RendereringQuality = 8,
UpperLabel = "High Density",
LowerLabel = "Low Density"
};
CIMHeatMapRenderer heatMapRndr = featureLayer.CreateRenderer(heatMapDef) as CIMHeatMapRenderer;
featureLayer.SetRenderer(heatMapRndr);
}
{
string colorBrewerSchemesName = "ArcGIS Colors";
//Get the style project item that contains the color ramps
//Refer to the Initialize region for an example of how to get a style item
//Note: Run within a QueuedTask
CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 16.0, SimpleMarkerStyle.Diamond);
CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
//defining an unclassed renderer with custom upper and lower stops
//all features with value >= 5,000,000 will be drawn with the upper color from the color ramp
//all features with value <= 50,000 will be drawn with the lower color from the color ramp
UnclassedColorsRendererDefinition unclassRndrDef = new UnclassedColorsRendererDefinition
("Population", symbolPointTemplate, colorRamp, "Highest", "Lowest", 5000000, 50000)
{
//drawing features with null values with a different symbol
ShowNullValues = true,
NullValueLabel = "Unknown"
};
// Create a point symbol for null values
CIMPointSymbol nullSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 16.0, SimpleMarkerStyle.Circle);
unclassRndrDef.NullValueSymbol = nullSym.MakeSymbolReference();
//Create the unclassed renderer using the definition
CIMClassBreaksRenderer cbRndr = featureLayer.CreateRenderer(unclassRndrDef) as CIMClassBreaksRenderer;
//Set the renderer to the feature layer
featureLayer.SetRenderer(cbRndr);
}
{
string colorBrewerSchemesName = "ArcGIS Colors";
//Get the style project item that contains the color ramps
//Refer to the Initialize region for an example of how to get a style item
//Note: Run within a QueuedTask
//Creating a point symbol to be used as a template symbol for the proportional renderer
CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle);
CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
//minimum symbol size is capped to 4 point while the maximum symbol size is set to 50 point
//Creating a proportional renderer definition that uses the "Population" field
ProportionalRendererDefinition prDef = new ProportionalRendererDefinition("POPULATION", symbolPointTemplate, 4, 50, true)
{
//setting upper and lower size stops to stop symbols growing or shrinking beyond those thresholds
UpperSizeStop = 5000000, //features with values >= 5,000,000 will be drawn with maximum symbol size
LowerSizeStop = 50000 //features with values <= 50,000 will be drawn with minimum symbol size
};
// Create a proportional renderer using the definition
CIMProportionalRenderer propRndr = featureLayer.CreateRenderer(prDef) as CIMProportionalRenderer;
// Set the renderer to the feature layer
featureLayer.SetRenderer(propRndr);
}
{
string colorBrewerSchemesName = "ArcGIS Colors";
//Get the style project item that contains the color ramps
//Refer to the Initialize region for an example of how to get a style item
//Note: Run within a QueuedTask
//Creating a point symbol to be used as a template symbol for the proportional renderer
CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle);
CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
//Defining proportional renderer where size of symbol will be same as its value in field used in the renderer.
ProportionalRendererDefinition prDef = new ProportionalRendererDefinition("POPULATION", esriUnits.esriMeters, symbolPointTemplate, SymbolShapes.Square, ValueRepresentations.Radius);
//Create a Proportional renderer using the definition
CIMProportionalRenderer propRndr = featureLayer.CreateRenderer(prDef) as CIMProportionalRenderer;
// Set the renderer to the feature layer
featureLayer.SetRenderer(propRndr);
}
{
// Note: call within QueuedTask.Run()
{
var url = @"https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer";
var uri = new Uri(url, UriKind.Absolute);
var createParams = new FeatureLayerCreationParams(uri)
{
IsVisible = false
};
streamLayer = LayerFactory.Instance.CreateLayer<StreamLayer>(
createParams, map);
//Define the unique values by hand
var uvr = new CIMUniqueValueRenderer()
{
Fields = new string[] { "ACTYPE" },
UseDefaultSymbol = true,
DefaultLabel = "Others",
DefaultSymbol = SymbolFactory.Instance.ConstructPointSymbol(
CIMColor.CreateRGBColor(185, 185, 185), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
};
var classes = new List<CIMUniqueValueClass>
{
//add in classes - one for ACTYPE of 727, one for DC 9
new CIMUniqueValueClass()
{
Values = new CIMUniqueValue[] {
new CIMUniqueValue() { FieldValues = new string[] { "B727" } } },
Visible = true,
Label = "Boeing 727",
Symbol = SymbolFactory.Instance.ConstructPointSymbol(
ColorFactory.Instance.RedRGB, 10, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
},
new CIMUniqueValueClass()
{
Values = new CIMUniqueValue[] {
new CIMUniqueValue() { FieldValues = new string[] { "DC9" } } },
Visible = true,
Label = "DC 9",
Symbol = SymbolFactory.Instance.ConstructPointSymbol(
ColorFactory.Instance.GreenRGB, 10, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
}
};
//add the classes to a group
var groups = new List<CIMUniqueValueGroup>()
{
new CIMUniqueValueGroup() {
Classes = classes.ToArray()
}
};
//add the groups to the renderer
uvr.Groups = groups.ToArray();
//Apply the renderer (for current observations)
streamLayer.SetRenderer(uvr);
streamLayer.SetVisibility(true);//turn on the layer
}
}
{
// Note: call within QueuedTask.Run()
{
streamLayer = null;
//https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer
var uvrDef = new UniqueValueRendererDefinition()
{
ValueFields = new List<string> { "ACTYPE" },
SymbolTemplate = SymbolFactory.Instance.ConstructPointSymbol(
ColorFactory.Instance.RedRGB, 10, SimpleMarkerStyle.Hexagon)
.MakeSymbolReference(),
ValuesLimit = 5
};
//Note: CreateRenderer can only create value classes based on
//the current events it has received
streamLayer.SetRenderer(streamLayer.CreateRenderer(uvrDef));
}
}
{
// Note: call within QueuedTask.Run()
{
//Define the classes by hand to avoid using CreateRenderer(...)
CIMUniqueValueClass uvcB727 = new CIMUniqueValueClass()
{
Values = new CIMUniqueValue[] { new CIMUniqueValue() { FieldValues = new string[] { "B727" } } },
Visible = true,
Label = "Boeing 727",
Symbol = SymbolFactory.Instance.ConstructPointSymbol(CIMColor.CreateRGBColor(255, 0, 0), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
};
CIMUniqueValueClass uvcD9 = new CIMUniqueValueClass()
{
Values = new CIMUniqueValue[] { new CIMUniqueValue() { FieldValues = new string[] { "DC9" } } },
Visible = true,
Label = "DC 9",
Symbol = SymbolFactory.Instance.ConstructPointSymbol(CIMColor.CreateRGBColor(0, 255, 0), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
};
//Assign the classes to a group
CIMUniqueValueGroup uvGrp = new CIMUniqueValueGroup()
{
Classes = new CIMUniqueValueClass[] { uvcB727, uvcD9 }
};
//assign the group to the renderer
var UVrndr = new CIMUniqueValueRenderer()
{
Fields = new string[] { "ACTYPE" },
Groups = new CIMUniqueValueGroup[] { uvGrp },
UseDefaultSymbol = true,
DefaultLabel = "Others",
DefaultSymbol = SymbolFactory.Instance.ConstructPointSymbol(
CIMColor.CreateRGBColor(185, 185, 185), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
};
//set the renderer. Depending on the current events received, the
//layer may or may not have events for each of the specified
//unique value classes
streamLayer.SetRenderer(UVrndr);
}
}
{
//The layer must be track aware and spatial
if (streamLayer.TrackType != TrackType.Spatial)
{
// not track aware and spatial
}
// Note: call within QueuedTask.Run()
{
//Define unique value classes same as we do for current observations
//or use "CreateRenderer(...)" to assign them automatically
CIMUniqueValueClass uvcB727Prev = new CIMUniqueValueClass()
{
Values = new CIMUniqueValue[] { new CIMUniqueValue() {
FieldValues = new string[] { "B727" } } },
Visible = true,
Label = "Boeing 727",
Symbol = SymbolFactory.Instance.ConstructPointSymbol(
CIMColor.CreateRGBColor(255, 0, 0), 4, SimpleMarkerStyle.Hexagon)
.MakeSymbolReference()
};
CIMUniqueValueClass uvcD9Prev = new CIMUniqueValueClass()
{
Values = new CIMUniqueValue[] { new CIMUniqueValue() {
FieldValues = new string[] { "DC9" } } },
Visible = true,
Label = "DC 9",
Symbol = SymbolFactory.Instance.ConstructPointSymbol(
CIMColor.CreateRGBColor(0, 255, 0), 4, SimpleMarkerStyle.Hexagon)
.MakeSymbolReference()
};
CIMUniqueValueGroup uvGrpPrev = new CIMUniqueValueGroup()
{
Classes = new CIMUniqueValueClass[] { uvcB727Prev, uvcD9Prev }
};
var UVrndr = new CIMUniqueValueRenderer()
{
Fields = new string[] { "ACTYPE" },
Groups = new CIMUniqueValueGroup[] { uvGrpPrev },
UseDefaultSymbol = true,
DefaultLabel = "Others",
DefaultSymbol = SymbolFactory.Instance.ConstructPointSymbol(
CIMColor.CreateRGBColor(185, 185, 185), 4, SimpleMarkerStyle.Hexagon)
.MakeSymbolReference()
};
streamLayer.SetRenderer(UVrndr, FeatureRendererTarget.PreviousObservations);
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)