VC++开发GIS系统(114)缩小地图之函数实现

前文已经实现了放大地图重置地图,下面的工作是缩小地图。

缩小地图类的定义

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

/*
* 缩小地图
*/
class malatoolsdll malaZoonOut :public CmalaMouseAction
{
public:
    malaZoonOut();
    malaZoonOut(CView* ptView, malaScreen *Screen);
    ~malaZoonOut();
    void LButtonDown(UINT nFlags, malaPoint point);
private:
    malaScreen *m_Screen;
};

缩小地图类的实现

缩小地图仅使用LButtonDown即可,也就是点击鼠标左键,地图缩小,实现代码如下:

/*
*缩小图形实现
*/
malaZoonOut::malaZoonOut()
{

}
malaZoonOut::malaZoonOut(CView* ptView, malaScreen *Screen)
{
    mBaseView = ptView;
    m_Screen = Screen;
}

malaZoonOut::~malaZoonOut()
{

}

void malaZoonOut::LButtonDown(UINT nFlags, malaPoint point)
{
    //中心点坐标
    long xmid = m_Screen->wScreen / 2;
    long ymid = m_Screen->hScreen / 2;
    malaPoint tmpPoint;
    ScreenToCoord(xmid, ymid, *m_Screen, &tmpPoint.x, &tmpPoint.y);

    //先把图形移到中心
    //m_Screen->lbx = m_Screen->lbx - (point.x - tmpPoint.x);
    //m_Screen->lby = m_Screen->lby - (point.y - tmpPoint.y);

    //再将图形缩小
    m_Screen->lbx = m_Screen->lbx - xmid * m_Screen->scale * 0.1;
    m_Screen->lby = m_Screen->lby - ymid * m_Screen->scale * 0.1;
    m_Screen->scale = m_Screen->scale*1.1;

    //重绘
    mBaseView->Invalidate(TRUE);
}

详细代码可以参考:GitHub

VC++开发GIS系统(113)重置地图 VC++开发GIS系统(115)缩小地图之菜单响应

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

发表评论