Programatically PanTo / ZoomTo and then Flash features

5647
4
Jump to solution
02-14-2011 03:13 AM
by Anonymous User
Not applicable
Hi!

I am trying to programatically pan to a feature and then flash the feature's geometry. For the "Pan To"-function I'm using the following code:

private IFeature m_feature;

public override void OnClick()
        {
            if (m_feature == null) return;

            IMxDocument pMxDoc = m_application.Document as IMxDocument;
            IActiveView activeView = pMxDoc.ActiveView;

            double midX = (m_feature.Extent.XMax + m_feature.Extent.XMin) / 2;
            double midY = (m_feature.Extent.YMax + m_feature.Extent.YMin) / 2;
            IPoint pPoint = new PointClass();
            pPoint.SpatialReference = m_feature.Extent.SpatialReference;
            pPoint.PutCoords(midX, midY);
            pPoint.Project(activeView.Extent.SpatialReference);

            IEnvelope pCurrentEnvelope = activeView.Extent;
            pCurrentEnvelope.CenterAt(pPoint);

            activeView.Extent = pCurrentEnvelope;
            activeView.Refresh();
        }


After panning  I'm calling FlashGeometry (taken from here: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000075000000).

When executing the code in ArcMap the Flash is always done before the Pan and i don't know why:



A moment before the Pan is visible on screen the feature is flashed in the correct position, but the panning seems not to be finished although I'm calling the methods in the right order.

Please help me :confused:

Regards,
Christian

P.S.: I'm using ArcGIS Desktop 9.3.1. I'm not using ArcGIS Engine.
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
I found a solution myself after searching the old forums 😮

Use IActiveView.Display.UpdateWindow before you run the flash command, this ensures the map has been fully redraw before any other code is executed:


public override void OnClick()
        {
            if (m_feature == null) return;

            IMxDocument pMxDoc = m_application.Document as IMxDocument;
            IActiveView activeView = pMxDoc.ActiveView;

            double midX = (m_feature.Extent.XMax + m_feature.Extent.XMin) / 2;
            double midY = (m_feature.Extent.YMax + m_feature.Extent.YMin) / 2;
            IPoint pPoint = new PointClass();
            pPoint.SpatialReference = m_feature.Extent.SpatialReference;
            pPoint.PutCoords(midX, midY);
            pPoint.Project(activeView.Extent.SpatialReference);

            IEnvelope pCurrentEnvelope = activeView.Extent;
            pCurrentEnvelope.CenterAt(pPoint);

            activeView.Extent = pCurrentEnvelope;
            activeView.Refresh();
            activeView.ScreenDisplay.UpdateWindow();

            IFeatureIdentifyObj featIdentify = new FeatureIdentifyObject();
            featIdentify.Feature = m_feature;
            IIdentifyObj identify = featIdentify as IIdentifyObj;
            identify.Flash(activeView.ScreenDisplay);
        }

View solution in original post

0 Kudos
4 Replies
by Anonymous User
Not applicable
I found a solution myself after searching the old forums 😮

Use IActiveView.Display.UpdateWindow before you run the flash command, this ensures the map has been fully redraw before any other code is executed:


public override void OnClick()
        {
            if (m_feature == null) return;

            IMxDocument pMxDoc = m_application.Document as IMxDocument;
            IActiveView activeView = pMxDoc.ActiveView;

            double midX = (m_feature.Extent.XMax + m_feature.Extent.XMin) / 2;
            double midY = (m_feature.Extent.YMax + m_feature.Extent.YMin) / 2;
            IPoint pPoint = new PointClass();
            pPoint.SpatialReference = m_feature.Extent.SpatialReference;
            pPoint.PutCoords(midX, midY);
            pPoint.Project(activeView.Extent.SpatialReference);

            IEnvelope pCurrentEnvelope = activeView.Extent;
            pCurrentEnvelope.CenterAt(pPoint);

            activeView.Extent = pCurrentEnvelope;
            activeView.Refresh();
            activeView.ScreenDisplay.UpdateWindow();

            IFeatureIdentifyObj featIdentify = new FeatureIdentifyObject();
            featIdentify.Feature = m_feature;
            IIdentifyObj identify = featIdentify as IIdentifyObj;
            identify.Flash(activeView.ScreenDisplay);
        }
0 Kudos
HalilSiddique
Occasional Contributor II
I was having the same problem, I'm glad I found this post.
0 Kudos
zhenliu
New Contributor II
I am glad to find the solution!
0 Kudos
ZLIU
by
New Contributor II

Worked for me! Thanks!

0 Kudos