ISnapEnvironment snapEnvironment = m_editor as ISnapEnvironment;
snapEnvironment.ClearSnapAgents();
IFeatureSnapAgent featureSnapAgent = new FeatureSnapClass();
while (pLayer != null)
{
switch (pLayer.Name)
{
case "GISADMIN.WaterMain":
IFeatureLayer featureLayer = (IFeatureLayer)pLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
featureSnapAgent.FeatureClass = featureClass;
featureSnapAgent.HitType = esriGeometryHitPartType.esriGeometryPartBoundary;
snapEnvironment.AddSnapAgent(featureSnapAgent);
break;
}
pLayer = (ILayer2)allLayers.Next();
}mDisplay = mMxDoc.ActiveView.ScreenDisplay 'get the current mouse point mMousePnt = mAV.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y) 'use ISnapEnvironment to see if the current mouse point will snap to any snap agents mSnapEnv.SnapPoint(mMousePnt) 'set the invert agent (blue circle) to the snap point 'if no snap occurs it will stay "under" the cursor mEditor.InvertAgent(mMousePnt, mEditor.Display.hDC) 'redraw mDisplay.Invalidate(mAV.Extent.Envelope, True, esriScreenCache.esriNoScreenCache)
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
try
{
IMxDocument pMxDoc = (IMxDocument)m_application.Document;
IActiveView pActiveView = pMxDoc.ActiveView;
ESRI.ArcGIS.Display.IScreenDisplay pScreenDisplay = pActiveView.ScreenDisplay;
ESRI.ArcGIS.Display.IDisplayTransformation pDisplayTransformation = pScreenDisplay.DisplayTransformation;
IPoint mousePoint = pDisplayTransformation.ToMapPoint(X, Y);
snapEnvironment.SnapPoint(mousePoint);
m_editor.InvertAgent(mousePoint, m_editor.Display.hDC);
pScreenDisplay.Invalidate(pActiveView.Extent.Envelope, true, (short)esriScreenCache.esriNoScreenCache);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Or even better would be how do I get the coordinate that the InvertAgent has snapped to?? I can see it has snapped, but when I create my new feature based on the mousePoint, it is not snapped.
public sealed class ServiceConnectionTool : BaseTool
{
private IPoint mousePoint;
//in here I have all my other methods including the mouse down and mouse move events
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
}
}
points[0] = mousePoint;
//For GeoFeature Classes
UID pID = new UID();
pID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
IMap pMap = pMxDoc.FocusMap;
IEnumLayer allLayers;
allLayers = pMap.get_Layers(pID, true);
ILayer2 pLayer;
pLayer = (ILayer2)allLayers.Next();
while (pLayer.Name != "GISADMIN.WAT_Fitting")
pLayer = (ILayer2)allLayers.Next();
if (pLayer.Name == "GISADMIN.WAT_Fitting")
{
IFeatureLayer featureLayer = (IFeatureLayer)pLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
watFittingSelections = (IFeatureSelection)featureLayer;
m_editor.StartOperation();
CreateWaterServiceConnection(featureClass, point1);
m_editor.StopOperation("Create new Service Connection");
}