Select to view content in your preferred language

CIMPolygonGraphic.Name not getting set?

340
2
10-19-2022 10:43 AM
DanielRatzlaff
Occasional Contributor

I apologize if this is a dumb question, I'm new.

I have a tool that allows a user to sketch a selection rectangle on a graphics layer, and I'm trying to set the Name property so I can refer to it again, but after adding the element to the layer, the Name property ends up being "Rectangle".  This code is in OnSketchCompleteAsync:

Polygon box = geometry as Polygon;
QueuedTask.Run(() =>
{
    var poly_symbol = SymbolFactory.Instance.ConstructPolygonSymbol(CIMColor.CreateRGBColor(130, 130, 130, 40));
    var graphic = new CIMPolygonGraphic()
    {
        Symbol = poly_symbol.MakeSymbolReference(),
        Polygon = box,
        Name = "ExtentSelection"
    };
    displayLayer.AddElement(graphic);
});

What am I doing wrong?

0 Kudos
2 Replies
DanielRatzlaff
Occasional Contributor

Sorry, I figured it out.  The Name needed to be set on the Element, not the CIMPolygonGraphic:

var poly_symbol = SymbolFactory.Instance.ConstructPolygonSymbol(CIMColor.CreateRGBColor(130, 130, 130, 40));
var graphic = new CIMPolygonGraphic()
{
    Symbol = poly_symbol.MakeSymbolReference(),
    Polygon = box
};
displayLayer.AddElement(graphic,"ExtentSelection");
0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

My code is a little bit different and it works on ArcGIS Pro 9.2

var poly_symbol = SymbolFactory.Instance.ConstructPolygonSymbol(CIMColor.CreateRGBColor(130, 130, 130, 40));
var graphic = new CIMPolygonGraphic()
{
    Symbol = poly_symbol.MakeSymbolReference(),
    Polygon = box
};
graphic.Name = "ExtentSelection";
displayLayer.AddElement(graphic);

It seems that CIMPolygonGraphic constructor overrides Name you set