ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / ILayerFactory Interface / CreateLayer Method / CreateLayer<T>(LayerCreationParams,ILayerContainerEdit) Method
Expected Layer Type
Can be one of LayerCreationParams derived objects.
A map or group layer instance to which the Layer will be added.
Example

In This Topic
    CreateLayer<T>(LayerCreationParams,ILayerContainerEdit) Method
    In This Topic
    Creates a new Layer instance using the specified LayerCreationParams and adds that to a container such as a map or group layer. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Overloads Function CreateLayer(Of T As Layer)( _
       ByVal layerParams As LayerCreationParams, _
       ByVal container As ILayerContainerEdit _
    ) As T

    Parameters

    layerParams
    Can be one of LayerCreationParams derived objects.
    container
    A map or group layer instance to which the Layer will be added.

    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.
    LayerCreationParams or container is null.
    Cannot create the layer of the specified type with the set of LayerCreationParams.
    Example
    Create a KG Layer containing a subset of Entity and Relate types
    QueuedTask.Run(() =>
    {
      //To create a KG layer (on a map or link chart) with a subset of
      //entities and relates, you must create an "id set". The workflow
      //is very similar to how you would create a SelectionSet.
    
      //First, create a dictionary containing the names of the types to be
      //added plus a corresponding list of ids (just like with a selection set).
      //Note: null or an empty list means add all records for "that" type..
      var kg_datamodel = kg.GetDataModel();
      //Arbitrarily get the name of the first entity and relate type
      var first_entity = kg_datamodel.GetEntityTypes().Keys.First();
      var first_relate = kg_datamodel.GetRelationshipTypes().Keys.First();
    
      //Make entries in the dictionary for each
      var dict = new Dictionary<string, List<long>>();
      dict.Add(first_entity, new List<long>());//Empty list means all records
      dict.Add(first_relate, null);//null list means all records
      //or specific records - however the ids are obtained
      //dict.Add(entity_or_relate_name, new List<long>() { 1, 5, 18, 36, 78});
    
      //Create the id set...
      var idSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict);
    
      //Create the layer params and assign the id set
      var kg_params = new KnowledgeGraphLayerCreationParams(kg)
      {
        Name = "KG_With_ID_Set",
        IsVisible = false,
        IDSet = idSet
      };
    
      //Call layer factory with map or group layer container
      //A KG layer containing just the feature layer(s) and/or standalone table(s)
      //for the entity and/or relate types + associated records will be created
      var kg_layer = LayerFactory.Instance.CreateLayer<KnowledgeGraphLayer>(
          kg_params, map);
    
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also