Hi,
I just want to use the ArcGIS Pro SDK to add the two layer files(.lyrx). Could someone please assist me with this?
I attempted to use LayerDocument(), but it would be greatly appreciated if someone could provide a sample for the same.
Wanted to add the layer file on TOC.
Thanks in advance!
Solved! Go to Solution.
Hi ,
There are a few examples in this page that can help you: ProSnippets: Map Authoring.
Check out this snippet: create-layer-from-a-lyrx-file
Thanks!
Uma
Hi Shabina,
Have you tried looking at this code snippet?
https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#create-layer-from-a-lyrx-file
I slimmed down that code snippet into fewer lines. This bit works for me. Have you confirmed the path to the lyrx file and that the file itself exists? Also have you enclosed your code in a QueuedTask as shown below?
protected override void OnClick()
{
QueuedTask.Run(() =>
{
var lyrDocFromLyrxFile = new LayerDocument(@"c:\temp\Hurricanes.lyrx");
var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
//create a layer and add it to a map
var lcp = new LayerCreationParams(cimLyrDoc);
var lyr = LayerFactory.Instance.CreateLayer<FeatureLayer>(lcp, MapView.Active.Map);
});
}
Hi ,
There are a few examples in this page that can help you: ProSnippets: Map Authoring.
Check out this snippet: create-layer-from-a-lyrx-file
Thanks!
Uma
Hi Shabina,
Have you tried looking at this code snippet?
https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#create-layer-from-a-lyrx-file
I slimmed down that code snippet into fewer lines. This bit works for me. Have you confirmed the path to the lyrx file and that the file itself exists? Also have you enclosed your code in a QueuedTask as shown below?
protected override void OnClick()
{
QueuedTask.Run(() =>
{
var lyrDocFromLyrxFile = new LayerDocument(@"c:\temp\Hurricanes.lyrx");
var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
//create a layer and add it to a map
var lcp = new LayerCreationParams(cimLyrDoc);
var lyr = LayerFactory.Instance.CreateLayer<FeatureLayer>(lcp, MapView.Active.Map);
});
}
Thanks a lot @RobBurke I really appreciate your time and effort and yes, it worked pretty well for me.
Thanks @UmaHarano 🙂