1

I want to add a large number of points to a QgsMapCanvas in a way that updates them every 100 milliseconds. In my initial attempt, I used QgsMapCanvasItem and QPainter to draw these points on the map. While it technically works, I've encountered lag in loading map , excessive CPU usage, and overall poor performance.

My goal is to improve the performance of this operation, and I've considered using OpenGL for this purpose. However, I'm struggling to correctly position the points on the map, especially when the user drags and drops the map.

I have one OpenGLItem class like this:

class OpenGLItem: public QOpenGLWidget, protected QOpenGLFunctions
{
public:
    OpenGLItem(QWidget *parent = nullptr);
    void  setCenterPoint(QPointF &centerPoint);

protected:
    void        initializeGL() override;

    void        resizeGL(int w, int h) override;

// I draw my Points in this function

    void        paintGL() override;

private:
    QPointF  centerPoint;
};

and I add it to map like this:

OpenGLItem *openGLWidget   = new OpenGLItem;
auto        mapCoordinates = QgsPoint(33.0, 31.877);
QgsPointXY  mapPoint       = mapCanvas->getCoordinateTransform()->transform(mapCoordinates);

// This part makes my position become wrong
// becouse widget should move and move dont accept QPointF
QPoint  pixelPoint(abs(static_cast<int>(mapPoint.x())), abs(static_cast<int>(mapPoint.y())));

openGLWidget->move(pixelPoint);
mapCanvas->scene()->addWidget(openGLWidget);


If I add any widget in mapCanvas by using addWidget function Its position will change by drag and drop!

How can I fix this issue?

5
  • 1
    Do you mean your widget is draggable while it should not or that it does not stay at the correct geographical location when the user interacts with the map canvas? Sep 3, 2023 at 7:36
  • @bugmenot123 yes Exactly.
    – Parisa.H.R
    Sep 3, 2023 at 10:25
  • Both of the things I said? Sep 3, 2023 at 10:32
  • @bugmenot123 move function accepts QPoint which means int but converted point is QPointF which is double so this makes a wrong position. on the other hand by using addWidget function and adding widget in map , makes it move while I drag and drop the map and its lon and lat will change. I didnt want widget will be draggable I want to add QOpenGLWidget instead of QgsMapCanvasItem but it acts like QgsMapCanvasItem. I want to use GPU to draw my points instead of QPainter which use CPU.
    – Parisa.H.R
    Sep 3, 2023 at 10:43
  • Please use the edit button beneath your question to revise it with any requested clarifications.
    – PolyGeo
    Sep 4, 2023 at 10:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.