Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a custom tool with snapping type is (snapping to point + snapping to edge), and the second tool having snapping type is snapping to point only, so when i select the first tool it works well, but when i switch to the second it do not work , even if when i return to the first tool, it do not work too. the same as when i start using the second tool , once i switch to the first tool the snapping stops working in all tools.

here is the code of the on click event of the first tool:

public override void OnClick()
    {


        IHookHelper2 m_hookHelper2 = m_hookHelper as IHookHelper2;
        IExtensionManager extensionManager = m_hookHelper2.ExtensionManager;
        if (extensionManager != null)
        {

            UID guid = new UIDClass();
            guid.Value = "{E07B4C52-C894-4558-B8D4-D4050018D1DA}"; //Snapping extension.
            IExtension extension = extensionManager.FindExtension(guid);
            m_SnappingEnvironment = extension as ISnappingEnvironment;

            m_SnappingEnvironment.SnappingType = (esriSnappingType)9;// esriSnappingType.esriSnappingTypePoint + esriSnappingType.esriSnappingTypeEdge;
            m_Snapper = m_SnappingEnvironment.PointSnapper;



            m_SnappingFeedback = new SnappingFeedbackClass();

            m_SnappingFeedback.Initialize(m_hookHelper.Hook, m_SnappingEnvironment, true);

            ISet excludedLayerSet = new ESRI.ArcGIS.esriSystem.SetClass();
            m_Snapper.ExcludedLayers(ref excludedLayerSet);

            for (int i = 0; i < dessin.get_instance().mapDocument.get_Map(0).LayerCount; i++)
            {
                if (dessin.get_instance().mapDocument.get_Layer(0, i).Name != "Point_t" && dessin.get_instance().mapDocument.get_Layer(0, i).Name != "Point_d" && dessin.get_instance().mapDocument.get_Layer(0, i).Name != "line_k")
                    excludedLayerSet.Add(dessin.get_instance().mapDocument.get_Layer(0, i));
            }

            m_Snapper.ClearCache();

        }

    }



 public override void OnMouseMove(int Button, int Shift, int X, int Y)
        {
            if (Button == 4)
                return;
            //Convert the point from pixels to map units.
            m_CurrentMouseCoords = QueryMapPoint(mapDocument.ActiveView.ScreenDisplay, X, Y);

            //Test the location against the snap environment.
            snapResult = m_Snapper.Snap(m_CurrentMouseCoords);

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

            //Update the current location to move the cursor to the snapped location.
            if (snapResult != null)
                if (snapResult.Location != null)
                {
                m_CurrentMouseCoords = snapResult.Location;
            //MessageBox.Show("sdsd");
                }

            if (m_linefeedback != null)
            {

                m_linefeedback.MoveTo(m_CurrentMouseCoords);

            }
        }

Any help please.

share|improve this question
hmm I cannot reproduce it. Could you write inside of OnMouseMove code? – Darksanta May 8 at 2:02
i'm sorry for being late, i have updated my code to include the onMouseMove. – geogeek May 8 at 15:09
I ran it almost same code, but it worked fine. How about removing ExcludedLayers or using same SnappingType? does it works? And If you don't mind, please write more detail such as OnMouseDown, OnMouseUp, Deactivate eventhandlers. – Darksanta May 9 at 1:25

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.