No event for a map being added to a Project

228
2
06-05-2020 11:02 AM
DavidLaMartina
New Contributor III

In a custom Add-In, I have a method I want to call both when a Map is removed from a Project, as well as when a Map is added. There is a clearly defined event for the former - MapRemovedEvent - which we're using. I don't see an equivalent, e.g. MapAddedEvent. The closest thing I've found is MapViewInitializedEvent, which technically works for our purpose, but it's also going to cause unnecessary method calls when a user opens a tab for a previously created Map.

If there is no map added event, are there plans to add one in 2.6 or later?

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You can use the Observable Collection of Items (which includes maps) of the Project class: ArcGIS Pro 2.5 API Reference Guide   in order to listen for change events.  Make sure to check that the added/removed item is a Map since folders, layouts, etc. are all Project Items.

0 Kudos
CharlesMacleod
Esri Regular Contributor

David, in addition to Wolf's suggestion, please see the below event. The ProjectItemsChangedEventArgs will tell you what the change is (map added, removed, layout added, removed, etc,etc) via its Action and ProjectItem properties.

ArcGIS.Desktop.Core.Events.ProjectItemsChangedEvent

0 Kudos