Select to view content in your preferred language

FeatureSnapAgent problems

1989
11
09-09-2010 06:25 AM
BBulla
by
Regular Contributor
Hi,

I need to be able to snap my custom tool to a few different features in my map.  I am trying to get the tool to snap to my Watermains first, but no luck.  Here is my code I have so far.  I think this is supposed to be setting up the SnapAgents, but something isn't working.  I get no errors, but my cursor for the tool isn't snapping to anything.

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();
}
0 Kudos
11 Replies
BBulla
by
Regular Contributor
Ahhhh!!!  I'm such a knob!!  In my own confusion I was still passing the point from the mouse click, and not the new mousePoint to my method that actually creates the feature.

Thanks for making me look at my code again to explain things.  I guess I was just looking at too many things and got all mixed up.

So mousePoint is getting updated with the snap point.....I just wasn't using properly!!

This line:

CreateWaterServiceConnection(featureClass, point1);

should say:  CreateWaterServiceConnection(featureClass, mousePoint);

Thanks for helping me to understand the snapping!!
0 Kudos
JeffMatson
Frequent Contributor
No problem, glad you got it working...
0 Kudos