ArcGIS Pro 2.9 API Reference Guide
StreamLayer Class
Members  Example 

ArcGIS.Desktop.Mapping Namespace : StreamLayer Class
Represents layer with a collection of real-time features and their visual representation.
Object Model
StreamLayer ClassCIMRenderer ClassCIMDefinitionFilter ClassCIMDataConnection ClassCIMBaseLayer ClassRealtimeFeatureClass ClassCIMRenderer ClassSelection ClassSpatialReference ClassTable ClassCIMSymbol ClassMap ClassILayerContainer InterfaceGeometry ClassEnvelope ClassRowCursor ClassRealtimeCursor ClassSelection ClassRealtimeCursor Class
Syntax
Remarks

Stream layer is a type of FeatureLayer.To create a StreamLayer, you must call CreateLayer method of the LayerFactory class, instead of directly using a constructor.

When you use LayerFactory.CreateLayer<T>, you need to pass in a FeatureLayerCreationParams. You should set UniqueValueRendererDefinition and ClassBreaksRendererDefinition in a FeatureLayerCreationParams only when the source stream service has associated archieved feature service layer. See ArcGIS.Core.Data.Realtime.StreamServiceFeatureClassDefinition.GetArchiveFeatureServiceLayerURL for details. That is because at the creation time a stream layer starts with empty set of features.

You can call FeatureLayer.CreateRenderer anytime later once you have sufficient features to compute and assign a ArcGIS.Core.CIM.CIMUniqueValueRenderer or ArcGIS.Core.CIM.CIMClassBreaksRenderer to a stream layer.

Example
Create Stream Layer with URI.
//Must be on the QueuedTask
var url = "https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer";
var createParam = new FeatureLayerCreationParams(new Uri(url))
{
  IsVisible = false //turned off by default
};
var streamLayer = LayerFactory.Instance.CreateLayer<StreamLayer>(createParam, map);

//or use "original" create layer (will be visible by default)
Uri uri = new Uri(url);
streamLayer = LayerFactory.Instance.CreateLayer(uri, map) as StreamLayer;
streamLayer.SetVisibility(false);//turn off
Create a stream layer with a definition query.
//Must be on the QueuedTask
var url = "https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer";
var lyrCreateParam = new FeatureLayerCreationParams(new Uri(url))
{
  IsVisible = true,
  DefinitionFilter = new CIMDefinitionFilter()
  {
    DefinitionExpression = "RWY = '29L'",
    Name = "Runway"
  }
};

var streamLayer = LayerFactory.Instance.CreateLayer<StreamLayer>(lyrCreateParam, map);
Setting a unique value renderer for latest observations.
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
Setting a unique value renderer for previous observations.
//The layer must be track aware and spatial
if (streamLayer.TrackType != TrackType.Spatial)
  return;
//Must be on QueuedTask!
//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 UVrndrPrev = 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()
};
Setting a simple renderer to draw track lines.
//The layer must be track aware and spatial
if (streamLayer.TrackType != TrackType.Spatial)
  return;
//Must be on QueuedTask!
//Note: only a simple renderer with solid line symbol is supported for track 
//line renderer
var trackRenderer = new SimpleRendererDefinition()
{
  SymbolTemplate = SymbolFactory.Instance.ConstructLineSymbol(
      ColorFactory.Instance.BlueRGB, 2, SimpleLineStyle.Solid)
        .MakeSymbolReference()
};
streamLayer.SetRenderer(
     streamLayer.CreateRenderer(trackRenderer), 
       FeatureRendererTarget.TrackLines);
Make both previous observations and track lines draw.
//The layer must be track aware and spatial for these settings
//to have an effect
if (streamLayer.TrackType != TrackType.Spatial)
  return;
//Must be on QueuedTask
//Note: Setting PreviousObservationsCount larger than the 
//"SetExpirationMaxCount()" has no effect
streamLayer.SetPreviousObservationsCount(6);
if (!streamLayer.AreTrackLinesVisible)
  streamLayer.SetTrackLinesVisibility(true);
if (!streamLayer.ArePreviousObservationsVisible)
  streamLayer.SetPreviousObservationsVisibility(true);
Inheritance Hierarchy

System.Object
   ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
      ArcGIS.Desktop.Mapping.MapMember
         ArcGIS.Desktop.Mapping.Layer
            ArcGIS.Desktop.Mapping.BasicFeatureLayer
               ArcGIS.Desktop.Mapping.FeatureLayer
                  ArcGIS.Desktop.Mapping.StreamLayer

Requirements

Target Platforms: Windows 11, Windows 10, Windows 8.1

See Also

Reference

StreamLayer Members
ArcGIS.Desktop.Mapping Namespace