Is there an ArcGIS Pro SDK event for layers being added to the map?

641
2
Jump to solution
08-16-2019 12:38 PM
Highlighted
New Contributor III

I'd like to create an ArcGIS Pro Add In that an event can be used to trigger some code execution when a layer is added to a map.  Is this possible?  I was unable to locate an event in the SDK, or I'm looking for the wrong thing.   Thanks for your help.

Regards,

Frank

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Regular Contributor

Hi Frank

You can use the LayerAddedEvent in the ArcGIS.Desktop.Mapping assembly.

The arcgis-pro-sdk-community-samples repo has a couple of samples that uses this event also.

1. TextSymbols sample

2. FeatureSelection sample

Thanks

Uma

View solution in original post

2 Replies
Highlighted
Esri Regular Contributor

Hi Frank

You can use the LayerAddedEvent in the ArcGIS.Desktop.Mapping assembly.

The arcgis-pro-sdk-community-samples repo has a couple of samples that uses this event also.

1. TextSymbols sample

2. FeatureSelection sample

Thanks

Uma

View solution in original post

Highlighted
New Contributor III

Hi Uma,

The LayersAddedEvent class worked.   Thanks for the succession.   

        protected override bool Initialize()
{
ArcGIS.Desktop.Mapping.Events.ActiveMapViewChangedEvent.Subscribe(MapViewActivateEvent);
ArcGIS.Desktop.Mapping.Events.LayersAddedEvent.Subscribe(LayerAddEvent);
return true;
}‍‍‍‍‍‍


private void LayerAddEvent(LayerEventsArgs args)
{
try
{
foreach(var newLayer in args.Layers)
{
if (newLayer.Map == MapView.Active.Map && newLayer is BasicFeatureLayer)
{
updateEventLayers(newLayer);
//var layerAddString = "Layer added event";
//MessageBox.Show(layerAddString, "Caption");
}
}
}
catch (Exception ex)
{
var ErrorString = ex.Message;
//MessageBox.Show("An tttterror occurred while updating attribute column data " + ErrorString);
}

}