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!