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?
Thanks
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 }); }
If you already have a reference to your Layer, try using
LayerFactory.Instance.CopyLayer(sourceLayer, map);
Thank you guys,
I have succeeded with Serban's answer. That is what I was looking for.
Have a great day!
If you have a featureclass:
var layerParams = new FeatureLayerCreationParams(fc);
var layer = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);
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.