Duplicate Leader Line Annotation tool

228
2
02-14-2024 12:49 PM
DaveWilcox
New Contributor III

Hi All,

I am building an edit tool with an embedded combo box control to select text from an approved list. The template symbol for the annotation feature class is set to a balloon callout. My current tool uses a point sketch to drop callout boxes. I would like the first click of the tool to establish the leader-line location and then the second click to position the box (similar to the built-in Leader Line Anno Tool). When I switch to a line sketch, it uses the second click to create a line that the text is placed on. I'm guessing there is something basic I'm missing, but I haven't found it yet. If anyone can point me in the right direction, I would be very grateful!

Thanks

- Dave

Tags (2)
0 Kudos
2 Replies
NarelleChedzey
Esri Contributor

Hi Dave, 

One way of having a sketch tool allow multiple clicks without using the Line sketch is to use the Multipoint geometry type.   You can then override the OnSketchModifiedAsync callback to force the sketch to finish after your required number of clicks (in this case 2). 

Here's a small snippet that sounds like what you're looking for. 

internal class LeaderLineTool : MapTool
{
  public LeaderLineTool()
  {
    IsSketchTool = true;
    SketchType = SketchGeometryType.Multipoint;
    SketchOutputMode = SketchOutputMode.Map;
  }

  protected override Task OnToolActivateAsync(bool active)
  {
    return base.OnToolActivateAsync(active);
  }

  protected override async Task<bool> OnSketchModifiedAsync()
  {
    var sketchGeom = await GetCurrentSketchAsync();
    if (sketchGeom is Multipoint multiPoint)
    {
      var ptCount = multiPoint.Points.Count;
      // force the sketch to finish if there are more than 2 points
      if (ptCount >= 2)
        FinishSketchAsync();
    }

    return true;
  }
  protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
  {
    if (geometry is Multipoint multiPoint)
    {
      // check the point count
      //   user could have finished the sketch with less than the 
      //   required 2 points
      var ptCount = multiPoint.Points.Count;
      if (ptCount < 2)
      {
        return Task.FromResult(true);
      }

      var firstPoint = multiPoint.Points[0];
      var secondPoint = multiPoint.Points[1];

      // first point for leader line location
      // second point for callout location
    }

    return base.OnSketchCompleteAsync(geometry);
  }
}

 

Narelle

0 Kudos
DaveWilcox
New Contributor III

Thanks. That is helpful. Any tips on how to visually drop the leader line on the first click so that the text can be accurately placed relative to the leader line, rather than be placed on the line defined by the two points?

- Dave

0 Kudos