![](dotnetdiagramimages/image631.png)
public class CIMUniqueValueRenderer : CIMRenderer, System.ComponentModel.INotifyPropertyChanged, System.Xml.Serialization.IXmlSerializable
Public Class CIMUniqueValueRenderer Inherits CIMRenderer Implements System.ComponentModel.INotifyPropertyChanged, System.Xml.Serialization.IXmlSerializable
await QueuedTask.Run(() => { var fields = new List<string> { "Type" }; //field to be used to retrieve unique values CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol( ColorFactory.Instance.GreenRGB, 16.0, SimpleMarkerStyle.Pushpin); //constructing a point symbol as a template symbol CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference(); //constructing renderer definition for unique value renderer UniqueValueRendererDefinition uniqueValueRendererDef = new UniqueValueRendererDefinition(fields, symbolPointTemplate); //creating a unique value renderer var flyr = MapView.Active.GetSelectedLayers()[0] as FeatureLayer; CIMUniqueValueRenderer uniqueValueRenderer = flyr.CreateRenderer(uniqueValueRendererDef) as CIMUniqueValueRenderer; //setting the renderer to the feature layer flyr.SetRenderer(uniqueValueRenderer); });
return QueuedTask.Run(() => { //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. featureLayer.SetRenderer(uvr); });
return QueuedTask.Run(() => { //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. featureLayer.SetRenderer(uvr); });
var url = @"https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer"; var uri = new Uri(url, UriKind.Absolute); //Must be on QueuedTask! var createParams = new FeatureLayerCreationParams(uri) { IsVisible = false }; var 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 classes.Add( 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() }); classes.Add( 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
var url = @"https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer"; var uri = new Uri(url, UriKind.Absolute); //Must be on QueuedTask! var createParams = new FeatureLayerCreationParams(uri) { IsVisible = false }; var 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 classes.Add( 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() }); classes.Add( 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
System.Object
ArcGIS.Core.CIM.CIMObject
ArcGIS.Core.CIM.CIMRenderer
ArcGIS.Core.CIM.CIMUniqueValueRenderer
Target Platforms: Windows 11, Windows 10, Windows 8.1