/// <summary>
/// You must call this method on the MCT!
/// </summary>
/// <returns></returns>
private CIMRenderer CreateUniqueValueRendererUsingColorTable(FeatureLayer lyrToColor,
StandaloneTable colorTable)
{
//All of these methods have to be called on the MCT
if (OnUIThread)
throw new ArcGIS.Core.CalledOnWrongThreadException();
//make a dictionary with MapUnit and Color
var dicMapUnitColor = new Dictionary<int, string>();
using (var rowCursor = colorTable.Search())
{
while (rowCursor.MoveNext())
{
using (var anyRow = rowCursor.Current)
{
dicMapUnitColor.Add((int)anyRow["MapUnit"], anyRow["Color"].ToString());
}
}
}
//Create the Unique Value Renderer
CIMUniqueValueRenderer uniqueValueRenderer = new CIMUniqueValueRenderer()
{
// set the value field
Fields = new string[] { "MapUnit" }
};
//Construct the list of UniqueValueClasses
List<CIMUniqueValueClass> classes = new List<CIMUniqueValueClass>();
//define the unique values for each dicMapUnitColor entry
foreach (var key in dicMapUnitColor.Keys)
{
var lstValue = new List<CIMUniqueValue>()
{
new CIMUniqueValue()
{
FieldValues = new string[] { key.ToString() }
}
};
var namedColor = System.Drawing.Color.FromName(dicMapUnitColor[key]);
var theColor = CIMColor.CreateRGBColor(namedColor.R, namedColor.G, namedColor.B);
classes.Add(
new CIMUniqueValueClass()
{
Values = lstValue.ToArray(),
Label = $@"Color: {dicMapUnitColor[key]}",
Visible = true,
Editable = true,
Symbol = new CIMSymbolReference() {
Symbol = SymbolFactory.Instance.ConstructPointSymbol(
SymbolFactory.Instance.ConstructMarker(theColor, 20, SimpleMarkerStyle.Pushpin)) }
}
);
}
//Add the classes to a group (by default there is only one group or "symbol level")
// Unique value groups
CIMUniqueValueGroup groupOne = new CIMUniqueValueGroup()
{
Heading = "By Color",
Classes = classes.ToArray()
};
uniqueValueRenderer.Groups = new CIMUniqueValueGroup[] { groupOne };
//Draw the rest with the default symbol
uniqueValueRenderer.UseDefaultSymbol = true;
uniqueValueRenderer.DefaultLabel = "All other values";
var defaultColor = CIMColor.CreateRGBColor(215, 215, 215);
uniqueValueRenderer.DefaultSymbol = new CIMSymbolReference()
{
Symbol = SymbolFactory.Instance.ConstructPointSymbol(
SymbolFactory.Instance.ConstructMarker(defaultColor, 15, SimpleMarkerStyle.Diamond))
};
return uniqueValueRenderer as CIMRenderer;
}