How to add TextSymbol and SimpleMarkerSymbol to the same Graphic object.

781
2
09-04-2017 05:42 AM
GeorgeArnaut
New Contributor II

Hi everyone! I have some trouble with displayng a marker with some legend. When i put a marker on the map, there is no problem to replace it during the program execution. But i want to connect this marker with a legend and update the position of my marker at the same time with the legend. I found a simple way to create a legend by using TextSymbol, but it blocked SimpleMarkerSymbol.

Sample of code:

----------------------------------------------------------------------------------------------------------------------------------------------------------

SimpleMarkerSymbol* crossSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Cross, QColor("red"), 12, this);

Point point(-110.828140, 44.460458, SpatialReference::wgs84());

Graphic* graphic = new Graphic(point, crossSymbol, this);

m_graphicsOverlay->graphics()->append(graphic);

And display it:

m_mapView->graphicsOverlays()->append(m_graphicsOverlay);

In this code there's no any problems. As if i add TextSymbol.

I know that both of this classes Inherited from the same parent, but can i put them together and then update coordinates in a way like this:

Graphic* tmp= m_graphicsOverlay->graphics()->at( 'Some index ');

tmp->setGeometry(point); (reinitialize coordinates).

Or should i use some other way? Can anyone tell me.

0 Kudos
2 Replies
LukeSmallwood
Esri Contributor

Hi George, you can use the CompositeSymbol type (CompositeSymbol Class | ArcGIS for Developers ) to combine together two or more Symbols. The code below shows how you could combine a TextSymbol with your existing crossSymbol and use them as a CompositeSymbol which gets its position (geometry) updated every time the user clicks on the map.

TextSymbol* textSymbol = new TextSymbol("hello", Qt::blue, 12, HorizontalAlignment::Left, VerticalAlignment::Bottom, this);
  textSymbol->setOffsetX(2);
  textSymbol->setOffsetY(2);
  SimpleMarkerSymbol* crossSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Cross, QColor("red"), 12, this);
  CompositeSymbol* compositeSymbol = new CompositeSymbol(QList<Symbol*>{textSymbol, crossSymbol}, this);
  Point point(-110.828140, 44.460458, SpatialReference::wgs84());
  Graphic* graphic = new Graphic(point, compositeSymbol, this);
  GraphicsOverlay* overlay = new GraphicsOverlay(this);
  overlay->graphics()->append(graphic);
  m_mapView->graphicsOverlays()->append(overlay);
  connect(m_mapView, &MapQuickView::mouseClicked, this, [graphic, this](QMouseEvent& mouseEvent)
  {
    Point newPos = m_mapView->screenToLocation(mouseEvent.x(), mouseEvent.y());
    graphic->setGeometry(newPos);
  });

This approach would let you apply a label to the market symbol you are already using.

I hope that helps,

Luke

0 Kudos
GeorgeArnaut
New Contributor II

Thanks for replying my question Luke! Your advice was very useful.

0 Kudos