Select to view content in your preferred language

Dispaly mil2525 symbology on a map using graphicsoverlay

1245
4
12-18-2019 09:10 PM
AbhijeetSatam
Occasional Contributor

I am using SymbolStyle and graphicsoverlay in ArcGIS qt 100.5 to read and display symbols from a style file. The code for the function is as follows. m_mapView is my MapGraphicsView object. The application is successfully built. The application crashes when this function is called. The debug statements display true status for both tw1.isValid() and for tw1.isDone() . Can somebody guide me why this problem is occurring??

 

 

void offlinemap2d::addPointsFromStyleFile()

{


   //create a new graphicsoverlay
   GraphicsOverlay* graphicsOverlay = new GraphicsOverlay(this);
   // create a list of points
   const QList<Point> pointsList

      {
      Point(72.852642647560347, 19.092812566811544, SpatialReference::wgs84()),
      Point(72.8708416959572303, 19.08444173689877, SpatialReference::wgs84()),
      Point(32.6697273884990937, 56.064250073402874, SpatialReference::wgs84()),
      Point(32.6395150461199726, 56.06127916736989, SpatialReference::wgs84())

      };

   QStringList params {"tank","friendly"};

   // create the symbology for the points
  SymbolStyle* symbolstyle1 = new SymbolStyle("/home/developer/Desktop/stylx_files/mil2525d.stylx", this);
   TaskWatcher tw1 = symbolstyle1->fetchSymbol(param);

   qDebug()<<tw1.isValid(); 
     while(tw1.isDone()==false)
         {
               for(int i=1;i<500;i++)

                  {
                     qDebug()<<i;
                  }
         }
   qDebug()<<tw1.isDone();
   symbolstyle1->fetchSymbolCompleted(tw1.taskId(),symbol1);

   foreach (const Point &buoyPoint, pointsList)
      {
            graphic = new Graphic(buoyPoint, this);

            graphic->setSymbol(symbol1);
            graphicsOverlay->graphics()->append(graphic);
       }

//add overlay to the map
m_mapView->graphicsOverlays()->append(graphicsOverlay);

}

0 Kudos
4 Replies
by Anonymous User
Not applicable

At a guess. I believe the crash your seeing is to do with this line

symbolstyle1->fetchSymbolCompleted(tw1.taskId(),symbol1);


This is a qt signal, which will be emitted at some time after your call to

symbolstyle1->fetchSymbol(param);

and shouldn't be called directly.
(You can read more about signals and slots here : (Signals & Slots | Qt Core 5.14.0 )

Could you try replacing everything below the call to fetchSymbol with this?

connect(symbolstyle1, &SymbolStyle::fetchSymbolCompleted, this,  [graphicsOverlay, pointsList, this](QUuid taskId, Symbol* symbol)
   {
     foreach (const Point &buoyPoint, pointsList)
     {
       auto graphic = new Graphic(buoyPoint, this);
       graphic->setSymbol(symbol);
       graphicsOverlay->graphics()->append(graphic);
     }

     m_mapView->graphicsOverlays()->append(graphicsOverlay);
   });

0 Kudos
AbhijeetSatam
Occasional Contributor

Hi Elliot,

I tried using your suggestion . The application is successfully built now and does not crash when run. However the points are not displayed on the map. The code I have used is as follows. The debug statement added is displayed in the console.

void offlinemap2d::addPointsFromStyleFile()

{

 


   //create a new graphicsoverlay
   GraphicsOverlay* graphicsOverlay = new GraphicsOverlay(this);
   // create a list of points
   const QList<Point> pointsList

      {
      Point(72.852642647560347, 19.092812566811544, SpatialReference::wgs84()),
      Point(72.8708416959572303, 19.08444173689877, SpatialReference::wgs84()),
      Point(32.6697273884990937, 56.064250073402874, SpatialReference::wgs84()),
      Point(32.6395150461199726, 56.06127916736989, SpatialReference::wgs84())

      };

   QStringList params {"tank","friendly"};

   // create the symbology for the points
    SymbolStyle* symbolstyle1 = new SymbolStyle("/home/developer/Desktop/stylx_files/mil2525d.stylx", this);
     TaskWatcher tw1 = symbolstyle1->fetchSymbol(param);

  

      connect(symbolstyle1, &SymbolStyle::fetchSymbolCompleted, this,  [graphicsOverlay, pointsList, this](QUuid taskId,       Symbol* symbol)
         {

              qDebug()<<"inside connect";
              foreach (const Point &buoyPoint, pointsList)
                 {

                      
                      auto graphic = new Graphic(buoyPoint, this);
                       graphic->setSymbol(symbol);
                       graphicsOverlay->graphics()->append(graphic);
                 }

 

     m_mapView->graphicsOverlays()->append(graphicsOverlay);
   });

}

0 Kudos
by Anonymous User
Not applicable

My first guess would be to check if the

Symbol*

provided from the connect argument list actually contains data, or if it is null. If it's null, it probably indicates that your data has not been loaded, or that the parameters provided are not being found inside the data.

(I don't think this is neccesary, but you can also try calling

symbolstyle1.load()

immediately after the symbolStyle has been initialised. It may help.)

0 Kudos
AbhijeetSatam
Occasional Contributor

Your guess is right. Null is returned for the Symbol.

However, we are using mil2525d.stylx (http://arcgisfordefense.maps.arcgis.com/home/item.html?id=e34835bf5ec5430da7cf16bb8c0b075c) file and trying to fetch Symbol with keywords like 'tank' and 'friendly' as

   QStringList params {"tank","friendly"};

Still we are not able to successfully display symbols on map.

0 Kudos