Phantom snap tip that stays after mouse cursor moves away.

2228
2
02-07-2014 08:32 AM
SuiHuang
Occasional Contributor II
Hi Everybody:

    I am trying to build a tool that uses the ArcGIS snapping. In general it works well, but there is a display issue that I don't know how to handle.

    In ArcMap I created a context menu command to activate the tool, such that user can right-click on map, select the command to get the tool activated, and the mouse cursor is on the map right-after. If right-after (say, within 0.1 second) activating the tool my mouse cursor is on some feature edge or vertices that can trigger a snap tip, that snap tip will not disappear even if I move the cursor away, regardless the mouse cursor is getting other snap tip or not. See the attached figure.

[ATTACH=CONFIG]31240[/ATTACH]

    Once that strange snap shows up, the way to remove it is to eigher refresh the map or deactivate the tool.

    Why does this happen? Is there any way to fix it?

Below are the code I wrote in the tool to handle the snapping.

        /// <summary>
        /// Triggered when the tool is clicked.
        /// </summary>
        public override void OnClick()
        {
            base.OnClick();
            SharedState sharedData = SharedState.GetInstance();
            m_SnappingEnv = sharedData.ArcApp.FindExtensionByName("ESRI Snapping") as ISnappingEnvironment;
            m_Snapper = m_SnappingEnv.PointSnapper;
            m_SnappingFeedback = new SnappingFeedbackClass();
            m_SnappingFeedback.Initialize(sharedData.ArcApp, m_SnappingEnv, true);
        }

        public override void OnMouseMove(int Button, int Shift, int X, int Y)
        {
            base.OnMouseMove(Button, Shift, X, Y);

            //Convert the point from pixels to map units.
            IPoint mapPoint = null;
            mapPoint = QueryMapPoint((m_application.Document as IMxDocument).ActivatedView.ScreenDisplay, X, Y);
            mapPoint.Z = 0;

            //Test the location against the snap environment.
            if (m_CurrentMousePoint != null)
            {
                Utils.ReleaseComObjects(m_CurrentMousePoint);
            }
            ISnappingResult snapResult = m_Snapper.Snap(mapPoint);
            if (snapResult != null)
            {
                m_CurrentMousePoint = snapResult.Location;
                Utils.ReleaseComObjects(mapPoint);
            }
            else
            {
                m_CurrentMousePoint = mapPoint;
            }

            //Update the snapping feedback.
            m_SnappingFeedback.Update(snapResult, 0);
        }

0 Kudos
2 Replies
by Anonymous User
Not applicable
Looks like your'e missing the Refresh method in the tool

public override void Refresh(int hDC)
{
    //Refresh the previous location of the snap tip.
    if (m_SnappingFeedback != null)
        m_SnappingFeedback.Refresh(hDC);
}


You can also check out the following resources:
Working with the ArcGIS snapping environment
Incorporating snapping into custom tools
0 Kudos
SuiHuang
Occasional Contributor II
Hi sean_jones:

    I did test the ISnappingFeedback.Refresh function but it doesn't work for me. I input 0 for the hDC value in the test.
    Did I input incorrect hDC value? If that's the case what shall I input?
    Thank you!

Looks like your'e missing the Refresh method in the tool

public override void Refresh(int hDC)
{
    //Refresh the previous location of the snap tip.
    if (m_SnappingFeedback != null)
        m_SnappingFeedback.Refresh(hDC);
}


You can also check out the following resources:
Working with the ArcGIS snapping environment
Incorporating snapping into custom tools
0 Kudos