ArcGIS Pro SDK add FeatureLayer to map

05-18-2020 10:34 AM
New Contributor III

I know this is a very simple question, however, I find it difficult to find an answer. How do I add an existing layer to my map using ArcGIS Pro SDK? I saw several examples where the layer is added while being created (for example

LayerFactory.Instance.CreateFeatureLayer(new Uri(strUri), map);

), however, how this is being done using the existing FeatureLayer?


0 Kudos
5 Replies
Occasional Contributor II

 int indexNumber = 0;
 shp_path = "C:\path to your shapefile"
 var mapView = MapView.Active;

 if (mapView != null)//Check if there is a map
    System.Uri shp_uri = new System.Uri(@shp_path); //creating uri for the shpfile
    QueuedTask.Run(() =>
       Layer shp_layer = LayerFactory.Instance.CreateLayer(
         shp_uri, mapView.Map, indexNumber, "YourlayerName");
       var selectedLayer = mapView.GetSelectedLayers()[0] as FeatureLayer
      //Do something with selected layer

New Contributor II

If you already have a reference to your Layer, try using

LayerFactory.Instance.CopyLayer(sourceLayer, map);

New Contributor III

Thank you guys, 

I have succeeded with Serban's answer. That is what I was looking for.

Have a great day!

0 Kudos
Occasional Contributor

If you have a featureclass:


var layerParams = new FeatureLayerCreationParams(fc);
var layer = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);
New Contributor

Does this automatically add the copied layer to the current map? Accrding to ChatGPT, it does not but every suggestion it has is wrong, i.e., map.AddLayer(copiedLayer); as Class Map does not have a AddLayer method. Same goes for MapView.Add. etc. 

0 Kudos