VC++开发GIS系统(111)放大地图之函数实现

前文《VC++开发GIS系统(110)放大地图之简析橡皮筋绘图》已经介绍并解决放大地图的橡皮筋问题,剩下的就是实现地图放大的模块功能了。

LButtonDown函数

表示按下鼠标左键

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

记录下最原始的点。

MouseMove函数

鼠标移动响应

void malaZoonIn::MouseMove(UINT nFlags, malaPoint point)
{
    if (m_bDraw)
    {
        malaCDC dc(mBaseView, *m_Screen);
        dc.drawRectNULLFill(m_PtOrigin, m_perPoint);
        dc.drawRectNULLFill(m_PtOrigin, point);
        m_perPoint.x = point.x;
        m_perPoint.y = point.y;
    }
}

这里用到了橡皮筋绘图的方法drawRectNULLFill,详细实现参考:VC++开发GIS系统(110)放大地图之简析橡皮筋绘图

LButtonUp函数

void malaZoonIn::LButtonUp(UINT nFlags, malaPoint point)
{
    m_bDraw = FALSE;
    //如果是点击放大
    if ((m_PtOrigin.x == point.x) && (m_PtOrigin.y == point.y))
    {
        //中心点坐标
        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*0.9;
    }
    else
    {
        //如果是拉框放大
        double x1 = min(m_PtOrigin.x, point.x);
        double y1 = min(m_PtOrigin.y, point.y);
        double x2 = max(m_PtOrigin.x, point.x);
        double y2 = max(m_PtOrigin.y, point.y);
        m_Screen->lbx = x1;
        m_Screen->lby = y1;

        double blc1 = (x2 - x1) / (double)m_Screen->wScreen;
        double blc2 = (y2 - y1) / (double)m_Screen->hScreen;
        m_Screen->scale = (blc1 > blc2) ? blc1 : blc2;
    }
    mBaseView->Invalidate(TRUE);
}

详细代码可以参考:GitHub

VC++开发GIS系统(110)放大地图之简析橡皮筋绘图 VC++开发GIS系统(112)放大地图之菜单响应

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

发表评论