VC++开发GIS系统(117)移动地图之函数实现

之前已经实现了地图的放大缩小工作,如果放大或者缩小了地图,经常有些我们感兴趣的区域无法显示,这时候就需要移动地图操作,如图:

移动地图类的定义

VC++开发GIS系统(108)放大地图之新建tools模块基础上,新建一个类,用于处理移动地图的相关操作。代码如下:

/*
* 移动地图
*/
class malatoolsdll malaMoveMap :public CmalaMouseAction
{
public:
    malaMoveMap();
    malaMoveMap(CView* ptView, malaScreen *Screen);
    ~malaMoveMap();
    void LButtonDown(UINT nFlags, malaPoint point);
    void LButtonUp(UINT nFlags, malaPoint point);
    void MouseMove(UINT nFlags, malaPoint point);
private:
    malaPoint m_PtOrigin;
    bool m_bDraw;
private:
    malaScreen *m_Screen;
};

移动地图类的实现

这个拉框放大相似,重写了LButtonDown、LButtonUp、MouseMove函数。

/*
* 移动图形实现
*/
malaMoveMap::malaMoveMap()
{

}
malaMoveMap::malaMoveMap(CView* ptView, malaScreen *Screen)
{
    mBaseView = ptView;
    m_Screen = Screen;
    m_bDraw = FALSE;
}

malaMoveMap::~malaMoveMap()
{

}

void malaMoveMap::LButtonDown(UINT nFlags, malaPoint point)
{
    m_bDraw = TRUE;
    m_PtOrigin.x = point.x;
    m_PtOrigin.y = point.y;
}

void malaMoveMap::MouseMove(UINT nFlags, malaPoint point)
{
    if (m_bDraw)
    {
        m_Screen->lbx = m_Screen->lbx - (point.x - m_PtOrigin.x);
        m_Screen->lby = m_Screen->lby - (point.y - m_PtOrigin.y);
        m_PtOrigin.x = point.x;
        m_PtOrigin.y = point.y;
    }
}

void malaMoveMap::LButtonUp(UINT nFlags, malaPoint point)
{
    m_bDraw = FALSE;
    mBaseView->Invalidate(TRUE);
}

详细代码可以参考:GitHub

VC++开发GIS系统(116)刷新地图 VC++开发GIS系统(118)移动地图之菜单响应

作者:,GIS爱好者。
分享本文,请您带上本文链接
分享到:

发表评论