PIE-SDK For C ++ map mouse event listeners

1. Introduction

Map mouse events include mouse press MouseButtonPress (), bounce MouseButtonRelease (), moving MouseMove () events such operations can be dynamically map by these events, the status bar next to the map information specific example explains how to use these three events.

2. Functional Implementation Notes

2.1. The realization of ideas and Rationale

The first step: in the main event-capture header file

protected:

    /**

    * @Brief rewrite eventFilter event

    * @Param [in] QObject * obj the object that triggered the event

    * @Param [in] QEvent * ev event triggered

    * @return

    */

    bool eventFilter(QObject *obj, QEvent *ev) override;

 

Step Two: In the .cpp be achieved write code file

2.2 core interfaces and methods

Interface / class

Methods / Properties

Explanation

SysDisplay::DisplayTransformationPtr

ToMapPoint

Screen coordinates to map coordinates

SysGeometry::SpatialReferencePtr

Name

Gets or sets the spatial reference Name

2.3. Sample Code

Project Path

Under Baidu cloud disk address / PIE sample program / 02. Map operation / 06. Map Mouse Event Listener

Data Path

The disc address Baidu cloud / the PIE exemplary data / raster data /04.World/World.tif

Video Path

Under Baidu cloud disk address / PIE video tutorials / 02. Map operation / 06. Map Mouse Event Listener .avi

Sample Code

  1. Add an event to capture the header file

    protected:

     

        /**

        * @Brief rewrite eventFilter event

        * @Param [in] QObject * obj the object that triggered the event

        * @Param [in] QEvent * ev event triggered

        * @return

        */

        bool eventFilter(QObject *obj, QEvent *ev) override;

     

  2. Event coding

    // This example is mainly to map the status bar

    bool PIEMainWindow::eventFilter(QObject *obj, QEvent *ev)

    {

        if (obj == m_pMapControl)

        {

            if (ev->type() == QEvent::MouseMove)

            {

                QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(ev);

                m_pLineEdit_ScreenCoordsInfos->setText(QString("%1,%2").arg(pMouseEvent->x()).arg(pMouseEvent->y()));

                double mapX, mapY;

                mapX = mapY = 0;

                m_pMapControl->GetActiveView()->GetDisplayTransformation()->ToMapPoint(pMouseEvent->x(), pMouseEvent->y(), mapX, mapY);

                m_pLineEdit_GeoCoordsInfos->setText(QString("%1,%2").arg(mapX).arg(mapY));

     

                SysGeometry::SpatialReferencePtr ptrSR = m_pMapControl->GetMap()->GetSpatialReference();

                if (ptrSR == nullptr) return true;

                m_pLabel_SpatialReferenceInfos->setText(ptrSR->GetName());

            }

            else if (ev->type()==QEvent::MouseButtonPress)

            {    

                QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(ev);

                QPoint qPoint;

                qPoint.setX(pMouseEvent->x());

                qPoint.setY(pMouseEvent->y());

                SysGeometry::PointPtr point = new SysGeometry::Point();

                point = m_pMapControl->GetActiveView()->GetDisplayTransformation()->ToMapPoint(qPoint);

                QString screenPoint = QString("屏幕坐标:%1,%2").arg(pMouseEvent->x()).arg(pMouseEvent->y());

                QString mapPoint= QString("屏幕坐标:%1,%2").arg(point->GetX()).arg(point->GetY());

            }

            else if (ev->type()==QEvent::MouseButtonRelease)

            {

                qDebug("鼠标释放事件");

            }

        }

        else if (obj == m_pPageLayoutControl)

        {

            if (ev->type() == QEvent::MouseMove)

            {

                QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(ev);

     

                m_pLineEdit_ScreenCoordsInfos->setText(QString("%1,%2").arg(pMouseEvent->x()).arg(pMouseEvent->y()));

                double mapX, mapY;

                mapX = mapY = 0;

                m_pPageLayoutControl->GetActiveView()->GetDisplayTransformation()->ToMapPoint(pMouseEvent->x(), pMouseEvent->y(), mapX, mapY);

                m_pLineEdit_GeoCoordsInfos->setText(QString("%1,%2").arg(mapX).arg(mapY));

     

                SysGeometry::SpatialReferencePtr ptrSR = m_pPageLayoutControl->GetMap()->GetSpatialReference();

                if (ptrSR == nullptr) return true;

                m_pLabel_SpatialReferenceInfos->setText(ptrSR->GetName());

            }

        }

        return QMainWindow::eventFilter(obj, ev);

    }

2.4. 示例截图

 

Guess you like

Origin www.cnblogs.com/PIESat/p/12366958.html