MapView Map PropertyChanged event trigger two times?

954
4
Jump to solution
12-10-2019 10:13 PM
by Anonymous User
Not applicable

Hi Guys,

I have noticed that MapView Map propertychanged event is triggered two times always whenever one property is changed from Map.

When I logged, First trigger is actual property change trigger, another event is "AnimationVM" property.

Is that correct behavior or bug?

I am currently using ArcGIS pro sdk version 2.4

I have to skip second trigger by checking whether PropertyChangedEventArgs property name is "AnimationVM" or not.

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi Than

I am not seeing this behavior with 2.5 or with 2.4.  Can you please share a code snippet? This is what I did -

Breakpoint in the event handler was also hit only once...

//In my Module class
internal class Module1 : Module
    {
protected override bool Initialize()
        {
            //Subscribe to the event:
            MapPropertyChangedEvent.Subscribe(OnMapPropertyChanged);
            return base.Initialize();
        }

        private void OnMapPropertyChanged(MapPropertyChangedEventArgs obj)
        {
            System.Diagnostics.Debug.WriteLine("MapPropChangedEventTriggered");
        }
....

Thanks

Uma

View solution in original post

0 Kudos
4 Replies
UmaHarano
Esri Regular Contributor

Hi Than,

Which specific Map Property are you changing when you see this behavior?

Also, to confirm, the event you are using is "MapPropertyChangedEvent", correct?

Thank you!

Uma

0 Kudos
by Anonymous User
Not applicable

Hi Uma,

Yes, I use "MapPropertyChangedEvent" , So far, I played with changing name from General tab, and Coordinate Systems.

Best Regards,

Than

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Than

I am not seeing this behavior with 2.5 or with 2.4.  Can you please share a code snippet? This is what I did -

Breakpoint in the event handler was also hit only once...

//In my Module class
internal class Module1 : Module
    {
protected override bool Initialize()
        {
            //Subscribe to the event:
            MapPropertyChangedEvent.Subscribe(OnMapPropertyChanged);
            return base.Initialize();
        }

        private void OnMapPropertyChanged(MapPropertyChangedEventArgs obj)
        {
            System.Diagnostics.Debug.WriteLine("MapPropChangedEventTriggered");
        }
....

Thanks

Uma

0 Kudos
by Anonymous User
Not applicable

Thank Uma,

That's different code. I totally missed to check that lib ArcGIS.Desktop.Mapping.Events.

For your sample MapPropertyChangedEventArgs send back map array "Maps" and map event hints "EventHints" .

Would like to understand in which circumstance multiple maps' properties shall be updated?

Let say event is fired, how shall we track which map and map's properties are updated?

If it is always returning one map object in the array return, I can safely say all EventHints, 

Even though not important for me, EventHints seem like string array and always the last index value is "Any".

I used below one currently, I think that code will trigger one event for each property, your sample code is more appropriate for me to use.

 protected override bool Initialize()
        {
            ArcGIS.Desktop.Mapping.Events.ActiveMapViewChangedEvent.Subscribe(this.MapViewActivateEvent);
       

                    }

        /// <summary>
        /// Active Map view change event 
        /// Perform coordinate system checking, feature layer checking ...... 
        /// </summary>
        /// <param name="obj"></param>
        private void MapViewActivateEvent(ActiveMapViewChangedEventArgs obj)
        {
            try
            {
                var mapView = MapView.Active;
                this.ShowVerifyDatumWindow();
                //Active map view change perform some kind of events
                if (mapView != null && mapView.Map != null)
                {
                    mapView.Map.PropertyChanged += CurrentMapViewMapPropertyChangeEvent;
                    
                }
            }
            catch (Exception ex)
            {
                var ErrorString = ex.Message;
                ProDialog.MessageBox.Show("An error occurred " + ErrorString);
            }
        }

        private void CurrentMapViewMapPropertyChangeEvent(object sender, PropertyChangedEventArgs e)
        {
           
System.Diagnostics.Debug.WriteLine(e.PropertyName + " is changed at MapPropChangedEventTriggered");
            ArcGIS.Desktop.Mapping.Map currentActiveMap = (ArcGIS.Desktop.Mapping.Map)sender;
            try
            {
               
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

            }
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos