How to get bounding rectangle of an ArcGIS TextSymbol?

  arcgis, arcgis-runtime, c++, qt

I’m using the Qt C++ ArcGIS Runtime SDK v100.9 and I have various shapes and labels being drawn on a map.

I want to be able to find out the area (bounding rectangle) of Graphic (which is a text label (TextSymbol) at a given point (SpatialReference::wgs84) on the map) so I can determine if the width of the label is more or less than another Graphic (lets say it has a Polygon for its Geometry which is being used to draw a circle) in order to decide if the label should be set to visible or not.

Within a class derived from Esri::ArcGISRuntime::MapGraphicsView the circle and the text label are created along the lines of:

    Point centerWgs84(0.0, 0.0, SpatialReference::wgs84());
    Graphic* circleGraphic_p = new Graphic(GeometryEngine::bufferGeodetic(centerWgs84, 1000.0, LinearUnit::meters(), 0.5, GeodeticCurveType::Geodesic));
    circleGraphic_p->setSymbol(new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::blue), 1.0));

    TextSymbol* textMarker_p = new TextSymbol("Some Label", Qt::black, 12.0, HorizontalAlignment::Center, VerticalAlignment::Bottom);
    Graphic* labelGraphic_p = new Graphic(centerWgs84, textMarker_p);

Rather than always setting the label visibility to true, I thought I would be able to take the Geometry of each Graphic and use it to construct an Envelope which would allow me to then get the width of each envelope that could then be compared:

    Envelope circleEnvelope(circleGraphic_p->geometry());
    Envelope labelEnvelope(labelGraphic_p->geometry());

    labelGraphic_p->setVisible(circleEnvelope.width() >= labelEnvelope.width());

but when I try and do this, the width of each envelope is always a very small negative value (such as -2.25017… e-98)

Any suggestions on what I am doing wrong or if there is a better way to get the size on the map (or in device independent units) of the text label and a Graphic described by the Geometry of a Polyline or Polygon?

EDIT: I’ve discovered that the Geometry object has an extent() method from which I can get the width of the circle but the Geometry of the Graphic being used for the text label results in a width of zero from its extent() method. I expect this is because the Geometry is just a Point which has no width or height. So the question still stands of how to get the bounding rectangle of a TextSymbol?

Source: Windows Questions C++