Docs about the data passed to event listeners in the ArcGIS Pro SDK

165
3
Jump to solution
12-07-2020 02:27 PM
MikeDavlantes
New Contributor II

I come from a background of web development and am having difficulty making sense of the ArcGIS Pro SDK API reference. I see that there’s a class for a LayersAdded event (docs herebut how do I see what data will be in the event? This exists in my code, and it works:

LayersAddedEvent.Subscribe((evt) => ...do something with event);
but in order to see what properties the event has, I have been triggering an event and logging it. This does not seem like the right way of doing things, but I am a lowly web developer who doesn’t really understand fully how C# or the Pro SDK API reference works. I'm trying to handle many different events. How can I tell what is getting returned?
Reply
0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Mike,

 The ArcGIS Pro SDK wiki explains how to 'subscribe' to Pro Events using the Pro SDK in general: ProConcepts Framework Events Specifically when you subscribe to an LayerAddedEvent you have to look at the parameter required for the Subscribe method (API Reference) : 

public static SubscriptionToken Subscribe( 
   Action<LayerEventsArgs> action,
   bool keepSubscriberAlive
)

The parameter Action<LayerEventsArgs> indicates that you have to specify a 'delegate' (action method) here.  The delegate action method has one parameter LayerEventsArgs and looking at the members of LayerEventsArgs you will notice that it contains a Layers property which contains the layers (as an enumeration)  that are added.  To test this i created an add-in module with a single button.  The OnClick method for the button contains this test code:

protected override void OnClick()
{
	LayersAddedEvent.Subscribe((evtArgs) => 
	{
		System.Diagnostics.Debug.WriteLine("LayersAddedEvent");
		foreach (var lyr in evtArgs.Layers)
		{
			System.Diagnostics.Debug.WriteLine($@"Added this layer: {lyr.Name}");
		}
	});
}

To test this i click my button and then add a new layer to my map view and I get the following output in my Visual Studio output window:

LayersAddedEvent
Added this layer: TestMultiPoints

 

 

View solution in original post

Reply
0 Kudos
3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Mike,

 The ArcGIS Pro SDK wiki explains how to 'subscribe' to Pro Events using the Pro SDK in general: ProConcepts Framework Events Specifically when you subscribe to an LayerAddedEvent you have to look at the parameter required for the Subscribe method (API Reference) : 

public static SubscriptionToken Subscribe( 
   Action<LayerEventsArgs> action,
   bool keepSubscriberAlive
)

The parameter Action<LayerEventsArgs> indicates that you have to specify a 'delegate' (action method) here.  The delegate action method has one parameter LayerEventsArgs and looking at the members of LayerEventsArgs you will notice that it contains a Layers property which contains the layers (as an enumeration)  that are added.  To test this i created an add-in module with a single button.  The OnClick method for the button contains this test code:

protected override void OnClick()
{
	LayersAddedEvent.Subscribe((evtArgs) => 
	{
		System.Diagnostics.Debug.WriteLine("LayersAddedEvent");
		foreach (var lyr in evtArgs.Layers)
		{
			System.Diagnostics.Debug.WriteLine($@"Added this layer: {lyr.Name}");
		}
	});
}

To test this i click my button and then add a new layer to my map view and I get the following output in my Visual Studio output window:

LayersAddedEvent
Added this layer: TestMultiPoints

 

 

View solution in original post

Reply
0 Kudos
MikeDavlantes
New Contributor II

Thanks Wolf-- this was very helpful! Looking at it now I think most of my difficulty was just in navigating the docs. Getting from the `LayersAdded` page to `LayerEventsArgs` isn't particularly straightforward.

Reply
0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You are correct that "Getting from the `LayersAdded` page to `LayerEventsArgs` isn't straightforward".  We had this issue in our cross hairs for a while, it's a limitation in the third party software we are using for the API reference website generation.  We are hoping to fix this 'linkage' problem in one of the upcoming releases.

Reply
0 Kudos