graphic layer: draw a fix length of leader line on screen

153
2
12-28-2021 08:35 AM
helenchu
Occasional Contributor II

All.

I'm drawing a leader line point to the center of my polygons.  My issue is using map point will make my leader lines varies depending on the zoom scale.  Is there any way I can make my leader lines look the same on screen regardless of the map scale?  Thanks in advance.

var shape = row as Feature;
var poly = shape.GetShape() as Polygon;
var maxY = poly.Extent.YMax + 1500;
var maxX = poly.Extent.XMax + 1500;
MapPoint maxPoint = MapPointBuilder.CreateMapPoint(maxX, maxY);

0 Kudos
2 Replies
Kristine-DanielaShepherdson
New Contributor II

If I understand correctly, you want the point symbol to turn into a line that will remain the same size. 

I have a lateral thinking solution to this.

Use the Labeling properties of the feature:

- go to symbology (for labels)

- scroll down to "Callout" and select simple line - set the tolerance to 0

- go to "Position" Properties for the label select your desired line length ( by setting up a distance of "x" points/inches"

- force the feature to label a space by adding " " in the label expression

- lock label (so that no matter your zoom level, it will remain the same).

0 Kudos
helenchu
Occasional Contributor II

@Kristine-DanielaShepherdson

I'm sorry for not able to explain things better.  I use Graphics Layer in my codes.  For many reasons, label doesn't work for me.  Is there a way we can detect the zoom level and set the length accordingly?   Thanks for your help.

@Kristine-DanielaShepherdson wrote:

If I understand correctly, you want the point symbol to turn into a line that will remain the same size. 

I have a lateral thinking solution to this.

Use the Labeling properties of the feature:

- go to symbology (for labels)

- scroll down to "Callout" and select simple line - set the tolerance to 0

- go to "Position" Properties for the label select your desired line length ( by setting up a distance of "x" points/inches"

- force the feature to label a space by adding " " in the label expression

- lock label (so that no matter your zoom level, it will remain the same).

using (var row = foundCursor.Current)
{
//The parcel is found. Get the center point to label at.
var shape = row as Feature;
var poly = shape.GetShape() as Polygon;
var maxY = poly.Extent.YMax + 100;
var maxX = poly.Extent.XMax + 100;
MapPoint maxPoint = MapPointBuilder.CreateMapPoint(maxX, maxY);

var textSymbol = await CreateBalloonCalloutAsync(ColorFactory.Instance.CreateRGBColor(230,0,169));

var textGraphic = new CIMTextGra0% at least it has proper length phic()

{
Text = "Subject",
Placement = Anchor.CenterPoint,
Symbol = textSymbol.MakeSymbolReference(),
Shape = maxPoint,

//Leaders is an array of CIMLeader - add a Leader point to show
//the leader, remove Leaders to hide the leader.
Leaders = new CIMLeader[] { new CIMLeaderPoint()
{
//for a graphics layer, the leader location is in map coords
Point = MapPointBuilderEx.CreateMapPoint(poly.Extent.Center.X,poly.Extent.Center.Y)

}
}
};
//specify a symbol
//var pt_symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB,3,SimpleMarkerStyle.Square);
var pt_symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.CreateRGBColor(230, 0, 169), 10, SimpleMarkerStyle.Square);

//create a CIMGraphic
var pointGraphic = new CIMPointGraphic()
{
Symbol = pt_symbol.MakeSymbolReference(),
Location = poly.Extent.Center //center of map

};


//Add the graphic label
graphicsLayer.AddElement(textGraphic);
graphicsLayer.AddElement(pointGraphic);
}

0 Kudos