ArcGIS Pro 2.7 API Reference Guide
CreateLayer<T>(LayerCreationParams,ILayerContainerEdit,LayerPosition) Method
Example 

ArcGIS.Desktop.Mapping Namespace > LayerFactory Class > CreateLayer Method : CreateLayer<T>(LayerCreationParams,ILayerContainerEdit,LayerPosition) Method
Expected Layer Type
Can be one of LayerCreationParams derived objects.
A map or group layer instance to which the Layer will be added.
Specifies whether the layer should be auto positioned or be on the top or at the bottom.
Creates a new Layer instance using the specified LayerCreationParams and adds that to a container such as a map or group layer. Optionally you can provide a name to override the default display name. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
Public Overloads Function CreateLayer(Of T As Layer)( _
   ByVal layerDef As LayerCreationParams, _
   ByVal mapOrGroupLayer As ILayerContainerEdit, _
   Optional ByVal position As LayerPosition _
) As T

Parameters

layerDef
Can be one of LayerCreationParams derived objects.
mapOrGroupLayer
A map or group layer instance to which the Layer will be added.
position
Specifies whether the layer should be auto positioned or be on the top or at the bottom.

Type Parameters

T
Expected Layer Type

Return Value

A specific Layer instance corresponding to type T.
Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Example
Create a feature layer with some pre-defined properties.
var flyrCreatnParam = new FeatureLayerCreationParams(new Uri(@"c:\data\world.gdb\cities"))
{
  Name = "World Cities",
  IsVisible = false,
  MinimumScale = 1000000,
  MaximumScale = 5000,
  DefinitionFilter = new CIMDefinitionFilter()
  {
    DefinitionExpression = "Population > 100000",
    Name = "More than 100k"
  },
  RendererDefinition = new SimpleRendererDefinition()
  {
    SymbolTemplate = SymbolFactory.Instance.ConstructPointSymbol(
      CIMColor.CreateRGBColor(255, 0, 0), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
  }
};

var featureLayer = LayerFactory.Instance.CreateLayer<FeatureLayer>(
  flyrCreatnParam, map, LayerPosition.AutoArrange);
Create a subtype group layer.
var subtypeGroupLayerCreateParam = new SubtypeGroupLayerCreationParams
(
    new Uri(@"c:\data\SubtypeAndDomain.gdb\Fittings")
);

// Define Subtype layers
subtypeGroupLayerCreateParam.SubtypeLayers = new List<SubtypeFeatureLayerCreationParams>()
{
  //define first subtype layer with unique value renderer
  new SubtypeFeatureLayerCreationParams()
  {
    SubtypeId = 1,
    RendererDefinition = new UniqueValueRendererDefinition(new string[] { "type" })
  },

  //define second subtype layer with simple symbol renderer
  new SubtypeFeatureLayerCreationParams()
  {
    SubtypeId = 2,
    RendererDefinition = new SimpleRendererDefinition()
    {
        SymbolTemplate = SymbolFactory.Instance.ConstructPointSymbol(
          CIMColor.CreateRGBColor(255, 0, 0), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
    }
  }
};

// Define additional parameters
subtypeGroupLayerCreateParam.DefinitionFilter = new CIMDefinitionFilter()
{
  Name = "IsActive",
  DefinitionExpression = "Enabled = 1"
};
subtypeGroupLayerCreateParam.IsVisible = true;
subtypeGroupLayerCreateParam.MinimumScale = 50000;

SubtypeGroupLayer subtypeGroupLayer2 = LayerFactory.Instance.CreateLayer<SubtypeGroupLayer>(
              subtypeGroupLayerCreateParam, MapView.Active.Map);
Create a layer from a .lyrx file.
var lyrDocFromLyrxFile = new LayerDocument(@"d:\data\cities.lyrx");
var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();

//modifying its renderer symbol to red
var r = ((CIMFeatureLayer)cimLyrDoc.LayerDefinitions[0]).Renderer as CIMSimpleRenderer;
r.Symbol.Symbol.SetColor(new CIMRGBColor() { R = 255 });

//optionally save the updates out as a file
lyrDocFromLyrxFile.Save(@"c:\data\cities_red.lyrx");

//get a json representation of the layer document and you want store away...
var aJSONString = lyrDocFromLyrxFile.AsJson();

//... and load it back when needed
lyrDocFromLyrxFile.Load(aJSONString);
cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();

//create a layer and add it to a map
var lcp = new LayerCreationParams(cimLyrDoc);
var lyr = LayerFactory.Instance.CreateLayer<FeatureLayer>(lcp, map, LayerPosition.AutoArrange);
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

LayerFactory Class
LayerFactory Members
Overload List