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 here) but 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);
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:
LayersAddedEventAdded this layer: TestMultiPoints
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.
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.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.