0
votes

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));
    this->graphicsOverlays()->at(0)->graphics()->append(circleGraphic_p);
    circleGraphic_p->setSymbol(new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::blue), 1.0));
    circleGraphic_p->setVisible(true);

    TextSymbol* textMarker_p = new TextSymbol("Some Label", Qt::black, 12.0, HorizontalAlignment::Center, VerticalAlignment::Bottom);
    Graphic* labelGraphic_p = new Graphic(centerWgs84, textMarker_p);
    this->graphicsOverlays()->at(0)->graphics()->append(labelGraphic_p);
    labelGraphic_p->setVisible(true);

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?

1

1 Answers

1
votes

You are correct, the extent is being returned of the underlying geometry, not the TextSymbol. I don't think you will be able to achieve what you are wanting in the way you are going about it, as there isn't a way to get the bounding box or screen coordinates of the symbol itself. Instead, have you considered using LabelDefinitions and setting the various deconfliction options? This sample shows labels on layers, but can be applied to graphics as well. There are many labeling options you can apply, and this would allow the internal labeling engine to deconflict for you.