We have developed a custom tool that inherits the BaseTool class with this OnMouseMove method.
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
IActiveView pActiveView = (IActiveView)m_pMapControl3.Map;
m_pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
ISnappingResult snapResult = m_SnappingEnvironment.PointSnapper.Snap(m_pPoint);
//Feedback
m_SnappingFeedback.Update(snapResult, 0);
//Update the current location to move the cursor to the snapped location.
if (snapResult != null)
m_pPoint = snapResult.Location;
}
And this is the code where we are trying to exclude layers from snapping. In this code we are trying to exclude ALL layers just for test.
public override void OnCreate(object hook)
{
//...other code
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.esriSnappingTypeVertex;
m_SnappingFeedback = new SnappingFeedbackClass();
m_SnappingFeedback.Initialize(hook, m_SnappingEnvironment, true);
IPointSnapper pointSnapper = m_SnappingEnvironment.PointSnapper;
ISet excludedLayerSet = new ESRI.ArcGIS.esriSystem.SetClass();
pointSnapper.ExcludedLayers(ref excludedLayerSet);
for (int i=0; i<m_pMapControl3.LayerCount; i++)
{
ILayer exkluderaLager = m_pMapControl3.Map.get_Layer(i);
excludedLayerSet.Add(exkluderaLager); //Exkludera lagret
}
pointSnapper.ClearCache();
}
Everything except ExcludeLayers seems to work fine for us.
Anders