Add lyr layer via code in ArcGIS Pro 3

153
2
12-05-2022 12:09 PM
JonathanDewalt
New Contributor II

Is it possible to add a layer file (.lyr) to the active map using code in Pro 3?  My Pro 2 code does not work in 3.

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Did you see the Map, Layout, and Layer Files and Packages section of the 3.0 Migration Guide?

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

This will work for lyrx files.   Lyr file are from ArcGIS Desktop so i am not sure if 3.0 will still load those.

protected override async void OnClick()
{
  string url = @"c:\temp\Acme Service Roads.lpkx";  // load layer file

  Uri uri = new Uri(url);
  await QueuedTask.Run(() => LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map));
}
0 Kudos