Graphics layer: element placement

521
4
Jump to solution
09-13-2020 11:49 PM
helenchu
Occasional Contributor II

Hi

I'm trying to have an element placed at the bottom left corner of the selected feature but can't figure out how to do it.  I can place it at the center of the polygon fine but not at any other positions.  Your help is much appreciated.

while (foundCursor.MoveNext())
{
using (var row = foundCursor.Current)
{
var shape = row as Feature;
var poly = shape.GetShape() as Polygon;
myLabelGraphic.Shape = poly.Extent;
myLabelGraphic.Placement = Anchor.BottomLeftCorner;

}

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi Helen,

You have almost all the logic in  

Once you get the polygon of your feature, you need to get its lower left corner coordinates. Use that for the graphic's shape property.  So like this:

var poly = currentRow.GetShape() as Polygon;
var lowerLeftX = poly.Extent.XMin;
var lowerLeftY = poly.Extent.YMin;‍‍‍
myLabelGraphic.Shape = //Create MapPoint using these coordinates.

Thanks

Uma

View solution in original post

4 Replies
UmaHarano
Esri Regular Contributor

Hi Helen,

You have almost all the logic in  

Once you get the polygon of your feature, you need to get its lower left corner coordinates. Use that for the graphic's shape property.  So like this:

var poly = currentRow.GetShape() as Polygon;
var lowerLeftX = poly.Extent.XMin;
var lowerLeftY = poly.Extent.YMin;‍‍‍
myLabelGraphic.Shape = //Create MapPoint using these coordinates.

Thanks

Uma

helenchu
Occasional Contributor II

Hi Uma Harano‌,

Line 12 returns an error : graphic shape property can not be null or empty.  What did I do wrong?  maxPoint is not null.

Thank you!

var poly = shape.GetShape() as Polygon;
var maxX= poly.Extent.MMax;
var maxY= poly.Extent.YMax;
MapPoint maxPoint = MapPointBuilder.CreateMapPoint(maxX, maxY);
if (maxPoint != null)
{
 myLabelGraphic.Shape = maxPoint;
 myLabelGraphic.Placement = Anchor.CenterPoint;
 myLabelGraphic.Text = myText;
 myLabelGraphic.Symbol = myTextSymbol.MakeSymbolReference();
 graphicsLayer.AddElement(myLabelGraphic);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
UmaHarano
Esri Regular Contributor

Hi,

On line 2, use XMax instead.  That should fix the issue.

Thanks

Uma

helenchu
Occasional Contributor II

Hi Uma,

Silly me.  I was so certain I had XMax there.  Thank you very much!

0 Kudos