What is the best way to display a tile map and some other object in a graphical representation?

I recently started to learn Qt, and now I'm working on a GCS project that it should have a map with some tiled imges and some graphic elements like Plan, path, and also on the off level. so we have 3 kinds of items:

  • A scaled map in the background so that its change is scrolling.
  • in the middle there is a photograph of an airplane that is moving with the help of GPS changes, as well as its method.
  • on all these elements there are 3 or 4 gauges, such as a speed indicator, horizontal gauge and altimeter, must be solid in some kind of graphic form and should not change when scrolling down / up or left to the right.

The question is, what is the best way to implement this? here is the first glance of my project:

Gcs

in the first manometer, the view is not on the map, but I want to be! I want sensors on a larger screen map!

And here is the map update code:

void mainMap::update()
{

      m_scene->clear();
    QString TilePathTemp;
    QImage  *imageTemp = new QImage();
    int X_Start=visibleRect().topLeft().x()/256;
    int X_Num=qCeil((float)visibleRect().bottomRight().x()/256.0f-(float)visibleRect().topLeft().x()/256.0f);
    int Y_Start=visibleRect().topLeft().y()/256;
    int Y_Num=qCeil((float)visibleRect().bottomRight().y()/256.0f-(float)visibleRect().topLeft().y()/256.0f);

    LastCenterPoint->setX(visibleRect().center().x());
    LastCenterPoint->setY(visibleRect().center().y());

   X_Start=(X_Start-X_MAP_MARGIN)>0?(X_Start-X_MAP_MARGIN):0;
    Y_Start=(Y_Start-Y_MAP_MARGIN)>0?(Y_Start-Y_MAP_MARGIN):0;
    X_Num+=X_MAP_MARGIN;
    Y_Num+=Y_MAP_MARGIN;
    qDebug()<<"XS:"<<X_Start<<" Num:"<<X_Num;
    qDebug()<<"YS:"<<Y_Start<<" Num:"<<Y_Num;

    for(int x=X_Start;x<=X_Start+X_Num;x++){
      for(int y=Y_Start;y<=Y_Start+Y_Num;y++){


         if(Setting->value("MapType",gis::Hybrid).toInt()==gis::Hybrid) TilePathTemp=Setting->value("MapPath","/Users/M410/Documents/Map").toString()+"/Hybrid/gh_"+QString::number(x)+"_"+QString::number(y)+"_"+QString::number(ZoomLevel)+".jpeg" ;
         else if(Setting->value("MapType",gis::Sattelite).toInt()==gis::Sattelite) TilePathTemp=Setting->value("MapPath","/Users/M410/Documents/Map").toString()+"/Sattelite/gs_"+QString::number(x)+"_"+QString::number(y)+"_"+QString::number(ZoomLevel)+".jpeg" ;
         else if(Setting->value("MapType",gis::Street).toInt()==gis::Street) TilePathTemp=Setting->value("MapPath","/Users/M410/Documents/Map").toString()+"/Street/gm_"+QString::number(x)+"_"+QString::number(y)+"_"+QString::number(ZoomLevel)+".jpeg" ;

          QFileInfo check_file(TilePathTemp);
           // check if file exists and if yes: Is it really a file and no directory?
           if (check_file.exists() && check_file.isFile()) {

              //  qDebug()<<"Exist!";
               imageTemp->load(TilePathTemp);
                QPixmap srcImage = QPixmap::fromImage(*imageTemp);

               //QPixmap srcImage("qrc:/Map/File1.jpeg");
               QGraphicsPixmapItem* item = new QGraphicsPixmapItem(srcImage);

               item->setPos(QPointF(x*256, y*256));

               m_scene->addItem(item);

             //  centerOn( width() / 2.0f , height() / 2.0f );

           } else {
               qDebug()<<"NOT Exist!";
           }


        }
    }
+4
source share
1 answer

Indeed, you should consider using QML. The advantage of using QML instead of QGraphicsView is that you can iterate much faster than if you were working directly in C ++. The primary flaw tends to increase memory usage and incompatibility with QWidgets.

, " ", QML, QGraphicsView .

, Qt , : https://doc.qt.io/qt-5/qml-qtlocation-map.html

+1

All Articles