Select to view content in your preferred language

Anchor distance?

485
2
Jump to solution
10-27-2022 01:16 PM
AndrewAlexander1
Emerging Contributor

Hello,

Another question if you please.
I am putting a CIMTextGraphic on the map, and I'd like to have another element, either another CIMTextGraphic (it will be displaying text), or maybe it should be another element type, but that is anchored to the first element.

But I'd like it to display "visually" the same when zooming in or out.

Currently, I can place the second element properly, and it looks pretty good.  But if I zoom out, the second element "looks" to be very far away from the first element.

I realize the issues with the scale and the points, and technically it is the same number of points away, but I'd like it to stay visually close to the first element.

Hope that makes sense.

Thanks
Andy

 

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Or you can use the Symbol's OffsetX and OffsetY to distance the two graphic elements.  

Wolf_0-1666984642106.png

Wolf_1-1666984657451.png

This is my code snippet:

internal class PlaceDoubleText : MapTool
{
  private CIMTextSymbol _callout1TextSymbol = null;
  private CIMTextSymbol _callout2TextSymbol = null;
  private GraphicsLayer _selectedGraphicLayer = null;

  public PlaceDoubleText()
  {
    IsSketchTool = true;
    SketchType = SketchGeometryType.Point;
    SketchOutputMode = SketchOutputMode.Map;
  }

  protected override async Task OnToolActivateAsync(bool active)
  {
    _callout1TextSymbol = await CreateBalloonCalloutAsync();
    _callout2TextSymbol = await CreateBalloonCalloutAsync();
    _callout2TextSymbol.OffsetY = 26;
    _selectedGraphicLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<GraphicsLayer>().FirstOrDefault();
    return;
  }

  protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
  {
    if (_selectedGraphicLayer == null)
    {
      MessageBox.Show("Add a graphics layer to the TOC", "No graphics layer found",
        System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
      return Task.FromResult(true);
    }
    if (_callout1TextSymbol == null)
      return Task.FromResult(true);
    var textGraphic = new CIMTextGraphic
    {
      Symbol = _callout1TextSymbol.MakeSymbolReference(),
      Shape = geometry as MapPoint,
      Text = "First Text"
    };
    var lowTextGraphic = new CIMTextGraphic
    {
      Symbol = _callout2TextSymbol.MakeSymbolReference(),
      Shape = geometry as MapPoint,
      Text = "Second Text"
    };
     

    return QueuedTask.Run(() =>
    {
      _selectedGraphicLayer.AddElement(textGraphic);
      _selectedGraphicLayer.AddElement(lowTextGraphic);
      return true;
    });
  }

  private static Task<CIMTextSymbol> CreateBalloonCalloutAsync()
  {
    return QueuedTask.Run<CIMTextSymbol>(() =>
    {
      //create a text symbol
      var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 11, "Corbel", "Regular");
      //A balloon callout
      var balloonCallout = new CIMBalloonCallout();
      //set the callout's style
      balloonCallout.BalloonStyle = BalloonCalloutStyle.RoundedRectangle;
      //Create a solid fill polygon symbol for the callout.
      var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid);
      //Set the callout's background to be the black polygon symbol
      balloonCallout.BackgroundSymbol = polySymbol;
      //margin inside the callout to place the text
      balloonCallout.Margin = new CIMTextMargin
      {
        Left = 5,
        Right = 5,
        Bottom = 5,
        Top = 5
      };
      //assign the callout to the text symbol's callout property
      textSymbol.Callout = balloonCallout;
      return textSymbol;
    });
  }
}

 

View solution in original post

0 Kudos
2 Replies
CharlesMacleod
Esri Regular Contributor

I think u may need to set the reference scale on your map. Try setting it to whatever is the scale when u place your graphics. By default it is 0 (no ref scale).

map_ref_scale.png

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Or you can use the Symbol's OffsetX and OffsetY to distance the two graphic elements.  

Wolf_0-1666984642106.png

Wolf_1-1666984657451.png

This is my code snippet:

internal class PlaceDoubleText : MapTool
{
  private CIMTextSymbol _callout1TextSymbol = null;
  private CIMTextSymbol _callout2TextSymbol = null;
  private GraphicsLayer _selectedGraphicLayer = null;

  public PlaceDoubleText()
  {
    IsSketchTool = true;
    SketchType = SketchGeometryType.Point;
    SketchOutputMode = SketchOutputMode.Map;
  }

  protected override async Task OnToolActivateAsync(bool active)
  {
    _callout1TextSymbol = await CreateBalloonCalloutAsync();
    _callout2TextSymbol = await CreateBalloonCalloutAsync();
    _callout2TextSymbol.OffsetY = 26;
    _selectedGraphicLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<GraphicsLayer>().FirstOrDefault();
    return;
  }

  protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
  {
    if (_selectedGraphicLayer == null)
    {
      MessageBox.Show("Add a graphics layer to the TOC", "No graphics layer found",
        System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
      return Task.FromResult(true);
    }
    if (_callout1TextSymbol == null)
      return Task.FromResult(true);
    var textGraphic = new CIMTextGraphic
    {
      Symbol = _callout1TextSymbol.MakeSymbolReference(),
      Shape = geometry as MapPoint,
      Text = "First Text"
    };
    var lowTextGraphic = new CIMTextGraphic
    {
      Symbol = _callout2TextSymbol.MakeSymbolReference(),
      Shape = geometry as MapPoint,
      Text = "Second Text"
    };
     

    return QueuedTask.Run(() =>
    {
      _selectedGraphicLayer.AddElement(textGraphic);
      _selectedGraphicLayer.AddElement(lowTextGraphic);
      return true;
    });
  }

  private static Task<CIMTextSymbol> CreateBalloonCalloutAsync()
  {
    return QueuedTask.Run<CIMTextSymbol>(() =>
    {
      //create a text symbol
      var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 11, "Corbel", "Regular");
      //A balloon callout
      var balloonCallout = new CIMBalloonCallout();
      //set the callout's style
      balloonCallout.BalloonStyle = BalloonCalloutStyle.RoundedRectangle;
      //Create a solid fill polygon symbol for the callout.
      var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid);
      //Set the callout's background to be the black polygon symbol
      balloonCallout.BackgroundSymbol = polySymbol;
      //margin inside the callout to place the text
      balloonCallout.Margin = new CIMTextMargin
      {
        Left = 5,
        Right = 5,
        Bottom = 5,
        Top = 5
      };
      //assign the callout to the text symbol's callout property
      textSymbol.Callout = balloonCallout;
      return textSymbol;
    });
  }
}

 

0 Kudos