Select to view content in your preferred language

Can a MapTool snap to a line?

895
4
Jump to solution
07-31-2020 07:37 AM
BrianBulla
Honored Contributor

I'm creating a MapTool and I need it to be able to snap to a line.  Within Pro, I have edge snapping 'enabled' and snapping turned on.  I also have Snapping turn on through the code in the MapTool, but either way I cannot get the little 'cross hair' cursor to snap to anything.

Where am I going wrong with this??

        protected override Task OnToolActivateAsync(bool active)
        {
            
            Snapping.IsEnabled = true;
            Snapping.SetSnapMode(SnapMode.Edge, true);
            Snapping.SetSnapMode(SnapMode.End, true);            

            return base.OnToolActivateAsync(active);
        }
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

HI Brian,

The UseSnapping property on maptool determines if the tool will use the snap environment.

You would normally set this to True in the tools constructor. Its False by default.

    public SketchSelect()
    {
      IsSketchTool = true;
      SketchType = SketchGeometryType.Line;
      SketchOutputMode = SketchOutputMode.Map;
      UseSnapping = true;

View solution in original post

4 Replies
by Anonymous User
Not applicable

HI Brian,

The UseSnapping property on maptool determines if the tool will use the snap environment.

You would normally set this to True in the tools constructor. Its False by default.

    public SketchSelect()
    {
      IsSketchTool = true;
      SketchType = SketchGeometryType.Line;
      SketchOutputMode = SketchOutputMode.Map;
      UseSnapping = true;
BrianBulla
Honored Contributor

Great.  Thanks Sean Jones‌.  

Another related question:  Is it possible to snap to a graphic that is drawn on the screen?  In my case, I have a tool that creates graphics along of a sewer segment to show where residential sewer connections are coming into the pipe (red graphics).  Ideally I would be able to snap to these red graphics and not just the line.

0 Kudos
by Anonymous User
Not applicable

Hey Brian,

Graphics created with the AddOverlay methods cant be snapped too, they arent in the snapping cache. We do want to add this in a future release.

You can look into graphics layers, which are new at 2.6, that lets users draw persisted snappable graphics and its API.

BrianBulla
Honored Contributor

Great.  Yes, I haven't updated my code since 2.6 came out, so I will look into graphics layers and see if that fixes my problem.

Thanks!

0 Kudos